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

feat-fe: 이메일 인증 훅 구현 #880

Merged
merged 3 commits into from
Oct 22, 2024
Merged
Show file tree
Hide file tree
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
12 changes: 12 additions & 0 deletions frontend/src/api/domain/email.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,18 @@ const emailApis = {
body: { clubId, applicantIds, subject, content },
isFormData: true,
}),

postVerifyMail: async ({ email }: { email: string }) =>
apiClient.post({
path: '/verification-code',
body: { email },
}),

confirmVerifyCode: async ({ email, verificationCode }: { email: string; verificationCode: string }) =>
apiClient.post({
path: '/verify-code',
body: { email, verificationCode },
}),
};

export default emailApis;
1 change: 1 addition & 0 deletions frontend/src/hooks/useEmail/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { useMutation } from '@tanstack/react-query';

export default function useEmail() {
const { success } = useToast();

return useMutation({
mutationFn: (prop: { clubId: string; applicantIds: number[]; subject: string; content: string }) =>
emailApis.send(prop),
Expand Down
23 changes: 23 additions & 0 deletions frontend/src/hooks/useEmailVerify/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import emailApis from '@api/domain/email';
import { useToast } from '@contexts/ToastContext';
import { useMutation } from '@tanstack/react-query';

export default function useEmailVerify() {
const { success } = useToast();

const { mutate: postVerifyEmailMutate } = useMutation({
mutationFn: (prop: { email: string }) => emailApis.postVerifyMail(prop),
onSuccess: () => {
success('메일 전송에 성공했습니다!');
},
});

const { mutate: confirmEmailVerifyMutate } = useMutation({
mutationFn: (prop: { email: string; verificationCode: string }) => emailApis.confirmVerifyCode(prop),
onSuccess: () => {
success('이메일 인증에 성공했습니다!');
},
});

return { postVerifyEmailMutate, confirmEmailVerifyMutate };
}
34 changes: 34 additions & 0 deletions frontend/src/mocks/handlers/emailHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,40 @@ const emailHandlers = [
status: 200,
});
}),

http.post(`${EMAILS}/verification-code`, async ({ request }) => {
const { email } = (await request.json()) as { email: string };

await new Promise((resolve) => setTimeout(resolve, 2000));

if (!email) {
return new Response(null, {
status: 400,
statusText: 'malformed request body syntax',
});
}

return new Response(null, {
status: 200,
});
}),

http.post(`${EMAILS}/verify-code`, async ({ request }) => {
const { email, verificationCode } = (await request.json()) as { email: string; verificationCode: string };

await new Promise((resolve) => setTimeout(resolve, 2000));

if (!email || !verificationCode) {
return new Response(null, {
status: 400,
statusText: 'malformed request body syntax',
});
}

return new Response(null, {
status: 200,
});
}),
];

export default emailHandlers;
Loading