73 lines
1.7 KiB
TypeScript
73 lines
1.7 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>
|
||
|
||
const emailRegex = /^([a-zA-Z0-9.\-_]+|[а-яА-ЯёЁ0-9.\-_]+)@(([a-zA-Z0-9.\-]+)\.([a-zA-Z]{2,})|([a-zA-Z0-9.\-]+)\.([а-яА-ЯёЁ]{2,})|([а-яА-ЯёЁ0-9.\-]+)\.([a-zA-Z]{2,})|([а-яА-ЯёЁ0-9.\-]+)\.([а-яА-ЯёЁ]{2,}))$/i;
|
||
|
||
export const SignupFormSchema = z
|
||
.object({
|
||
full_name: z
|
||
.string()
|
||
.min(3, { error: 'register-error-name' })
|
||
.regex(/^[^0-9]*$/, { message: 'register-error-no-digits' })
|
||
.trim(),
|
||
email: z
|
||
.string()
|
||
.trim()
|
||
.refine(
|
||
(value) => emailRegex.test(value),
|
||
{ message: 'register-error-valid-email' }
|
||
),
|
||
phone: z
|
||
.string()
|
||
.min(12, { error: 'register-error-phone' }),
|
||
password: z
|
||
.string()
|
||
.min(8, { error: 'register-error-password-symbols' })
|
||
.regex(/[a-zA-Zа-яёА-ЯЁ]/, { error: 'register-error-password-one-letter' })
|
||
.regex(/[0-9]/, { error: 'register-error-password-one-digit' })
|
||
.trim(),
|
||
confirm_password: z
|
||
.string(),
|
||
agree: z
|
||
.string()
|
||
.min(2, { error: 'register-error-agree' })
|
||
})
|
||
.refine((data) => data.password === data.confirm_password, {
|
||
message: 'repeat-password',
|
||
path: ['confirm_password'],
|
||
});
|
||
|
||
export const loginFormSchema = z
|
||
.object({
|
||
email: z
|
||
.string()
|
||
.min(1, { error: 'login-error-email' })
|
||
.trim(),
|
||
password: z
|
||
.string()
|
||
.min(1, { error: 'login-error-password' })
|
||
.trim(),
|
||
})
|
||
|
||
export const localDevelopmentUrl = 'http://localhost';
|
||
|
||
export const testUserData = {
|
||
fullName: 'test',
|
||
email: 'test@mail.com',
|
||
subscriptionType: 'base'
|
||
} |