Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Hotfix] #161 배포 환경 버그 || 견주정보수정 familyRole : undefind 오류 해결 #162

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions src/modals/OwnerUpdateModal/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { FAMILY_ROLE } from '~constants/familyRole'
import { REVERSE_FAMILY_ROLE } from '~constants/familyRole'

import { FamilyRole, Gender } from '~types/common'
// import { validateOwnerProfile } from '~utils/validateOwnerProfile'

interface updateProfileType {
familyRole: FamilyRole
Expand All @@ -28,13 +29,13 @@ interface updateProfileType {
export default function OwnerUpdateModal() {
const pushModal = useModalStore(state => state.pushModal)
const popModal = useModalStore(state => state.popModal)

const [ownerProfile, setOwnerProfile] = useState<updateProfileType>({
familyRole: '',
familyRole: 'MOTHER',
gender: 'MALE', // 기본값
name: '',
profileImg: '',
})

const [ProfileImage, setProfileImage] = useState<React.ComponentType | null>(null)

const queryClient = useQueryClient()
Expand All @@ -46,8 +47,11 @@ export default function OwnerUpdateModal() {

useEffect(() => {
if (data?.data) {
setOwnerProfile(data?.data)
console.log('ownerProfile :', ownerProfile)
setOwnerProfile(prev => ({
...prev, // 기존 상태 유지
...data.data, // 서버 데이터 병합
familyRole: data.data.familyRole || prev.familyRole, // familyRole이 없으면 기존 값 유지
}))
}
}, [data])

Expand All @@ -58,10 +62,6 @@ export default function OwnerUpdateModal() {
queryClient.invalidateQueries({ queryKey: queryKey.family.UpdateOwner() })
popModal()
},
onError: error => {
console.error('정보 수정 실패:', error)
alert('정보 수정에 실패했습니다. 다시 시도해주세요.')
},
})

useEffect(() => {
Expand Down Expand Up @@ -123,12 +123,12 @@ export default function OwnerUpdateModal() {
// familyRole을 영어 Enum 값으로 변환
const updatedProfile = {
...ownerProfile,
familyRole: REVERSE_FAMILY_ROLE[ownerProfile.familyRole || ''], // value를 key로 변환
familyRole: REVERSE_FAMILY_ROLE[ownerProfile.familyRole] || ownerProfile.familyRole, // ENUM 변환 또는 기존 값 유지
}

console.log('프로필 업데이트 요청 데이터:', updatedProfile)
updateOwnerMutation.mutate(updatedProfile) // 변환된 데이터를 서버로 전송
updateOwnerMutation.mutate(updatedProfile) // 서버로 전송
}

if (isLoading) return <div>Loading...</div>
if (isError) return <div>Error loading data</div>

Expand Down Expand Up @@ -181,7 +181,7 @@ export default function OwnerUpdateModal() {
</S.OwnerProfileSection>

<S.ToastWrapper>
<ActionButton $fontWeight='700' $bgColor='gc_1' onClick={handleUpdateClick}>
<ActionButton $fontWeight='700' $bgColor={'default'} onClick={handleUpdateClick}>
수정 완료
</ActionButton>
<Toast />
Expand Down
Loading