From 2f559f1e37e182d68af116e4b8168e92eb436a01 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9D=B4=EC=98=81=EC=9A=B0?= Date: Wed, 6 Dec 2023 20:54:44 +0900 Subject: [PATCH] =?UTF-8?q?[feat]=20reset=20password=20API=20=EC=9A=94?= =?UTF-8?q?=EC=B2=AD=20=EB=B0=8F=20=EC=B9=A9=20font=20weight=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/signup.ts | 10 ++++++++ components/Chip/Chip.tsx | 2 +- pages/resetPassword/step2.tsx | 48 ++++++++++++++++++++++------------- 3 files changed, 41 insertions(+), 19 deletions(-) diff --git a/api/signup.ts b/api/signup.ts index 84fdb6a..6e63856 100644 --- a/api/signup.ts +++ b/api/signup.ts @@ -64,3 +64,13 @@ export const postResetPassword = async (email: string) => { }, }); }; + +export const putPassword = async (payload: { password: string; email: string; passwordVerify: string }) => { + return fetchData(`/api/v1/auth/reset-password?email=${payload.email}`, { + method: 'PUT', + body: JSON.stringify(payload), + headers: { + 'Content-Type': 'application/json', + }, + }); +}; diff --git a/components/Chip/Chip.tsx b/components/Chip/Chip.tsx index 3f7d4a2..32df881 100644 --- a/components/Chip/Chip.tsx +++ b/components/Chip/Chip.tsx @@ -37,7 +37,7 @@ export default function Chip({ label, onDelete, clicked, onChipClick, onlyText } }`} onClick={onDivClick} > - + {label} {!onlyText && ( diff --git a/pages/resetPassword/step2.tsx b/pages/resetPassword/step2.tsx index b638086..edb9bfd 100644 --- a/pages/resetPassword/step2.tsx +++ b/pages/resetPassword/step2.tsx @@ -1,5 +1,5 @@ /* eslint-disable react-hooks/rules-of-hooks */ -import React, { useEffect, useState } from 'react'; +import React from 'react'; import ResetPasswordLayout from '@/components/layouts/ResetPasswordLayout.tsx'; import Space from '@/components/Space.tsx'; import Typography from '@/components/Typography/Typography.tsx'; @@ -8,10 +8,11 @@ import Input from '@/components/Input/Input.tsx'; import { isRequired, isValidPassword, isSamePassword } from '@/utils/validCheck.ts'; import { useTranslation as UseTranslation } from 'next-i18next'; import Button from '@/components/Button/Button.tsx'; -import ModalBox from '@/components/Modal/ModalBox.tsx'; import type { GetStaticPropsContext } from 'next'; import { serverSideTranslations } from 'next-i18next/serverSideTranslations'; -import { emit } from 'process'; +import { putPassword } from '@/api/signup'; +import { useRouter } from 'next/router'; +import useModal from '@/hooks/useModal'; export const getStaticProps = async ({ locale }: GetStaticPropsContext) => ({ props: { @@ -21,21 +22,42 @@ export const getStaticProps = async ({ locale }: GetStaticPropsContext) => ({ export default function step2() { const { t } = UseTranslation('common'); - const [resetPassword, setResetPassword] = useState(false); + const router = useRouter(); const { register, getValues, + watch, formState: { errors }, } = UseForm({ mode: 'onChange' }); - const fnResetPassword = () => { - console.log('error is ??', errors); - return !errors.password?.message && !errors.passwordConfirm?.message && setResetPassword(true); + const { openModal, closeModal } = useModal(); + + const fnResetPassword = async () => { + if (!errors.password?.message && !errors.passwordConfirm?.message) { + const params = { + email: router.query.email as string, + password: watch('password'), + passwordVerify: watch('passwordConfirm'), + }; + await putPassword(params); + openModal({ + props: { + title: 'Password changed!', + content: 'Your password has been successfully changed.', + buttonType: 'default', + buttonName: 'Try Log in', + handleClose: () => { + closeModal(); + router.push('/login'); + }, + }, + }); + } }; return ( -
+
@@ -87,16 +109,6 @@ export default function step2() { > Reset password - - {resetPassword && ( - - )}
); }