From 5771f4514cdc284e8fb5568dde21ced00d2cfd69 Mon Sep 17 00:00:00 2001 From: chaeseungyun Date: Thu, 20 Jun 2024 18:18:40 +0900 Subject: [PATCH] =?UTF-8?q?fix:=20=EB=94=94=EB=B0=94=EC=9A=B4=EC=8B=B1=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80=20=EB=B0=8F=20=ED=8C=8C=EB=9D=BC=EB=AF=B8?= =?UTF-8?q?=ED=84=B0=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/auth/index.ts | 3 +- src/page/Auth/components/Common/index.tsx | 39 ++++++++++++++++------- 2 files changed, 29 insertions(+), 13 deletions(-) diff --git a/src/api/auth/index.ts b/src/api/auth/index.ts index 51339bc7..8b154b22 100644 --- a/src/api/auth/index.ts +++ b/src/api/auth/index.ts @@ -51,7 +51,8 @@ export const changePassword = ({ phone_number, password } : { phone_number:strin export const loginByPhone = async (param: LoginParams) => { const { data } = await client.post('/owner/login', { - param, + account: param.account, + password: param.password, }); return LoginResponse.parse(data); diff --git a/src/page/Auth/components/Common/index.tsx b/src/page/Auth/components/Common/index.tsx index eacf7107..2ee2eb9d 100644 --- a/src/page/Auth/components/Common/index.tsx +++ b/src/page/Auth/components/Common/index.tsx @@ -8,6 +8,7 @@ import { changePassword } from 'api/auth'; import { phoneRegisterUser } from 'api/register'; import { isKoinError, sendClientError } from '@bcsdlab/koin'; import { useStep } from 'page/Auth/hook/useStep'; +import { useDebounce } from 'utils/hooks/useDebounce'; // eslint-disable-next-line import Done from '../Done/index'; import styles from './index.module.scss'; @@ -18,7 +19,6 @@ const setNewPassword = ( setError: UseFormSetError, ) => { changePassword({ phone_number, password }) - .then(() => sessionStorage.removeItem('accessToken')) .catch((e) => { if (isKoinError(e)) { setError('password', { type: 'custom', message: e.message }); @@ -28,7 +28,7 @@ const setNewPassword = ( }); }; -const registerUser = ( +interface RegisterParam { company_number: string, name: string, password: string, @@ -37,6 +37,19 @@ const registerUser = ( shop_name: string, attachment_urls: { file_url: string; }[], setError: UseFormSetError, +} + +const registerUser = ( + { + company_number, + name, + password, + phone_number, + shop_id, + shop_name, + attachment_urls, + setError, + }: RegisterParam, ) => { phoneRegisterUser({ company_number, name, password, phone_number, shop_id, shop_name, attachment_urls, @@ -64,6 +77,17 @@ export default function CommonLayout() { formState: { errors }, setError, getValues, setValue, } = method; + const debounce = useDebounce(registerUser, { + company_number: getValues('company_number'), + name: getValues('name'), + password: getValues('password'), + phone_number: getValues('phone_number'), + shop_id: getValues('shop_id'), + shop_name: getValues('shop_name'), + attachment_urls: getValues('attachment_urls'), + setError, + }); + const steps = useStep(isFindPassword ? 'find' : 'register'); const { nextStep, @@ -86,16 +110,7 @@ export default function CommonLayout() { if (index + 1 === totalStep && isFindPassword) { setNewPassword(getValues('phone_number'), getValues('password'), setError); } else if (index + 1 === totalStep && !isFindPassword) { - registerUser( - getValues('company_number'), - getValues('name'), - getValues('password'), - getValues('phone_number'), - getValues('shop_id'), - getValues('shop_name'), - getValues('attachment_urls'), - setError, - ); + debounce(); } nextStep(); }