2025-11-27 21:33:53 +07:00
|
|
|
|
import * as z from 'zod'
|
|
|
|
|
|
|
2025-11-28 15:28:15 +07:00
|
|
|
|
export type FormState =
|
|
|
|
|
|
| {
|
|
|
|
|
|
errors?: {
|
|
|
|
|
|
name?: string[]
|
|
|
|
|
|
email?: string[]
|
|
|
|
|
|
password?: string[]
|
|
|
|
|
|
}
|
|
|
|
|
|
message?: string
|
|
|
|
|
|
}
|
|
|
|
|
|
| undefined
|
|
|
|
|
|
|
|
|
|
|
|
export type FormAction = (
|
|
|
|
|
|
state: FormState,
|
|
|
|
|
|
formData: FormData
|
|
|
|
|
|
) => Promise<FormState>
|
|
|
|
|
|
|
2025-12-19 16:11:58 +07:00
|
|
|
|
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;
|
2025-12-16 11:24:05 +07:00
|
|
|
|
|
2025-11-28 12:38:14 +07:00
|
|
|
|
export const SignupFormSchema = z
|
|
|
|
|
|
.object({
|
2025-12-19 16:11:58 +07:00
|
|
|
|
fullName: z
|
2025-11-28 12:38:14 +07:00
|
|
|
|
.string()
|
2025-12-19 16:11:58 +07:00
|
|
|
|
.min(2, { error: 'register-error-name' })
|
2025-12-17 15:43:13 +07:00
|
|
|
|
.regex(/^[^0-9]*$/, { message: 'register-error-no-digits' })
|
2025-12-24 15:41:06 +07:00
|
|
|
|
/* .refine(
|
|
|
|
|
|
(value) => !/\p{Emoji}/u.test(value),
|
|
|
|
|
|
{ message: 'no-emoji-allowed' }
|
|
|
|
|
|
) */
|
2025-11-28 12:38:14 +07:00
|
|
|
|
.trim(),
|
2025-12-16 11:24:05 +07:00
|
|
|
|
email: z
|
|
|
|
|
|
.string()
|
|
|
|
|
|
.trim()
|
2025-12-19 16:11:58 +07:00
|
|
|
|
.refine(
|
|
|
|
|
|
(value) => value === value.toLowerCase(),
|
|
|
|
|
|
{ message: 'email-no-uppercase' }
|
|
|
|
|
|
)
|
2025-12-16 11:24:05 +07:00
|
|
|
|
.refine(
|
|
|
|
|
|
(value) => emailRegex.test(value),
|
2025-12-19 16:11:58 +07:00
|
|
|
|
{ message: 'email-invalid' }
|
2025-12-16 11:24:05 +07:00
|
|
|
|
),
|
2025-12-08 13:57:26 +07:00
|
|
|
|
phone: z
|
|
|
|
|
|
.string()
|
2025-12-10 16:39:13 +07:00
|
|
|
|
.min(12, { error: 'register-error-phone' }),
|
2025-11-28 12:38:14 +07:00
|
|
|
|
password: z
|
|
|
|
|
|
.string()
|
2025-12-10 16:39:13 +07:00
|
|
|
|
.min(8, { error: 'register-error-password-symbols' })
|
2025-12-16 11:24:05 +07:00
|
|
|
|
.regex(/[a-zA-Zа-яёА-ЯЁ]/, { error: 'register-error-password-one-letter' })
|
2025-12-10 16:39:13 +07:00
|
|
|
|
.regex(/[0-9]/, { error: 'register-error-password-one-digit' })
|
2025-12-24 15:41:06 +07:00
|
|
|
|
/* .refine(
|
|
|
|
|
|
(value) => !/\p{Emoji}/u.test(value),
|
|
|
|
|
|
{ message: 'no-emoji-allowed' }
|
|
|
|
|
|
) */
|
2025-11-28 12:38:14 +07:00
|
|
|
|
.trim(),
|
|
|
|
|
|
confirm_password: z
|
2025-12-08 13:57:26 +07:00
|
|
|
|
.string(),
|
|
|
|
|
|
agree: z
|
2025-11-28 12:38:14 +07:00
|
|
|
|
.string()
|
2025-12-10 16:39:13 +07:00
|
|
|
|
.min(2, { error: 'register-error-agree' })
|
2025-11-28 12:38:14 +07:00
|
|
|
|
})
|
|
|
|
|
|
.refine((data) => data.password === data.confirm_password, {
|
2025-12-10 16:39:13 +07:00
|
|
|
|
message: 'repeat-password',
|
2025-11-28 12:38:14 +07:00
|
|
|
|
path: ['confirm_password'],
|
|
|
|
|
|
});
|
2025-11-27 21:33:53 +07:00
|
|
|
|
|
2025-11-28 15:28:15 +07:00
|
|
|
|
export const loginFormSchema = z
|
|
|
|
|
|
.object({
|
|
|
|
|
|
email: z
|
|
|
|
|
|
.string()
|
2025-12-10 16:39:13 +07:00
|
|
|
|
.min(1, { error: 'login-error-email' })
|
2025-11-28 15:28:15 +07:00
|
|
|
|
.trim(),
|
|
|
|
|
|
password: z
|
|
|
|
|
|
.string()
|
2025-12-10 16:39:13 +07:00
|
|
|
|
.min(1, { error: 'login-error-password' })
|
2025-11-28 15:28:15 +07:00
|
|
|
|
.trim(),
|
2025-12-03 21:02:31 +07:00
|
|
|
|
})
|
|
|
|
|
|
|
2025-12-11 20:38:06 +07:00
|
|
|
|
export const localDevelopmentUrl = 'http://localhost';
|
2025-12-11 18:28:35 +07:00
|
|
|
|
|
2025-12-26 17:56:57 +07:00
|
|
|
|
export const API_BASE_URL = process.env.NODE_ENV === 'development'
|
|
|
|
|
|
? localDevelopmentUrl
|
|
|
|
|
|
: 'http://app:8080';
|
|
|
|
|
|
|
2025-12-11 18:28:35 +07:00
|
|
|
|
export const testUserData = {
|
|
|
|
|
|
fullName: 'test',
|
|
|
|
|
|
email: 'test@mail.com',
|
|
|
|
|
|
subscriptionType: 'base'
|
|
|
|
|
|
}
|