52 lines
1.1 KiB
TypeScript
52 lines
1.1 KiB
TypeScript
import * as z from 'zod'
|
|
|
|
export type FormState =
|
|
| {
|
|
errors?: {
|
|
name?: string[]
|
|
email?: string[]
|
|
password?: string[]
|
|
}
|
|
message?: string
|
|
}
|
|
| undefined
|
|
|
|
export type FormAction = (
|
|
state: FormState,
|
|
formData: FormData
|
|
) => Promise<FormState>
|
|
|
|
export const SignupFormSchema = z
|
|
.object({
|
|
full_name: z
|
|
.string()
|
|
.min(3, { error: 'Name must be at least 3 characters long.' })
|
|
.trim(),
|
|
email: z.email({ error: 'Please enter a valid email.' }).trim(),
|
|
password: z
|
|
.string()
|
|
.min(8, { error: 'Be at least 8 characters long' })
|
|
.regex(/[a-zA-Z]/, { error: 'Contain at least one letter.' })
|
|
.regex(/[0-9]/, { error: 'Contain at least one number.' })
|
|
.trim(),
|
|
confirm_password: z
|
|
.string()
|
|
})
|
|
.refine((data) => data.password === data.confirm_password, {
|
|
message: 'passwordMismatchErrorMessage',
|
|
path: ['confirm_password'],
|
|
});
|
|
|
|
export const loginFormSchema = z
|
|
.object({
|
|
email: z
|
|
.string()
|
|
.min(1, { error: 'Email must be not empty' })
|
|
.trim(),
|
|
password: z
|
|
.string()
|
|
.min(1, { error: 'Password must be not empty' })
|
|
.trim(),
|
|
})
|
|
|
|
export const localDevelopmentUrl = 'http://localhost:81'; |