diff --git a/apps/shelter/src/pages/settings/password/index.tsx b/apps/shelter/src/pages/settings/password/index.tsx index ef1ed7b3..0d9ff65a 100644 --- a/apps/shelter/src/pages/settings/password/index.tsx +++ b/apps/shelter/src/pages/settings/password/index.tsx @@ -19,6 +19,11 @@ import IoEyeSharp from 'shared/assets/IoEyeSharp'; import LogoImageBox from 'shared/components/LogoImageBox'; import useToggle from 'shared/hooks/useToggle'; import { ChangePasswordRequestData } from 'shared/types/apis/auth'; +import { + newPassword, + newPasswordConfirm, + oldPassword, +} from 'shared/utils/validations'; import * as z from 'zod'; import { changeShelterPassword } from '@/apis/auth'; @@ -27,17 +32,9 @@ type Schema = z.infer; const schema = z .object({ - oldPassword: z.string().min(1, '기본 비밀번호 정보는 필수입니다'), - newPassword: z.string().min(1, '변경 비밀번호 정보는 필수입니다'), - // TODO - // - // .regex( - // /^(?=.*[!@#$%^&*()\-_=+[\]\\|{};:'",<.>/?]+)(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{8,}$/, - // '비밀번호는 필수 정보입니다(8자 이상)', - // ), - newPasswordConfirm: z - .string() - .min(1, '변경 비밀번호 확인 정보는 필수입니다'), + oldPassword, + newPassword, + newPasswordConfirm, }) .refine( ({ newPassword, newPasswordConfirm }) => newPassword === newPasswordConfirm, diff --git a/apps/shelter/src/pages/signin/index.tsx b/apps/shelter/src/pages/signin/index.tsx index be57d2f1..a8f6239b 100644 --- a/apps/shelter/src/pages/signin/index.tsx +++ b/apps/shelter/src/pages/signin/index.tsx @@ -24,6 +24,7 @@ import IoEyeSharp from 'shared/assets/IoEyeSharp'; import useToggle from 'shared/hooks/useToggle'; import useAuthStore from 'shared/store/authStore'; import { SigninRequestData } from 'shared/types/apis/auth'; +import { email, password } from 'shared/utils/validations'; import * as z from 'zod'; import { signinShelter } from '@/apis/auth'; @@ -32,11 +33,8 @@ import PATH from '@/constants/path'; type Schema = z.infer; const schema = z.object({ - email: z - .string() - .min(1, '이메일이 입려되지 않았습니다') - .email('유효하지 않은 이메일입니다'), - password: z.string().min(1, '비밀번호가 입력되지 않았습니다'), + email, + password, }); export default function SigninPage() { diff --git a/apps/shelter/src/pages/signup/index.tsx b/apps/shelter/src/pages/signup/index.tsx index 694cbc4a..ac2b1042 100644 --- a/apps/shelter/src/pages/signup/index.tsx +++ b/apps/shelter/src/pages/signup/index.tsx @@ -26,6 +26,18 @@ import IoEyeOff from 'shared/assets/IoEyeOff'; import IoEyeSharp from 'shared/assets/IoEyeSharp'; import useToggle from 'shared/hooks/useToggle'; import { CheckDuplicatedEmailRequestData } from 'shared/types/apis/auth'; +import { + address, + addressDetail, + email, + isEmailDuplicated, + isOpenedAddress, + name, + password, + passwordConfirm, + phoneNumber, + sparePhoneNumber, +} from 'shared/utils/validations'; import * as z from 'zod'; import { checkDuplicatedShelterEmail, signupShelter } from '@/apis/auth'; @@ -36,43 +48,20 @@ type Schema = z.infer; const schema = z .object({ - email: z - .string() - .min(1, '이메일은 필수 정보입니다') - .regex( - /^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/, - '이메일 형식에 맞게 적어주세요', - ), - isEmailDuplicated: z.boolean(), - password: z.string().min(1, '비밀번호는 필수 정보입니다'), - // TODO 나중에 추가 예정 - // - // .regex( - // /^(?=.*[!@#$%^&*()\-_=+[\]\\|{};:'",<.>/?]+)(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{8,}$/, - // '비밀번호는 필수 정보입니다(8자 이상)', - // ), - passwordConfirm: z.string().min(1, '비밀번호 확인 정보는 필수입니다'), - name: z.string().min(1, '보호소 이름 정보는 필수입니다'), - address: z.string().min(1, '보호소 주소 정보는 필수입니다'), - addressDetail: z.string().min(1, '보호소 상세주소 정보는 필수입니다'), - isOpenedAddress: z.boolean(), - phoneNumber: z - .string() - .min(1, '보호소 전화번호 정보는 필수입니다') - .refine( - (val) => !Number.isNaN(Number(val)), - '전화번호 형식은 숫자입니다', - ), - sparePhoneNumber: z - .string() - .refine( - (val) => !Number.isNaN(Number(val)) || val === '', - '전화번호 형식은 숫자입니다', - ), + email, + isEmailDuplicated, + password, + passwordConfirm, + name, + address, + addressDetail, + isOpenedAddress, + phoneNumber, + sparePhoneNumber, }) .refine(({ password, passwordConfirm }) => password === passwordConfirm, { - message: '비밀번호가 일치하지 않습니다', path: ['passwordConfirm'], + message: '비밀번호가 일치하지 않습니다', }); export default function SignupPage() { diff --git a/apps/volunteer/src/pages/settings/password/index.tsx b/apps/volunteer/src/pages/settings/password/index.tsx index c5b0ceb0..8d0c2328 100644 --- a/apps/volunteer/src/pages/settings/password/index.tsx +++ b/apps/volunteer/src/pages/settings/password/index.tsx @@ -19,6 +19,11 @@ import IoEyeSharp from 'shared/assets/IoEyeSharp'; import LogoImageBox from 'shared/components/LogoImageBox'; import useToggle from 'shared/hooks/useToggle'; import { ChangePasswordRequestData } from 'shared/types/apis/auth'; +import { + newPassword, + newPasswordConfirm, + oldPassword, +} from 'shared/utils/validations'; import * as z from 'zod'; import { changeVolunteerPassword } from '@/apis/auth'; @@ -27,17 +32,9 @@ type Schema = z.infer; const schema = z .object({ - oldPassword: z.string().min(1, '기본 비밀번호 정보는 필수입니다'), - newPassword: z.string().min(1, '변경 비밀번호 정보는 필수입니다'), - // TODO - // - // .regex( - // /^(?=.*[!@#$%^&*()\-_=+[\]\\|{};:'",<.>/?]+)(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{8,}$/, - // '비밀번호는 필수 정보입니다(8자 이상)', - // ), - newPasswordConfirm: z - .string() - .min(1, '변경 비밀번호 확인 정보는 필수입니다'), + oldPassword, + newPassword, + newPasswordConfirm, }) .refine( ({ newPassword, newPasswordConfirm }) => newPassword === newPasswordConfirm, diff --git a/apps/volunteer/src/pages/signin/index.tsx b/apps/volunteer/src/pages/signin/index.tsx index c32a5e39..ee3a1506 100644 --- a/apps/volunteer/src/pages/signin/index.tsx +++ b/apps/volunteer/src/pages/signin/index.tsx @@ -24,6 +24,7 @@ import IoEyeSharp from 'shared/assets/IoEyeSharp'; import useToggle from 'shared/hooks/useToggle'; import useAuthStore from 'shared/store/authStore'; import { SigninRequestData } from 'shared/types/apis/auth'; +import { email, password } from 'shared/utils/validations'; import * as z from 'zod'; import { signinVolunteer } from '@/apis/auth'; @@ -32,11 +33,8 @@ import PATH from '@/constants/path'; type Schema = z.infer; const schema = z.object({ - email: z - .string() - .min(1, '이메일이 입려되지 않았습니다') - .email('유효하지 않은 이메일입니다'), - password: z.string().min(1, '비밀번호가 입력되지 않았습니다'), + email, + password, }); export default function SigninPage() { diff --git a/apps/volunteer/src/pages/signup/index.tsx b/apps/volunteer/src/pages/signup/index.tsx index 3ca9cc8b..2dbf74e8 100644 --- a/apps/volunteer/src/pages/signup/index.tsx +++ b/apps/volunteer/src/pages/signup/index.tsx @@ -26,6 +26,16 @@ import RadioGroup from 'shared/components/RadioGroup'; import useToggle from 'shared/hooks/useToggle'; import { CheckDuplicatedEmailRequestData } from 'shared/types/apis/auth'; import { PersonGenderEng, PersonGenderKor } from 'shared/types/gender'; +import { + birthDate, + email, + gender, + isEmailDuplicated, + name, + password, + passwordConfirm, + phoneNumber, +} from 'shared/utils/validations'; import * as z from 'zod'; import { checkDuplicatedVolunteerEmail, signupVolunteer } from '@/apis/auth'; @@ -36,46 +46,18 @@ type Schema = z.infer; const schema = z .object({ - email: z - .string() - .min(1, '이메일은 필수 정보입니다') - .regex( - /^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/, - '이메일 형식에 맞게 적어주세요', - ), - isEmailDuplicated: z.boolean(), - password: z.string(), - // TODO 나중에 추가 예정 - // - // .regex( - // /^(?=.*[!@#$%^&*()\-_=+[\]\\|{};:'",<.>/?]+)(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{8,}$/, - // '비밀번호는 필수 정보입니다(8자 이상)', - // ), - passwordConfirm: z.string().min(1, '비밀번호 확인 정보는 필수입니다'), - name: z.string().min(1, '이름 정보는 필수입니다'), - birthDate: z - .string() - .min(1, '생년월일 정보는 필수입니다') - .refine( - (val) => new Date(val) < new Date(), - `${new Date() - .toLocaleDateString('ko-KR') - .split('') - .filter((v) => v !== ' ') - .join('')} 이전으로 선택해주세요`, - ), - phoneNumber: z - .string() - .min(1, '전화번호 정보는 필수입니다') - .refine( - (val) => !Number.isNaN(Number(val)), - '전화번호 형식은 숫자입니다', - ), - gender: z.enum(['FEMALE', 'MALE']), + email, + isEmailDuplicated, + password, + passwordConfirm, + name, + birthDate, + phoneNumber, + gender, }) .refine(({ password, passwordConfirm }) => password === passwordConfirm, { - message: '비밀번호가 일치하지 않습니다', path: ['passwordConfirm'], + message: '비밀번호가 일치하지 않습니다', }); export default function SignupPage() { diff --git a/packages/shared/utils/validations.ts b/packages/shared/utils/validations.ts index 7466a24a..bc98b2e9 100644 --- a/packages/shared/utils/validations.ts +++ b/packages/shared/utils/validations.ts @@ -20,7 +20,7 @@ export const password = z.string().min(1, '비밀번호 정보는 필수입니 export const passwordConfirm = z .string() .min(1, '비밀번호 확인 정보는 필수입니다'); -export const oldPassword = z.string().min(1, '기본 비밀번호 정보는 필수입니다'); +export const oldPassword = z.string().min(1, '기존 비밀번호 정보는 필수입니다'); export const newPassword = z.string().min(1, '변경 비밀번호 정보는 필수입니다'); // TODO 나중에 추가 예정 //