|
| 1 | +import { SetStateAction, useState, useEffect } from 'react' |
| 2 | +import * as S from './styles' |
| 3 | +import Select from '~components/Select' |
| 4 | +import { WalkModalProps, RequestUserInfo, OtherUserInfo } from '~types/modal' |
| 5 | + |
| 6 | +const reportOptions = [ |
| 7 | + { value: 'dog', label: '강아지가 사나워요.' }, |
| 8 | + { value: 'other', label: '기타' }, |
| 9 | +] |
| 10 | + |
| 11 | +const WalkModal = ({ type, userInfo, onClose, onConfirm, onCancel }: WalkModalProps) => { |
| 12 | + useEffect(() => { |
| 13 | + document.body.style.overflow = 'hidden' |
| 14 | + |
| 15 | + return () => { |
| 16 | + document.body.style.overflow = 'unset' |
| 17 | + } |
| 18 | + }, []) |
| 19 | + |
| 20 | + const [selectedReportType, setSelectedReportType] = useState('') |
| 21 | + const getModalContent = () => { |
| 22 | + switch (type) { |
| 23 | + case 'request': |
| 24 | + return { |
| 25 | + message: '함께 산책하기 위해 멘트를 입력하세요.', |
| 26 | + confirmText: '전송하기', |
| 27 | + } |
| 28 | + case 'accept': |
| 29 | + return { |
| 30 | + message: '산책 요청이 왔어요!', |
| 31 | + confirmText: '수락', |
| 32 | + cancelText: '거절', |
| 33 | + } |
| 34 | + case 'complete': |
| 35 | + return { |
| 36 | + message: '신고가 완료됐습니다.', |
| 37 | + confirmText: '확인', |
| 38 | + } |
| 39 | + case 'progress': |
| 40 | + return { |
| 41 | + title: '강번따 응답', |
| 42 | + message: `${userInfo.name}이(가) 거절했어요.`, |
| 43 | + confirmText: '다시 시도', |
| 44 | + cancelText: '취소', |
| 45 | + } |
| 46 | + case 'friend': |
| 47 | + return { |
| 48 | + message: `${userInfo.name}이 30분동안 산책했어요.`, |
| 49 | + confirmText: '수락', |
| 50 | + cancelText: '거절', |
| 51 | + } |
| 52 | + case 'report': |
| 53 | + return { |
| 54 | + title: '어떤 이유로 신고하시나요?', |
| 55 | + confirmText: '전달', |
| 56 | + cancelText: '취소', |
| 57 | + } |
| 58 | + case 'reportComplete': |
| 59 | + return { |
| 60 | + title: '신고 완료!', |
| 61 | + message: '신고가 완료됐습니다.', |
| 62 | + confirmText: '확인', |
| 63 | + } |
| 64 | + case 'walkRequest': |
| 65 | + return { |
| 66 | + title: '산책 친구하실래요?', |
| 67 | + confirmText: '수락', |
| 68 | + cancelText: '거절', |
| 69 | + } |
| 70 | + } |
| 71 | + } |
| 72 | + |
| 73 | + const modalContent = getModalContent() |
| 74 | + |
| 75 | + return ( |
| 76 | + <S.ModalOverlay onClick={onClose}> |
| 77 | + <S.ModalContent type={type} onClick={e => e.stopPropagation()}> |
| 78 | + {(type === 'accept' || type === 'progress' || type === 'walkRequest') && ( |
| 79 | + <> |
| 80 | + <h1>{type === 'progress' || type === 'walkRequest' ? modalContent?.title : modalContent?.message}</h1> |
| 81 | + {type === 'walkRequest' && <S.ReportIcon />} |
| 82 | + </> |
| 83 | + )} |
| 84 | + {type !== 'accept' && type === 'friend' && <div className='date'>2024.12.14</div>} |
| 85 | + |
| 86 | + {type !== 'progress' && type !== 'report' && type !== 'reportComplete' && ( |
| 87 | + <S.UserInfo type={type}> |
| 88 | + <S.Avatar type={type} /> |
| 89 | + <S.Info type={type}> |
| 90 | + <h3>{userInfo.name}</h3> |
| 91 | + {type === 'request' || type === 'accept' || type === 'walkRequest' ? ( |
| 92 | + <> |
| 93 | + <p> |
| 94 | + {(userInfo as RequestUserInfo).breed} <S.InfoSeparator $height={8} />{' '} |
| 95 | + {(userInfo as RequestUserInfo).age} <S.InfoSeparator $height={8} />{' '} |
| 96 | + {(userInfo as RequestUserInfo).gender} |
| 97 | + </p> |
| 98 | + </> |
| 99 | + ) : ( |
| 100 | + <> |
| 101 | + {(userInfo as OtherUserInfo).location && <p>{(userInfo as OtherUserInfo).location}</p>} |
| 102 | + {(userInfo as OtherUserInfo).time && <p>{(userInfo as OtherUserInfo).time}</p>} |
| 103 | + </> |
| 104 | + )} |
| 105 | + </S.Info> |
| 106 | + </S.UserInfo> |
| 107 | + )} |
| 108 | + |
| 109 | + {type === 'report' && ( |
| 110 | + <> |
| 111 | + <h1>{modalContent?.title}</h1> |
| 112 | + <S.SelectWrapper> |
| 113 | + <Select |
| 114 | + options={reportOptions} |
| 115 | + value={selectedReportType} |
| 116 | + onChange={(value: SetStateAction<string>) => setSelectedReportType(value)} |
| 117 | + placeholder='신고 사유 선택' |
| 118 | + /> |
| 119 | + </S.SelectWrapper> |
| 120 | + </> |
| 121 | + )} |
| 122 | + |
| 123 | + {type === 'request' ? ( |
| 124 | + <S.Message as='textarea' type={type} className='message' placeholder={modalContent?.message} /> |
| 125 | + ) : type === 'progress' ? ( |
| 126 | + <S.Message type={type} className='message'> |
| 127 | + {modalContent?.message} |
| 128 | + </S.Message> |
| 129 | + ) : null} |
| 130 | + |
| 131 | + {type === 'reportComplete' && ( |
| 132 | + <> |
| 133 | + <h1>{modalContent?.title}</h1> |
| 134 | + <S.Message type={type}>{modalContent?.message}</S.Message> |
| 135 | + </> |
| 136 | + )} |
| 137 | + |
| 138 | + <S.ButtonGroup type={type}> |
| 139 | + {modalContent?.cancelText && ( |
| 140 | + <S.Button type={type} variant='cancel' onClick={onCancel}> |
| 141 | + {modalContent.cancelText} |
| 142 | + </S.Button> |
| 143 | + )} |
| 144 | + <S.Button type={type} variant='confirm' onClick={onConfirm}> |
| 145 | + {modalContent?.confirmText} |
| 146 | + </S.Button> |
| 147 | + </S.ButtonGroup> |
| 148 | + </S.ModalContent> |
| 149 | + </S.ModalOverlay> |
| 150 | + ) |
| 151 | +} |
| 152 | + |
| 153 | +export default WalkModal |
0 commit comments