|
| 1 | +'use client'; |
| 2 | + |
| 3 | +import React, { Suspense, useEffect, useState } from 'react'; |
| 4 | +import styled, { css } from 'styled-components'; |
| 5 | +import { theme } from '@/styles/theme'; |
| 6 | +import Input from '@/components/common/Input'; |
| 7 | +import Button from '@/components/common/Button'; |
| 8 | +import { useRouter, useSearchParams } from 'next/navigation'; |
| 9 | +import { sendLetterState } from '@/recoil/letterStore'; |
| 10 | +import { useRecoilState } from 'recoil'; |
| 11 | +import { useToast } from '@/hooks/useToast'; |
| 12 | +import Loader, { LoaderContainer } from '@/components/common/Loader'; |
| 13 | + |
| 14 | +const SendSenderPage = () => { |
| 15 | + const router = useRouter(); |
| 16 | + const searchParams = useSearchParams(); |
| 17 | + const { showToast } = useToast(); |
| 18 | + const [draftId, setDraftId] = useState<string | null>(null); |
| 19 | + const [sender, setSender] = useState<string>(''); |
| 20 | + const [receiver, setReceiver] = useState<string>(''); |
| 21 | + const [content, setContent] = useState<string>(''); |
| 22 | + const [images, setImages] = useState<string[]>([]); // 서버 전송용 |
| 23 | + const [previewImages, setPreviewImages] = useState<string[]>([]); // 미리보기용 |
| 24 | + |
| 25 | + const isGuest = searchParams.get('guest') === 'true'; |
| 26 | + const [letterState, setLetterState] = useRecoilState(sendLetterState); |
| 27 | + |
| 28 | + useEffect(() => { |
| 29 | + if (letterState) { |
| 30 | + setDraftId(letterState.draftId); |
| 31 | + setSender(letterState.senderName); |
| 32 | + setReceiver(letterState.receiverName); |
| 33 | + setContent(letterState.content); |
| 34 | + setImages(letterState.images); |
| 35 | + setPreviewImages(letterState.images); |
| 36 | + } |
| 37 | + }, [letterState]); |
| 38 | + |
| 39 | + const handleSenderChange = (newValue: string) => { |
| 40 | + setSender(newValue); |
| 41 | + setLetterState((prevState) => ({ |
| 42 | + ...prevState, |
| 43 | + senderName: newValue |
| 44 | + })); |
| 45 | + }; |
| 46 | + |
| 47 | + const handleAddNext = async () => { |
| 48 | + /* 다음 페이지 */ |
| 49 | + setLetterState((prevState) => ({ |
| 50 | + ...prevState, |
| 51 | + draftId: draftId, |
| 52 | + receiverName: receiver, |
| 53 | + content: content, |
| 54 | + images: images, |
| 55 | + previewImages: previewImages |
| 56 | + })); |
| 57 | + |
| 58 | + router.push(`/send/template${isGuest ? '?guest=true' : ''}`); |
| 59 | + }; |
| 60 | + |
| 61 | + return ( |
| 62 | + <> |
| 63 | + <Container> |
| 64 | + <Column> |
| 65 | + <Label>From. 편지를 보내는 사람</Label> |
| 66 | + <Input |
| 67 | + inputType="boxText" |
| 68 | + value={sender} |
| 69 | + onChange={handleSenderChange} |
| 70 | + placeholder="작성자 본인의 '성 + 이름' 의 실명을 입력해주세요" |
| 71 | + /> |
| 72 | + </Column> |
| 73 | + </Container> |
| 74 | + <ButtonWrapper> |
| 75 | + <Button |
| 76 | + buttonType="primary" |
| 77 | + size="large" |
| 78 | + text={'다음'} |
| 79 | + disabled={!sender} |
| 80 | + onClick={handleAddNext} |
| 81 | + /> |
| 82 | + </ButtonWrapper> |
| 83 | + </> |
| 84 | + ); |
| 85 | +}; |
| 86 | + |
| 87 | +export default function SendSenderPaging() { |
| 88 | + return ( |
| 89 | + <Suspense |
| 90 | + fallback={ |
| 91 | + <LoaderContainer> |
| 92 | + <Loader /> |
| 93 | + </LoaderContainer> |
| 94 | + } |
| 95 | + > |
| 96 | + <SendSenderPage /> |
| 97 | + </Suspense> |
| 98 | + ); |
| 99 | +} |
| 100 | + |
| 101 | +const Container = styled.div` |
| 102 | + width: 100%; |
| 103 | + height: 100%; |
| 104 | + display: flex; |
| 105 | + flex-direction: column; |
| 106 | + overflow-y: auto; |
| 107 | +
|
| 108 | + &::-webkit-scrollbar { |
| 109 | + display: none; |
| 110 | + } |
| 111 | +
|
| 112 | + @media (max-height: 628px) { |
| 113 | + position: relative; |
| 114 | + } |
| 115 | +`; |
| 116 | + |
| 117 | +const Column = styled.div<{ $position?: boolean }>` |
| 118 | + margin-bottom: 40px; |
| 119 | +
|
| 120 | + @media (max-height: 710px) { |
| 121 | + margin-bottom: 20px; |
| 122 | + } |
| 123 | +
|
| 124 | + @media (max-height: 628px) { |
| 125 | + ${({ $position }) => |
| 126 | + $position && |
| 127 | + css` |
| 128 | + width: 100%; |
| 129 | + position: absolute; |
| 130 | + top: 300px; |
| 131 | + `} |
| 132 | + } |
| 133 | +
|
| 134 | + @media (max-height: 580px) { |
| 135 | + ${({ $position }) => |
| 136 | + $position && |
| 137 | + css` |
| 138 | + width: 100%; |
| 139 | + position: absolute; |
| 140 | + top: 280px; |
| 141 | + `} |
| 142 | + } |
| 143 | +`; |
| 144 | + |
| 145 | +const Label = styled.div<{ $show?: boolean }>` |
| 146 | + display: flex; |
| 147 | + justify-content: space-between; |
| 148 | + align-items: center; |
| 149 | + color: ${theme.colors.white}; |
| 150 | + ${(props) => props.theme.fonts.subtitle}; |
| 151 | + margin-bottom: 12px; |
| 152 | +
|
| 153 | + @media (max-height: 628px) { |
| 154 | + ${theme.fonts.body6} |
| 155 | + margin-bottom: 12px; |
| 156 | + ${({ $show }) => |
| 157 | + $show === false && |
| 158 | + css` |
| 159 | + display: none; |
| 160 | + margin-bottom: 0px; |
| 161 | + `} |
| 162 | + } |
| 163 | +
|
| 164 | + @media (max-height: 580px) { |
| 165 | + ${theme.fonts.body10} |
| 166 | + margin-bottom: 8px; |
| 167 | + } |
| 168 | +`; |
| 169 | + |
| 170 | +const ButtonWrapper = styled.div` |
| 171 | + width: 100%; |
| 172 | + position: absolute; |
| 173 | + padding: 0 20px; |
| 174 | + bottom: 40px; |
| 175 | + left: 0; |
| 176 | +`; |
| 177 | + |
| 178 | +const DescriptionText = styled.button` |
| 179 | + width: 100%; |
| 180 | + display: flex; |
| 181 | + justify-content: center; |
| 182 | + padding: 23px; |
| 183 | + text-decoration: underline; |
| 184 | + ${theme.fonts.body09}; |
| 185 | + color: ${(props) => props.theme.colors.gray400}; |
| 186 | +`; |
| 187 | + |
| 188 | +const BottomWrapper = styled.div` |
| 189 | + width: 100%; |
| 190 | + max-width: 393px; |
| 191 | + position: absolute; |
| 192 | + bottom: 0px; |
| 193 | + z-index: 1000; |
| 194 | +`; |
0 commit comments