From 18b582bcffbb3fee0ab7545446c82071984f0338 Mon Sep 17 00:00:00 2001 From: jisu Seo Date: Tue, 16 Jan 2024 19:22:08 +0900 Subject: [PATCH 1/3] =?UTF-8?q?Refactor:=20=EA=B8=B0=EB=B3=B8=20=EC=9D=B4?= =?UTF-8?q?=EB=AF=B8=EC=A7=80=20=ED=91=9C=EC=8B=9C=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/Auth/SignupInfo/UserInfoImg.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/Auth/SignupInfo/UserInfoImg.tsx b/src/components/Auth/SignupInfo/UserInfoImg.tsx index 904fd8b9..f699ed36 100644 --- a/src/components/Auth/SignupInfo/UserInfoImg.tsx +++ b/src/components/Auth/SignupInfo/UserInfoImg.tsx @@ -28,7 +28,7 @@ const UserInfoImg = ({ register, setValue, inputValue }: AuthImgProps) => { Date: Wed, 17 Jan 2024 17:00:47 +0900 Subject: [PATCH 2/3] =?UTF-8?q?Refactor:=20=EB=93=9C=EB=9E=8D=EB=8B=A4?= =?UTF-8?q?=EC=9A=B4=20=EC=9E=84=EC=8B=9C=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../SignupInfo/AuthDropDown/AuthDropDown.tsx | 83 +++++++++---------- .../AuthDropDown/AuthDropDownOption.tsx | 61 +++++++------- .../Auth/SignupInfo/SignupInfoForm.tsx | 25 +----- src/components/Mypage/UserInfoForm.tsx | 29 ++----- src/pages/mypage/editUserInfo.page.tsx | 5 +- src/utils/authSelectOptions.ts | 15 ++++ 6 files changed, 99 insertions(+), 119 deletions(-) create mode 100644 src/utils/authSelectOptions.ts diff --git a/src/components/Auth/SignupInfo/AuthDropDown/AuthDropDown.tsx b/src/components/Auth/SignupInfo/AuthDropDown/AuthDropDown.tsx index 0ff87eea..1c57aed0 100644 --- a/src/components/Auth/SignupInfo/AuthDropDown/AuthDropDown.tsx +++ b/src/components/Auth/SignupInfo/AuthDropDown/AuthDropDown.tsx @@ -1,33 +1,26 @@ import AuthDropDownOption from './AuthDropDownOption'; -import * as Select from '@radix-ui/react-select'; -import { DownIcon } from '@components/common/icons/Icons'; -import { UseFormRegister, UseFormSetValue } from 'react-hook-form'; +import { UseFormRegister } from 'react-hook-form'; interface Props { label: string; - text: string; options: SelectOption[]; name: string; register: UseFormRegister; - setValue: UseFormSetValue; - - // initialState: string | null; - // setState: React.Dispatch>; } -const AuthDropDown = ({ - label, - text, - options, - name, - register, - setValue, -}: Props) => { - const onSelectClick = (e: any) => { - setValue(name, e); - }; - +const AuthDropDown = ({ label, options, name, register }: Props) => { return ( +
+

{label}

+ +
+ //
//

{label}

//
//
-
- -

{label}

- - - - - - - - - - {options.map((option) => ( - - {option.value} - - ))} - - - -
-
+ //
+ // + //

{label}

+ // + // + // + // + // + // + // + // + // + // {options.map((option) => ( + // + // {option.value} + // + // ))} + // + // + // + //
+ //
); }; diff --git a/src/components/Auth/SignupInfo/AuthDropDown/AuthDropDownOption.tsx b/src/components/Auth/SignupInfo/AuthDropDown/AuthDropDownOption.tsx index f1f2a0a0..077cad1e 100644 --- a/src/components/Auth/SignupInfo/AuthDropDown/AuthDropDownOption.tsx +++ b/src/components/Auth/SignupInfo/AuthDropDown/AuthDropDownOption.tsx @@ -1,7 +1,3 @@ -import { CheckIcon } from '@components/common/icons/Icons'; -import * as Select from '@radix-ui/react-select'; -import React, { ReactNode, Ref } from 'react'; - // interface Props { // children: string; // clickHandler?: VoidFunction; @@ -42,30 +38,39 @@ import React, { ReactNode, Ref } from 'react'; // export default AuthDropDownOption; -interface SelectItemProps { - value: string; - children: ReactNode; - className?: string; - disabled?: boolean; -} +// interface SelectItemProps { +// value: string; +// children: ReactNode; +// className?: string; +// disabled?: boolean; +// } + +// const AuthDropDownOption = React.forwardRef( +// ( +// { children, className, ...props }: SelectItemProps, +// forwardedRef: Ref, +// ) => { +// return ( +// +// {children} +// +// +// +// +// ); +// }, +// ); -const AuthDropDownOption = React.forwardRef( - ( - { children, className, ...props }: SelectItemProps, - forwardedRef: Ref, - ) => { - return ( - - {children} - - - - - ); - }, -); +// export default AuthDropDownOption; + +interface Props { + option: SelectOption; +} +const AuthDropDownOption = ({ option }: Props) => { + return ; +}; export default AuthDropDownOption; diff --git a/src/components/Auth/SignupInfo/SignupInfoForm.tsx b/src/components/Auth/SignupInfo/SignupInfoForm.tsx index 8c5732ff..5fe4e480 100644 --- a/src/components/Auth/SignupInfo/SignupInfoForm.tsx +++ b/src/components/Auth/SignupInfo/SignupInfoForm.tsx @@ -8,6 +8,7 @@ import { useEffect } from 'react'; import SubmitBtn from '@components/common/button/SubmitBtn'; import AuthDropDown from './AuthDropDown/AuthDropDown'; import AuthNicknameInputBox from '../AuthInput/AuthInputBox/AuthNicknameInputBox'; +import { ageArr, genderArr } from '@utils/authSelectOptions'; const SignupInfoForm = () => { const { @@ -23,8 +24,6 @@ const SignupInfoForm = () => { mode: 'onChange', criteriaMode: 'all', }); - // const [genderType, setGenderType] = useState(null); - // const [ageType, setAgeType] = useState(null); const navigate = useNavigate(); @@ -43,8 +42,8 @@ const SignupInfoForm = () => { const res = await putMember({ nickname: nickname, profileImageUrl: profileImageUrl, - genderType: genderType, - ageType: ageType, + ageType: ageType === '' ? null : ageType, + genderType: genderType === '' ? null : genderType, }); if (res.status === 200) { navigate('/'); @@ -77,19 +76,15 @@ const SignupInfoForm = () => {
@@ -101,17 +96,3 @@ const SignupInfoForm = () => { }; export default SignupInfoForm; - -const genderArr: SelectOption[] = [ - { id: 'FEMALE', value: '여' }, - { id: 'MALE', value: '남' }, - { id: 'NON_BINARY', value: '기타' }, -]; - -const ageArr: SelectOption[] = [ - { id: 'TEENAGER', value: '10대' }, - { id: 'TWENTIES', value: '20대' }, - { id: 'THIRTIES', value: '30대' }, - { id: 'FOURTIES', value: '40대' }, - { id: 'ABOVE_FIFTIES', value: '50대 이상' }, -]; diff --git a/src/components/Mypage/UserInfoForm.tsx b/src/components/Mypage/UserInfoForm.tsx index 2925a017..6126a244 100644 --- a/src/components/Mypage/UserInfoForm.tsx +++ b/src/components/Mypage/UserInfoForm.tsx @@ -8,6 +8,7 @@ import SubmitBtn from '@components/common/button/SubmitBtn'; import UserInfoImg from '@components/Auth/SignupInfo/UserInfoImg'; import AuthNicknameInputBox from '@components/Auth/AuthInput/AuthInputBox/AuthNicknameInputBox'; import AuthDropDown from '@components/Auth/SignupInfo/AuthDropDown/AuthDropDown'; +import { ageArr, genderArr } from '@utils/authSelectOptions'; const UserInfoForm = () => { const { @@ -29,20 +30,22 @@ const UserInfoForm = () => { useEffect(() => { setValue('nickname', userInfo?.nickname); setValue('profileImageUrl', userInfo?.profileImageUrl); + setValue('genderType', userInfo?.genderType); + setValue('ageType', userInfo?.ageType); }, [userInfo]); const onInfoSubmit: SubmitHandler = async (data) => { - const { nickname, profileImageUrl } = data; + const { nickname, profileImageUrl, genderType, ageType } = data; try { const res = await putMember({ nickname: nickname, profileImageUrl: profileImageUrl, - ageType: null, - genderType: null, + ageType: ageType === '' ? null : ageType, + genderType: genderType === '' ? null : genderType, }); if (res.status === 200) { - navigate('/'); + navigate('/mypage'); } } catch (err) { console.error('회원정보 수정 요청 중 에러 발생', err); @@ -80,19 +83,15 @@ const UserInfoForm = () => {
@@ -104,17 +103,3 @@ const UserInfoForm = () => { }; export default UserInfoForm; - -const genderArr: SelectOption[] = [ - { id: '1', value: '여' }, - { id: '2', value: '남' }, - { id: '3', value: '기타' }, -]; - -const ageArr: SelectOption[] = [ - { id: '1', value: '10대' }, - { id: '2', value: '20대' }, - { id: '3', value: '30대' }, - { id: '4', value: '40대' }, - { id: '5', value: '50대 이상' }, -]; diff --git a/src/pages/mypage/editUserInfo.page.tsx b/src/pages/mypage/editUserInfo.page.tsx index 02cb39a8..aab9743d 100644 --- a/src/pages/mypage/editUserInfo.page.tsx +++ b/src/pages/mypage/editUserInfo.page.tsx @@ -12,8 +12,9 @@ const EditUserInfo = () => { backHandler={() => { navigate('/mypage'); }} - showSave - saveHandler={() => {}}> + // showSave + // saveHandler={() => {}} + > 회원정보 수정
diff --git a/src/utils/authSelectOptions.ts b/src/utils/authSelectOptions.ts new file mode 100644 index 00000000..0e544aa7 --- /dev/null +++ b/src/utils/authSelectOptions.ts @@ -0,0 +1,15 @@ +export const genderArr: SelectOption[] = [ + { id: '', value: '성별을 선택해주세요.' }, + { id: 'FEMALE', value: '여' }, + { id: 'MALE', value: '남' }, + { id: 'NON_BINARY', value: '기타' }, +]; + +export const ageArr: SelectOption[] = [ + { id: '', value: '연령대를 설정해주세요.' }, + { id: 'TEENAGER', value: '10대' }, + { id: 'TWENTIES', value: '20대' }, + { id: 'THIRTIES', value: '30대' }, + { id: 'FOURTIES', value: '40대' }, + { id: 'ABOVE_FIFTIES', value: '50대 이상' }, +]; From 89ea6bf937e81172b10ca2edeeb17cda4b24ea67 Mon Sep 17 00:00:00 2001 From: jisu Seo Date: Wed, 17 Jan 2024 17:28:24 +0900 Subject: [PATCH 3/3] =?UTF-8?q?Refactor:=20=EB=B9=84=EB=B0=80=EB=B2=88?= =?UTF-8?q?=ED=98=B8=20=ED=99=95=EC=9D=B8=20=EB=A1=9C=EC=A7=81=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 --- src/components/Mypage/EditPassword/EditPwForm.tsx | 10 ++++++++++ src/pages/signup/signup.page.tsx | 10 ++++++++++ 2 files changed, 20 insertions(+) diff --git a/src/components/Mypage/EditPassword/EditPwForm.tsx b/src/components/Mypage/EditPassword/EditPwForm.tsx index 75d3c58f..43438f67 100644 --- a/src/components/Mypage/EditPassword/EditPwForm.tsx +++ b/src/components/Mypage/EditPassword/EditPwForm.tsx @@ -7,6 +7,7 @@ import { } from '@components/Auth'; import SubmitBtn from '@components/common/button/SubmitBtn'; import { AxiosError } from 'axios'; +import { useEffect } from 'react'; import { SubmitHandler, useForm } from 'react-hook-form'; import { useNavigate } from 'react-router-dom'; @@ -18,6 +19,7 @@ const EditPwForm = () => { watch, resetField, setError, + trigger, formState: { errors, isValid }, } = useForm({ mode: 'onChange', @@ -26,6 +28,14 @@ const EditPwForm = () => { const navigate = useNavigate(); + const password = watch('password'); + const passwordCheck = watch('passwordCheck'); + useEffect(() => { + if (passwordCheck) { + trigger('passwordCheck'); + } + }, [password, trigger]); + const onEditPwSubmit: SubmitHandler = async (data) => { const { currentPw, password } = data; diff --git a/src/pages/signup/signup.page.tsx b/src/pages/signup/signup.page.tsx index 77c69186..def45d2d 100644 --- a/src/pages/signup/signup.page.tsx +++ b/src/pages/signup/signup.page.tsx @@ -10,6 +10,7 @@ import { BackBox } from '@components/common'; import SubmitBtn from '@components/common/button/SubmitBtn'; import { CheckboxIcon } from '@components/common/icons/Icons'; import { setItem } from '@utils/localStorageFun'; +import { useEffect } from 'react'; import { SubmitHandler, useForm } from 'react-hook-form'; import { useNavigate } from 'react-router-dom'; @@ -21,6 +22,7 @@ const Signup = () => { watch, resetField, setError, + trigger, formState: { errors, isValid }, } = useForm({ mode: 'onChange', @@ -29,6 +31,14 @@ const Signup = () => { const navigate = useNavigate(); + const password = watch('password'); + const passwordCheck = watch('passwordCheck'); + useEffect(() => { + if (passwordCheck) { + trigger('passwordCheck'); + } + }, [password, trigger]); + const onSignupSubmit: SubmitHandler = async (data) => { const { email, password } = data;