Skip to content

Commit

Permalink
Refactor: #144 동일한 신규 비밀번호 입력 시 Validation 작성
Browse files Browse the repository at this point in the history
  • Loading branch information
Yoonyesol committed Sep 22, 2024
1 parent 0ed1545 commit 28ab3dc
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
4 changes: 4 additions & 0 deletions src/constants/formValidationRules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,10 @@ export const USER_AUTH_VALIDATION_RULES = deepFreeze({
required: '비밀번호를 한 번 더 입력해 주세요.',
validate: (value: string) => value === password || '비밀번호가 일치하지 않습니다.',
}),
NEW_PASSWORD: (currentPassword: string) => ({
...USER_AUTH_VALIDATION_RULES.PASSWORD,
validate: (value: string) => value !== currentPassword || '신규 비밀번호가 현재 비밀번호와 동일합니다.',
}),
ID: {
required: '아이디를 입력해 주세요.',
minLength: {
Expand Down
4 changes: 1 addition & 3 deletions src/pages/setting/UserPasswordSettingPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ export default function UserPasswordSettingPage() {
});

const onSubmit = async (data: UpdatePasswordForm) => {
if (watch('password') === watch('newPassword')) return toastError('신규 비밀번호가 현재 비밀번호와 동일합니다.');

const { checkNewPassword, ...submitData } = data;

// ToDo: useAxios 훅을 이용한 네트워크 로직으로 변경
Expand Down Expand Up @@ -53,7 +51,7 @@ export default function UserPasswordSettingPage() {
label="신규 비밀번호"
type="password"
errors={errors.newPassword?.message}
register={register('newPassword', USER_AUTH_VALIDATION_RULES.PASSWORD)}
register={register('newPassword', USER_AUTH_VALIDATION_RULES.NEW_PASSWORD(watch('password')))}
/>

{/* 신규 비밀번호 확인 */}
Expand Down

0 comments on commit 28ab3dc

Please sign in to comment.