Skip to content

Commit

Permalink
Merge pull request #2 from JongMany/feat/function-calling
Browse files Browse the repository at this point in the history
[Feat] 회원가입 시 실패 UI 수정
  • Loading branch information
JongMany authored Oct 24, 2024
2 parents 9bccb2c + 92b5a77 commit bae6be8
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 12 deletions.
10 changes: 4 additions & 6 deletions src/components/auth/join/join-form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,12 @@ export default function JoinForm() {
// Validation
const validationResult = joinFormSchema.safeParse(joinForm);
if (!validationResult.success) {
const errorMessages = validationResult.error.format();
console.log(errorMessages); // Validation errors will be logged here
showToast('error', <>로그인 오류</>);
// const errorMessages = validationResult.error.format();
const errors = Object.values(validationResult.error.flatten().fieldErrors);
showToast('error', <p>{errors[0]}</p>);
return;
}

// Register Fetch


fetch(`${process.env.NEXT_PUBLIC_API_URL || ''}/api/v1/auth/register`, {
method: 'POST',
Expand All @@ -47,7 +45,7 @@ export default function JoinForm() {
alert('회원가입 성공');
router.replace('/login');
} else {
alert(res.message);
showToast('error', <p>{res.message}</p>);
}
});
};
Expand Down
12 changes: 6 additions & 6 deletions src/models/auth/join.schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@ import { z } from 'zod';

export const joinFormSchema = z
.object({
email: z.string().email({ message: 'Invalid email address' }),
email: z.string().email({ message: '올바른 이메일 형식이 아닙니다.' }),
password: z
.string()
.min(8, { message: 'Password must be at least 8 characters long' }),
.min(8, { message: '비밀번호는 8자리 이상이어야 합니다.' }),
passwordConfirm: z.string(),
name: z.string().min(1, { message: 'Name is required' }),
name: z.string().min(2, { message: '이름은 2자리 이상이어야 합니다.' }),
phoneNumber: z
.string()
.regex(/^\d+$/, { message: 'Phone number must contain only digits' }),
group: z.enum(['A', 'B', 'C', 'D'], { message: 'Invalid group selection' }),
.regex(/^\d+$/, { message: '올바른 전화번호 형식이어야 합니다.' }),
group: z.enum(['A', 'B', 'C', 'D'], { message: '그룹은 A, B, C 또는 D 중 하나여야 합니다.' }),
})
.refine((data) => data.password === data.passwordConfirm, {
message: 'Passwords do not match',
message: '비밀번호가 일치하지 않습니다.',
path: ['passwordConfirm'],
});

0 comments on commit bae6be8

Please sign in to comment.