Files
bewell-in-ua/lib/schemas/admin/order.ts
2025-03-11 02:54:09 +02:00

39 lines
1.2 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 {DeliveryOption, Lang, Order} from '@prisma/client'
import {z} from 'zod'
interface Map {
[key: string]: string | undefined
}
export const DeliveryOptionTypeDescription: Map = {
NP: 'До відділення «Нової Пошти»',
PICKUP: 'Самовивіз (для Києва)',
COURIER: "Кур'єр (для Києва)"
}
export const createOrderFormSchema = z.object({
user_id: z.string().optional(),
is_quick: z.boolean(),
lang: z.enum(Object.keys(Lang) as [string, ...string[]]),
first_name: z.coerce.string().trim().min(1).max(255),
//patronymic: z.coerce.string().trim().min(1).max(255),
surname: z.coerce.string().trim().min(1).max(255),
delivery_option: z.enum(
Object.keys(DeliveryOption) as [string, ...string[]],
{
message: "Обов'язкове до вибору"
}
),
phone: z.coerce.string().trim().min(1).max(24),
email: z.coerce
.string()
.trim()
.regex(/^[A-Za-z0-9\._%+\-]+@[A-Za-z0-9\.\-]+\.[A-Za-z]{2,}$/, {
message: 'Ведуть коректну e-mail адресу'
})
.max(320),
address: z.coerce.string().trim(),
notes: z.coerce.string().trim().max(1024).optional(),
details: z.coerce.string().trim()
})