Skip to content

Commit

Permalink
πŸ› Fix : FamilyRole λ³€μˆ˜λͺ… λ³€κ²½
Browse files Browse the repository at this point in the history
  • Loading branch information
kimjuyoung78 committed Dec 7, 2024
1 parent 1de524f commit 2b9ed27
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 44 deletions.
25 changes: 11 additions & 14 deletions src/modals/PositionChoiceModal/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,39 +4,36 @@ import { RadioGroup } from '@mui/material'
import { useModalStore } from '~stores/modalStore'
import { ActionButton } from '~components/Button/ActionButton'
import { FAMILY_ROLE } from '~constants/familyRole'
import { FamilyRole } from '~types/common'

interface PositionChoiceModalProps {
onSelect: (position: string) => void
initialValue?: string | null
}

const positions = Object.values(FAMILY_ROLE)
const familyRoles = Object.values(FAMILY_ROLE)
type FamilyRoleChoiceModalProps = { onSelectRole: (role: FamilyRole) => void; initialRole: FamilyRole }

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

const handleConfirm = () => {
if (value !== null) {
onSelect(value)
if (selectedFamilyRole !== null) {
onSelectRole(selectedFamilyRole)
popModal()
}
}

return (
<S.DialogContainer open={true} onClose={popModal}>
<S.DialogTitle>κ°€μ‘± ν¬μ§€μ…˜ 선택</S.DialogTitle>
<RadioGroup value={value} onChange={e => setValue(e.target.value)}>
<RadioGroup value={selectedFamilyRole} onChange={e => setSelectedFamilyRole(e.target.value as FamilyRole)}>
<S.RadioGroupContainer>
{positions.map(position => (
<S.StyledFormControlLabel key={position} value={position} control={<S.StyledRadio />} label={position} />
{familyRoles.map(role => (
<S.StyledFormControlLabel key={role} value={role} control={<S.StyledRadio />} label={role} />
))}
</S.RadioGroupContainer>
</RadioGroup>

<S.ButtonContainer>
<ActionButton onClick={popModal}>μ·¨μ†Œ</ActionButton>
<ActionButton onClick={handleConfirm} disabled={!value} $fontWeight='700'>
<ActionButton onClick={handleConfirm} disabled={!selectedFamilyRole} $fontWeight='700'>
확인
</ActionButton>
</S.ButtonContainer>
Expand Down
50 changes: 21 additions & 29 deletions src/pages/RegisterPage/Register/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { Input } from '~components/Input'
import RegisterAvatarModal from '~modals/RegisterAvatarModal'
import { useModalStore } from '~stores/modalStore'
import { ActionButton } from '~components/Button/ActionButton'
import PositionChoiceModal from '~modals/PositionChoiceModal'
import FamilyRoleChoiceModal from '~modals/PositionChoiceModal'
import { useGeolocation } from '~hooks/useGeolocation'
import { useOwnerProfileStore } from '~stores/ownerProfileStore'
import { validateOwnerProfile } from '~utils/validateOwnerProfile'
Expand All @@ -18,17 +18,6 @@ import { createRegister } from '~apis/register/createRegister'
import { FamilyRole } from '~types/common'
import { useEffect } from 'react'

const positionLabelMap: Record<FamilyRole, string> = {
MOTHER: 'μ—„λ§ˆ',
FATHER: 'μ•„λΉ ',
OLDER_BROTHER: 'ν˜•',
ELDER_BROTHER: '였빠',
ELDER_SISTER: 'μ–Έλ‹ˆ',
OLDER_SISTER: 'λˆ„λ‚˜',
GRANDFATHER: '할아버지',
GRANDMOTHER: 'ν• λ¨Έλ‹ˆ',
}

export default function Register() {
const { ownerProfile, setOwnerProfile } = useOwnerProfileStore()
const { location, getCurrentLocation } = useGeolocation()
Expand All @@ -49,16 +38,16 @@ export default function Register() {
const registerData = {
email,
provider,
name: ownerProfile.nickName,
name: ownerProfile.name,
gender: ownerProfile.gender as 'MALE' | 'FEMALE',
address: ownerProfile.location,
familyRole: ownerProfile.position as FamilyRole,
profileImg: ownerProfile.avatar || '',
address: ownerProfile.address,
familyRole: ownerProfile.familyRole as FamilyRole,
profileImg: ownerProfile.profileImg || '',
}

const response = await createRegister({
...registerData,
provider: registerData.provider as 'KAKAO' | 'NAVER' | 'GOOGLE',
provider: registerData.provider as 'KAKAO' | 'GOOGLE',
})
if (response.code === 201) {
pushModal(<RegisterDogPage />)
Expand All @@ -69,7 +58,7 @@ export default function Register() {
}
useEffect(() => {
if (location.address) {
setOwnerProfile({ location: location.address })
setOwnerProfile({ address: location.address })
}
}, [location.address, setOwnerProfile])
const handleLocationClick = () => {
Expand All @@ -78,15 +67,18 @@ export default function Register() {

const handleRoleClick = () => {
pushModal(
<PositionChoiceModal onSelect={position => setOwnerProfile({ position })} initialValue={ownerProfile.position} />
<FamilyRoleChoiceModal
onSelectRole={role => setOwnerProfile({ familyRole: role })}
initialRole={ownerProfile.familyRole}
/>
)
}

const handleAvatarClick = () => {
pushModal(
<RegisterAvatarModal
onSelectAvatar={avatarSrc => setOwnerProfile({ avatar: avatarSrc })}
initialSelectedAvatar={ownerProfile.avatar}
onSelectAvatar={avatarSrc => setOwnerProfile({ profileImg: avatarSrc })}
initialSelectedAvatar={ownerProfile.profileImg}
/>
)
}
Expand All @@ -105,9 +97,9 @@ export default function Register() {
<S.TextSection weight='700'>κ²¬μ£Όλ‹˜μ— λŒ€ν•΄{'\n'}μ•Œλ €μ£Όμ„Έμš”</S.TextSection>

<S.AddOwnerAvatarBtnWrapper>
{ownerProfile.avatar ? (
{ownerProfile.profileImg ? (
<S.Avatar onClick={handleAvatarClick}>
<img src={ownerProfile.avatar} alt='μ„ νƒλœ 아바타' />
<img src={ownerProfile.profileImg} alt='μ„ νƒλœ 아바타' />
</S.Avatar>
) : (
<S.AddOwnerAvatarBtn onClick={handleAvatarClick}>
Expand All @@ -121,15 +113,15 @@ export default function Register() {
<S.NickNameWrapper>
<Input
placeholder='λ‹‰λ„€μž„ μž…λ ₯'
value={ownerProfile.nickName}
onChange={e => setOwnerProfile({ nickName: e.target.value })}
value={ownerProfile.name}
onChange={e => setOwnerProfile({ name: e.target.value })}
/>
</S.NickNameWrapper>
<S.PositionChoiceBtn onClick={handleRoleClick} $hasSelected={!!ownerProfile.position}>
{ownerProfile.position ? positionLabelMap[ownerProfile.position as FamilyRole] : 'κ°€μ‘± ν¬μ§€μ…˜ 선택'}
<S.PositionChoiceBtn onClick={handleRoleClick} $hasSelected={!!ownerProfile.familyRole}>
{ownerProfile.familyRole || 'κ°€μ‘± ν¬μ§€μ…˜ 선택'}
</S.PositionChoiceBtn>
<S.LocationBtn onClick={handleLocationClick} $hasSelected={!!ownerProfile.location}>
{ownerProfile.location || 'λ‚΄ 동넀 뢈러였기'}
<S.LocationBtn onClick={handleLocationClick} $hasSelected={!!ownerProfile.address}>
{ownerProfile.address || 'λ‚΄ 동넀 뢈러였기'}
</S.LocationBtn>
<S.GenderSelectBtnWrapper>
<GenderSelectButton
Expand Down
2 changes: 1 addition & 1 deletion src/stores/ownerProfileStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@ export const useOwnerProfileStore = create<OwnerProfileStore>(set => ({
set(state => ({
ownerProfile: { ...state.ownerProfile, ...profile },
})),
}))
}))

0 comments on commit 2b9ed27

Please sign in to comment.