Skip to content

Commit

Permalink
Merge pull request #247 from gloddy-dev/feature/245-join
Browse files Browse the repository at this point in the history
Refactoring : 회원가입 중 에러 수정 및 리팩토링
  • Loading branch information
guesung authored Aug 19, 2023
2 parents 1ed789f + 8504e0a commit 034ab8a
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 25 deletions.
12 changes: 12 additions & 0 deletions src/apis/auth/mutations.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {
SignUpResponse,
postEmail,
postEmailVerify,
postLogin,
Expand All @@ -7,7 +8,9 @@ import {
postSMSVerify,
postSignUp,
} from '.';
import { setTokenAtCookie } from '@/utils/auth/tokenController';
import { useMutation } from '@tanstack/react-query';
import { useRouter } from 'next/navigation';

export const useLoginMutation = () => {
return useMutation(postLogin);
Expand Down Expand Up @@ -50,7 +53,16 @@ export const useEmailVerifyMutation = () => {
};

export const useSignUpMutation = () => {
const router = useRouter();
return useMutation(postSignUp, {
onSuccess: (data: SignUpResponse) => {
const {
userId,
token: { accessToken, refreshToken },
} = data;
setTokenAtCookie({ accessToken, refreshToken, userId });
router.push('grouping');
},
onError: (error) => {
// TODO : 회원가입 에러에 대한 처리
},
Expand Down
11 changes: 10 additions & 1 deletion src/app/(sub)/join/funnels/step3/components/EmailForm.client.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export default memo(function EmailForm() {
const {
register,
handleSubmit,
setValue,
formState: { isDirty },
} = hookForm;

Expand Down Expand Up @@ -48,7 +49,15 @@ export default memo(function EmailForm() {

const handlePassClick = () => {
open(({ exit }) => (
<Modal isOpen={true} variant="warning" onOkClick={nextStep} onCancelClick={exit}>
<Modal
isOpen={true}
variant="warning"
onOkClick={() => {
setValue('schoolInfo.email', '');
nextStep();
}}
onCancelClick={exit}
>
<Spacing size={32} />
<Image src="/icons/48/warning.svg" width={48} height={48} alt="warning" />
<Spacing size={12} />
Expand Down
18 changes: 1 addition & 17 deletions src/app/(sub)/join/funnels/step5/components/InputForm.client.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ import { useSignUpMutation } from '@/apis/auth';
import { Button, ButtonGroup } from '@/components/Button';
import { Tag } from '@/components/Tag';
import { personalityList } from '@/constants/personalityList';
import { setTokenAtCookie } from '@/utils/auth/tokenController';
import { useRouter } from 'next/navigation';
import { useCallback } from 'react';

import type { SignUpState } from '../../../type';
Expand All @@ -16,7 +14,6 @@ import type { GenderType } from '@/types';
export default function InputForm() {
const { handleSubmit, watch } = useJoinContext();
const { mutate: mutateSignUp } = useSignUpMutation();
const router = useRouter();

const onSubmit = async (data: SignUpState) => {
const { verifyEmailNumber, verifyNumber, birth, personalityIdList, gender, ...rest } = data;
Expand All @@ -26,20 +23,7 @@ export default function InputForm() {
personalities: personalityIdList.map((id) => personalityList[id].keywordInEnglish),
gender: (gender === '남성' ? 'MAIL' : 'FEMAIL') as GenderType,
};
mutateSignUp(signUpRequest, {
onSuccess: (data) => {
const {
token: { accessToken, refreshToken },
userId,
} = data;
setTokenAtCookie({
accessToken,
refreshToken,
userId,
});
router.push('/grouping');
},
});
mutateSignUp(signUpRequest);
};

return (
Expand Down
1 change: 1 addition & 0 deletions src/components/SegmentGroup/SegmentGroup.client.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ function Segment<T extends ValueType>({ label, value, className }: SegmentProps<
className
)}
onClick={() => onChange(value)}
type="button"
>
{label}
</button>
Expand Down
12 changes: 5 additions & 7 deletions src/constants/dummyData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,16 +69,14 @@ export const CREATE_GROUP_DUMMY_DATA: CreateGroupRequest = {
};

export const DUMMY_SIGN_UP_DATA = {
phoneNumber: '010-5728-9353',
imageUrl:
'https://gloddy.s3.ap-northeast-2.amazonaws.com/file/87d8b6c4-fcda-4588-8334-b3ca96e635a0.png',
phoneNumber: '010-5728-9310',
schoolInfo: {
school: '가천대학교',
email: 'gueit214@gachon.ac.kr',
school: '경희대학교',
email: 'gueit201@gachon.ac.kr',
certifiedStudent: true,
},
nickname: 'string',
birth: '2023-07-22',
nickname: '박규리',
birth: '2000-02-14',
gender: 'MAIL',
personalities: ['OUTGOING'],
};
Expand Down

0 comments on commit 034ab8a

Please sign in to comment.