Skip to content

Commit

Permalink
fix: 카카오 로그인 성별, 연령대 초기값 설정
Browse files Browse the repository at this point in the history
  • Loading branch information
bottlewook committed Mar 5, 2024
1 parent 0ba324a commit 1539f5b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 23 deletions.
35 changes: 13 additions & 22 deletions src/app/(my-page)/my-page/profile/page.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/* eslint-disable @typescript-eslint/no-misused-promises */

'use client';

import { useEffect, useMemo } from 'react';
Expand All @@ -9,7 +11,7 @@ import {
AGE_MAP, AgeType, GENDER_MAP, GenderType,
} from '@constants/dropdownMap';
import { AGE_OPTIONS, GENDER_OPTIONS } from '@constants/myPage';
import VALIDATION_MESSAGE_MAP from '@constants/validationMessage';
import { ISignUp } from '@remote/api/types/auth';
import useProfile from '@remote/queries/my-page/useProfile';
import useUpdateProfile from '@remote/queries/my-page/useUpdateProfile';
import DropdownField from '@shared/dropdown-field/DropdownField';
Expand All @@ -25,9 +27,9 @@ function ProfilePage() {
const { data: profile } = useProfile();
const { mutate } = useUpdateProfile();
const {
register, watch, reset, formState: {
errors, isDirty, isValid,
}, getValues,
register, watch, reset, handleSubmit, formState: {
isDirty, isValid,
},
} = useForm({
defaultValues: useMemo(() => {
return {
Expand All @@ -40,9 +42,8 @@ function ProfilePage() {
mode: 'onBlur',
});

const onSubmit = () => {
// eslint-disable-next-line no-console
const { gender, age } = getValues();
const onSubmit = (profileInfo: Partial<ISignUp>) => {
const { gender, age } = profileInfo;
if (gender != null && age != null) {
mutate({ gender, age });
}
Expand All @@ -52,8 +53,8 @@ function ProfilePage() {
reset({
id: profile?.value.id,
email: profile?.value.email,
gender: profile?.value.gender,
age: profile?.value.age,
gender: profile?.value.gender === 'OTHERS' ? 'MALE' : profile?.value.gender,
age: profile?.value.age === 'AGE_99' ? 'AGE_20' : profile?.value.age,
});
}, [profile, reset]);

Expand All @@ -66,24 +67,14 @@ function ProfilePage() {
label="아이디"
required
placeholder="아이디"
{...register('id', {
required: true,
pattern: VALIDATION_MESSAGE_MAP.id.value,
})}
hasError={!!errors.id}
helpMessage={VALIDATION_MESSAGE_MAP.id.message}
{...register('id')}
readOnly
/>
<TextField
label="이메일"
required
placeholder="이메일"
{...register('email', {
required: true,
pattern: VALIDATION_MESSAGE_MAP.email.value,
})}
hasError={!!errors.email}
helpMessage={VALIDATION_MESSAGE_MAP.email.message}
{...register('email')}
readOnly
/>
<Spacing size={12} />
Expand All @@ -102,7 +93,7 @@ function ProfilePage() {
options={AGE_OPTIONS}
{...register('age')}
/>
<FixedBottomButton onClick={onSubmit} type="submit" disabled={!isDirty || !isValid}>변경 사항 저장하기</FixedBottomButton>
<FixedBottomButton onClick={handleSubmit(onSubmit)} type="submit" disabled={!isDirty || !isValid}>변경 사항 저장하기</FixedBottomButton>
</main>
</>
);
Expand Down
2 changes: 1 addition & 1 deletion src/remote/queries/my-page/useUpdateProfile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { updateProfile } from '@/remote/api/requests/my-page/myPage.patch.api';
function useUpdateProfile() {
const router = useRouter();
const onSuccess = () => {
router.push('/');
router.push('/my-page');
toast.success('회원정보가 수정되었습니다.');
};
const onError = () => {
Expand Down

0 comments on commit 1539f5b

Please sign in to comment.