From 5be3d9a551296c0635ca23a4d229651047fd5bee Mon Sep 17 00:00:00 2001 From: "(hoooooony)" <(cjh41820@gmail.com)> Date: Thu, 20 Jun 2024 18:55:23 +0900 Subject: [PATCH] =?UTF-8?q?feat=20:=20=EC=98=A4=EB=84=88=20=EC=A0=95?= =?UTF-8?q?=EB=B3=B4=20=EB=93=B1=EB=A1=9D=20=EB=8B=A4=EC=9D=8C=20=EB=8B=A8?= =?UTF-8?q?=EA=B3=84=20=EB=A1=9C=EC=A7=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/model/auth/index.ts | 6 --- .../Signup/components/ownerInfoStep/index.tsx | 15 +++++++- .../Signup/components/phoneStep/index.tsx | 38 ++++++++++++++++++- src/page/Auth/Signup/index.tsx | 7 +++- src/page/Auth/components/Common/index.tsx | 29 +++++++------- 5 files changed, 70 insertions(+), 25 deletions(-) diff --git a/src/model/auth/index.ts b/src/model/auth/index.ts index e5235aba..e26e017c 100644 --- a/src/model/auth/index.ts +++ b/src/model/auth/index.ts @@ -10,11 +10,6 @@ export type LoginParams = z.infer; export const LoginResponse = z.object({ refresh_token: z.string(), token: z.string(), - user_type: z.union([ - z.literal('OWNER'), - z.literal('COOP'), - z.null(), - ]), }); export type LoginResponse = z.infer; @@ -50,7 +45,6 @@ export type OwnerShop = z.infer; export const OwnerResponse = z.object({ attachments: z.array(UserFile), company_number: z.string(), - email: z.string(), name: z.string(), shops: z.array(OwnerShop), }); diff --git a/src/page/Auth/Signup/components/ownerInfoStep/index.tsx b/src/page/Auth/Signup/components/ownerInfoStep/index.tsx index 58cadd49..09998bad 100644 --- a/src/page/Auth/Signup/components/ownerInfoStep/index.tsx +++ b/src/page/Auth/Signup/components/ownerInfoStep/index.tsx @@ -1,5 +1,5 @@ import { useFormContext } from 'react-hook-form'; -import { useState, ChangeEvent } from 'react'; +import { useState, useEffect, ChangeEvent } from 'react'; import { ReactComponent as FileIcon } from 'assets/svg/auth/file-icon.svg'; import { ReactComponent as DeleteFile } from 'assets/svg/auth/delete-file.svg'; import FileUploadModal from 'page/Auth/Signup/components/fileUploadModal'; @@ -18,9 +18,10 @@ interface OwnerInfo { interface OwnerInfoStepProps { onSearch: () => void; + setIsStepComplete: (state: boolean) => void; } -export default function OwnerInfoStep({ onSearch }: OwnerInfoStepProps) { +export default function OwnerInfoStep({ onSearch, setIsStepComplete }: OwnerInfoStepProps) { const { register, watch, @@ -77,6 +78,16 @@ export default function OwnerInfoStep({ onSearch }: OwnerInfoStepProps) { } }; + const watchedValues = watch(['name', 'shop_name', 'company_number', 'attachment_urls']); + + useEffect(() => { + const values = watch(); + const isComplete = values.name && values.shop_name + && values.company_number + && values.attachment_urls; + setIsStepComplete(!!isComplete); + }, [watchedValues, setIsStepComplete, watch]); + return (
diff --git a/src/page/Auth/Signup/components/phoneStep/index.tsx b/src/page/Auth/Signup/components/phoneStep/index.tsx index f4f06f0e..8fe0d41f 100644 --- a/src/page/Auth/Signup/components/phoneStep/index.tsx +++ b/src/page/Auth/Signup/components/phoneStep/index.tsx @@ -195,11 +195,45 @@ export default function PhoneStep({ setIsStepComplete }: PhoneStepProps) {
비밀번호 - + +
+ {errors.password && ( + <> + + {errors.password.message} + + )} +
비밀번호 확인 - + +
+ {errors.passwordConfirm && ( + <> + + {errors.passwordConfirm.message} + + )} +
); diff --git a/src/page/Auth/Signup/index.tsx b/src/page/Auth/Signup/index.tsx index b35871d2..08e18ce0 100644 --- a/src/page/Auth/Signup/index.tsx +++ b/src/page/Auth/Signup/index.tsx @@ -75,7 +75,12 @@ export default function SignUp() { {steps.index === 2 && (steps.isSearch ? ( - ) : steps.setIsSearch(true)} /> + ) : ( + steps.setIsSearch(true)} + setIsStepComplete={setStepPhoneComplete} + /> + ) )} ); diff --git a/src/page/Auth/components/Common/index.tsx b/src/page/Auth/components/Common/index.tsx index 2ee2eb9d..48be3318 100644 --- a/src/page/Auth/components/Common/index.tsx +++ b/src/page/Auth/components/Common/index.tsx @@ -8,7 +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'; +import sha256 from 'utils/ts/SHA-256'; // eslint-disable-next-line import Done from '../Done/index'; import styles from './index.module.scss'; @@ -77,17 +77,6 @@ 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, @@ -104,13 +93,25 @@ export default function CommonLayout() { // eslint-disable-next-line const progressPercentage = (index + 1) / totalStep * 100; - const stepCheck = () => { + const stepCheck = async () => { if (isComplete) navigate('/login'); if (!errors.root) { if (index + 1 === totalStep && isFindPassword) { setNewPassword(getValues('phone_number'), getValues('password'), setError); } else if (index + 1 === totalStep && !isFindPassword) { - debounce(); + const hash = await sha256(getValues('password')); + registerUser( + { + company_number: getValues('company_number'), + name: getValues('name'), + password: hash, + phone_number: getValues('phone_number'), + shop_id: getValues('shop_id'), + shop_name: getValues('shop_name'), + attachment_urls: getValues('attachment_urls'), + setError, + }, + ); } nextStep(); }