Skip to content

Commit 2b9ed27

Browse files
committed
๐Ÿ› Fix : FamilyRole ๋ณ€์ˆ˜๋ช… ๋ณ€๊ฒฝ
1 parent 1de524f commit 2b9ed27

File tree

3 files changed

+33
-44
lines changed

3 files changed

+33
-44
lines changed

โ€Žsrc/modals/PositionChoiceModal/index.tsx

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,39 +4,36 @@ import { RadioGroup } from '@mui/material'
44
import { useModalStore } from '~stores/modalStore'
55
import { ActionButton } from '~components/Button/ActionButton'
66
import { FAMILY_ROLE } from '~constants/familyRole'
7+
import { FamilyRole } from '~types/common'
78

8-
interface PositionChoiceModalProps {
9-
onSelect: (position: string) => void
10-
initialValue?: string | null
11-
}
12-
13-
const positions = Object.values(FAMILY_ROLE)
9+
const familyRoles = Object.values(FAMILY_ROLE)
10+
type FamilyRoleChoiceModalProps = { onSelectRole: (role: FamilyRole) => void; initialRole: FamilyRole }
1411

15-
export default function PositionChoiceModal({ onSelect, initialValue = 'null' }: PositionChoiceModalProps) {
16-
const [value, setValue] = useState(initialValue)
12+
export default function FamilyRoleChoiceModal({ onSelectRole, initialRole }: FamilyRoleChoiceModalProps) {
13+
const [selectedFamilyRole, setSelectedFamilyRole] = useState<FamilyRole>(initialRole)
1714
const { popModal } = useModalStore()
1815

1916
const handleConfirm = () => {
20-
if (value !== null) {
21-
onSelect(value)
17+
if (selectedFamilyRole !== null) {
18+
onSelectRole(selectedFamilyRole)
2219
popModal()
2320
}
2421
}
2522

2623
return (
2724
<S.DialogContainer open={true} onClose={popModal}>
2825
<S.DialogTitle>๊ฐ€์กฑ ํฌ์ง€์…˜ ์„ ํƒ</S.DialogTitle>
29-
<RadioGroup value={value} onChange={e => setValue(e.target.value)}>
26+
<RadioGroup value={selectedFamilyRole} onChange={e => setSelectedFamilyRole(e.target.value as FamilyRole)}>
3027
<S.RadioGroupContainer>
31-
{positions.map(position => (
32-
<S.StyledFormControlLabel key={position} value={position} control={<S.StyledRadio />} label={position} />
28+
{familyRoles.map(role => (
29+
<S.StyledFormControlLabel key={role} value={role} control={<S.StyledRadio />} label={role} />
3330
))}
3431
</S.RadioGroupContainer>
3532
</RadioGroup>
3633

3734
<S.ButtonContainer>
3835
<ActionButton onClick={popModal}>์ทจ์†Œ</ActionButton>
39-
<ActionButton onClick={handleConfirm} disabled={!value} $fontWeight='700'>
36+
<ActionButton onClick={handleConfirm} disabled={!selectedFamilyRole} $fontWeight='700'>
4037
ํ™•์ธ
4138
</ActionButton>
4239
</S.ButtonContainer>

โ€Žsrc/pages/RegisterPage/Register/index.tsx

Lines changed: 21 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { Input } from '~components/Input'
66
import RegisterAvatarModal from '~modals/RegisterAvatarModal'
77
import { useModalStore } from '~stores/modalStore'
88
import { ActionButton } from '~components/Button/ActionButton'
9-
import PositionChoiceModal from '~modals/PositionChoiceModal'
9+
import FamilyRoleChoiceModal from '~modals/PositionChoiceModal'
1010
import { useGeolocation } from '~hooks/useGeolocation'
1111
import { useOwnerProfileStore } from '~stores/ownerProfileStore'
1212
import { validateOwnerProfile } from '~utils/validateOwnerProfile'
@@ -18,17 +18,6 @@ import { createRegister } from '~apis/register/createRegister'
1818
import { FamilyRole } from '~types/common'
1919
import { useEffect } from 'react'
2020

21-
const positionLabelMap: Record<FamilyRole, string> = {
22-
MOTHER: '์—„๋งˆ',
23-
FATHER: '์•„๋น ',
24-
OLDER_BROTHER: 'ํ˜•',
25-
ELDER_BROTHER: '์˜ค๋น ',
26-
ELDER_SISTER: '์–ธ๋‹ˆ',
27-
OLDER_SISTER: '๋ˆ„๋‚˜',
28-
GRANDFATHER: 'ํ• ์•„๋ฒ„์ง€',
29-
GRANDMOTHER: 'ํ• ๋จธ๋‹ˆ',
30-
}
31-
3221
export default function Register() {
3322
const { ownerProfile, setOwnerProfile } = useOwnerProfileStore()
3423
const { location, getCurrentLocation } = useGeolocation()
@@ -49,16 +38,16 @@ export default function Register() {
4938
const registerData = {
5039
email,
5140
provider,
52-
name: ownerProfile.nickName,
41+
name: ownerProfile.name,
5342
gender: ownerProfile.gender as 'MALE' | 'FEMALE',
54-
address: ownerProfile.location,
55-
familyRole: ownerProfile.position as FamilyRole,
56-
profileImg: ownerProfile.avatar || '',
43+
address: ownerProfile.address,
44+
familyRole: ownerProfile.familyRole as FamilyRole,
45+
profileImg: ownerProfile.profileImg || '',
5746
}
5847

5948
const response = await createRegister({
6049
...registerData,
61-
provider: registerData.provider as 'KAKAO' | 'NAVER' | 'GOOGLE',
50+
provider: registerData.provider as 'KAKAO' | 'GOOGLE',
6251
})
6352
if (response.code === 201) {
6453
pushModal(<RegisterDogPage />)
@@ -69,7 +58,7 @@ export default function Register() {
6958
}
7059
useEffect(() => {
7160
if (location.address) {
72-
setOwnerProfile({ location: location.address })
61+
setOwnerProfile({ address: location.address })
7362
}
7463
}, [location.address, setOwnerProfile])
7564
const handleLocationClick = () => {
@@ -78,15 +67,18 @@ export default function Register() {
7867

7968
const handleRoleClick = () => {
8069
pushModal(
81-
<PositionChoiceModal onSelect={position => setOwnerProfile({ position })} initialValue={ownerProfile.position} />
70+
<FamilyRoleChoiceModal
71+
onSelectRole={role => setOwnerProfile({ familyRole: role })}
72+
initialRole={ownerProfile.familyRole}
73+
/>
8274
)
8375
}
8476

8577
const handleAvatarClick = () => {
8678
pushModal(
8779
<RegisterAvatarModal
88-
onSelectAvatar={avatarSrc => setOwnerProfile({ avatar: avatarSrc })}
89-
initialSelectedAvatar={ownerProfile.avatar}
80+
onSelectAvatar={avatarSrc => setOwnerProfile({ profileImg: avatarSrc })}
81+
initialSelectedAvatar={ownerProfile.profileImg}
9082
/>
9183
)
9284
}
@@ -105,9 +97,9 @@ export default function Register() {
10597
<S.TextSection weight='700'>๊ฒฌ์ฃผ๋‹˜์— ๋Œ€ํ•ด{'\n'}์•Œ๋ ค์ฃผ์„ธ์š”</S.TextSection>
10698

10799
<S.AddOwnerAvatarBtnWrapper>
108-
{ownerProfile.avatar ? (
100+
{ownerProfile.profileImg ? (
109101
<S.Avatar onClick={handleAvatarClick}>
110-
<img src={ownerProfile.avatar} alt='์„ ํƒ๋œ ์•„๋ฐ”ํƒ€' />
102+
<img src={ownerProfile.profileImg} alt='์„ ํƒ๋œ ์•„๋ฐ”ํƒ€' />
111103
</S.Avatar>
112104
) : (
113105
<S.AddOwnerAvatarBtn onClick={handleAvatarClick}>
@@ -121,15 +113,15 @@ export default function Register() {
121113
<S.NickNameWrapper>
122114
<Input
123115
placeholder='๋‹‰๋„ค์ž„ ์ž…๋ ฅ'
124-
value={ownerProfile.nickName}
125-
onChange={e => setOwnerProfile({ nickName: e.target.value })}
116+
value={ownerProfile.name}
117+
onChange={e => setOwnerProfile({ name: e.target.value })}
126118
/>
127119
</S.NickNameWrapper>
128-
<S.PositionChoiceBtn onClick={handleRoleClick} $hasSelected={!!ownerProfile.position}>
129-
{ownerProfile.position ? positionLabelMap[ownerProfile.position as FamilyRole] : '๊ฐ€์กฑ ํฌ์ง€์…˜ ์„ ํƒ'}
120+
<S.PositionChoiceBtn onClick={handleRoleClick} $hasSelected={!!ownerProfile.familyRole}>
121+
{ownerProfile.familyRole || '๊ฐ€์กฑ ํฌ์ง€์…˜ ์„ ํƒ'}
130122
</S.PositionChoiceBtn>
131-
<S.LocationBtn onClick={handleLocationClick} $hasSelected={!!ownerProfile.location}>
132-
{ownerProfile.location || '๋‚ด ๋™๋„ค ๋ถˆ๋Ÿฌ์˜ค๊ธฐ'}
123+
<S.LocationBtn onClick={handleLocationClick} $hasSelected={!!ownerProfile.address}>
124+
{ownerProfile.address || '๋‚ด ๋™๋„ค ๋ถˆ๋Ÿฌ์˜ค๊ธฐ'}
133125
</S.LocationBtn>
134126
<S.GenderSelectBtnWrapper>
135127
<GenderSelectButton

โ€Žsrc/stores/ownerProfileStore.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,4 @@ export const useOwnerProfileStore = create<OwnerProfileStore>(set => ({
2121
set(state => ({
2222
ownerProfile: { ...state.ownerProfile, ...profile },
2323
})),
24-
}))
24+
}))

0 commit comments

Comments
ย (0)