Files
no-copy-frontend/src/app/actions/definitions.ts
T
2026-01-07 19:47:15 +07:00

89 lines
2.1 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
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-z0-9.\-_]+|[а-яё0-9.\-_]+)@(([a-z0-9.\-]+)\.([a-z]{2,})|([a-z0-9.\-]+)\.([а-яё]{2,})|([а-яё0-9.\-]+)\.([a-z]{2,})|([а-яё0-9.\-]+)\.([а-яё]{2,}))$/i;
export const SignupFormSchema = z
.object({
fullName: z
.string()
.min(2, { error: 'register-error-name' })
.regex(/^[^0-9]*$/, { message: 'register-error-no-digits' })
/* .refine(
(value) => !/\p{Emoji}/u.test(value),
{ message: 'no-emoji-allowed' }
) */
.trim(),
email: z
.string()
.trim()
.refine(
(value) => value === value.toLowerCase(),
{ message: 'email-no-uppercase' }
)
.refine(
(value) => emailRegex.test(value),
{ message: 'email-invalid' }
),
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' })
/* .refine(
(value) => !/\p{Emoji}/u.test(value),
{ message: 'no-emoji-allowed' }
) */
.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 = process.env.DEV_URL ? process.env.DEV_URL : 'http://localhost';
export const API_BASE_URL = process.env.NODE_ENV === 'development'
? localDevelopmentUrl
: 'http://app:8080';
export const testUserData = {
fullName: 'test',
email: 'test@mail.com',
subscriptionType: 'base'
}