- Create apps/web/lib/phone.ts with VN_PHONE_REGEX, normalizePhone, formatPhone, and zaloHref helpers - Deduplicate phone regex: auth.ts and inquiry.ts now import VN_PHONE_REGEX from @/lib/phone instead of defining their own local patterns - Replace raw .replace(/^0/, '84') in inquiry-detail-dialog.tsx and lead-detail-dialog.tsx with zaloHref(); use formatPhone() for display Resolves GOO-209 Co-Authored-By: Paperclip <noreply@paperclip.ing>
40 lines
1.2 KiB
TypeScript
40 lines
1.2 KiB
TypeScript
import { z } from 'zod';
|
|
|
|
import { VN_PHONE_REGEX as phoneRegex } from '@/lib/phone';
|
|
|
|
export const loginSchema = z.object({
|
|
phone: z
|
|
.string()
|
|
.min(1, 'Vui lòng nhập số điện thoại')
|
|
.regex(phoneRegex, 'Số điện thoại không hợp lệ'),
|
|
password: z.string().min(1, 'Vui lòng nhập mật khẩu'),
|
|
});
|
|
|
|
export const registerSchema = z
|
|
.object({
|
|
fullName: z
|
|
.string()
|
|
.min(1, 'Vui lòng nhập họ tên')
|
|
.min(2, 'Họ tên phải có ít nhất 2 ký tự'),
|
|
phone: z
|
|
.string()
|
|
.min(1, 'Vui lòng nhập số điện thoại')
|
|
.regex(phoneRegex, 'Số điện thoại không hợp lệ'),
|
|
email: z
|
|
.string()
|
|
.email('Email không hợp lệ')
|
|
.optional()
|
|
.or(z.literal('')),
|
|
password: z
|
|
.string()
|
|
.min(8, 'Mật khẩu phải có ít nhất 8 ký tự'),
|
|
confirmPassword: z.string().min(1, 'Vui lòng xác nhận mật khẩu'),
|
|
})
|
|
.refine((data) => data.password === data.confirmPassword, {
|
|
message: 'Mật khẩu xác nhận không khớp',
|
|
path: ['confirmPassword'],
|
|
});
|
|
|
|
export type LoginFormData = z.infer<typeof loginSchema>;
|
|
export type RegisterFormData = z.infer<typeof registerSchema>;
|