diff --git a/features/profile/components/organisms/profile-edit-form.tsx b/features/profile/components/organisms/profile-edit-form.tsx index d1889f30..f18aff7c 100644 --- a/features/profile/components/organisms/profile-edit-form.tsx +++ b/features/profile/components/organisms/profile-edit-form.tsx @@ -1,10 +1,17 @@ 'use client'; import { useRouter } from 'next/navigation'; -import { FormProvider, SubmitHandler, useForm } from 'react-hook-form'; +import { useEffect } from 'react'; +import { + FormProvider, + SubmitHandler, + useForm, + useWatch, +} from 'react-hook-form'; import { useImagePresignUrl } from '@/apis'; import { Button } from '@/components/atoms'; +import { FormTextArea, FormTextField } from '@/components/molecules'; import { useCurrentMemberInfo, useToast } from '@/hooks'; import { css } from '@/styled-system/css'; import { flex } from '@/styled-system/patterns'; @@ -17,7 +24,6 @@ import { } from '../../apis'; import { useProfileData, useProfileEditForm } from '../../hooks'; import { ProfileEditImageSection } from './profile-edit-image-section'; -import { ProfileEditTextInfoSection } from './profile-edit-text-info-section'; interface ProfileEditFormProps { nickname: string; @@ -147,7 +153,32 @@ export function ProfileEditForm() { } }; + const nickname = useWatch({ control: methods.control, name: 'nickname' }); + const introduction = useWatch({ + control: methods.control, + name: 'introduction', + }); + + useEffect(() => { + if (!profileData) return; + + const { nickname: currentNickname, introduction: currentIntroduction } = + profileData; + + if (currentNickname) methods.setValue('nickname', currentNickname); + if (currentIntroduction) + methods.setValue('introduction', currentIntroduction); + // eslint-disable-next-line react-hooks/exhaustive-deps + }, [profileData]); + if (!profileData) return null; + + const isDirty = () => { + const { nickname: prevNickname, introduction: prevIntroduction } = + profileData; + return !(nickname === prevNickname && introduction === prevIntroduction); + }; + return ( - +