Files
bewell-in-ua/lib/schemas/admin/product.ts
2025-02-05 08:01:14 +02:00

45 lines
1.5 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 {z} from 'zod'
import {i18nLocalesCodes} from '@/i18n-config'
import {metaFormSchema} from '@/lib/schemas/meta'
export const productLocaleSchema = z.object({
lang: z.enum(i18nLocalesCodes),
title: z.coerce.string().trim().min(1).max(384),
shortTitle: z.coerce.string().trim().max(191).optional(),
headingTitle: z.coerce.string().trim().max(191).optional(),
description: z.coerce.string().trim(),
content: z.coerce.string().trim().optional(),
instruction: z.coerce.string().trim().optional()
})
export const createProductFormSchema = z.object({
image: z.coerce.string().trim().max(512).optional(),
published: z.coerce.boolean().default(false).optional(), // ProductToStore
price: z.coerce
.string()
.min(2)
.regex(/^\d{1,7}(\.\d{1,2})?$/, {
message: 'Максимум 7 цифр до крапки та 2 після неї'
}), // ProductToStore
pricePromotional: z.coerce
.string()
.regex(/^\d{1,7}(\.\d{1,2})?$/, {
message: 'Максимум 7 цифр до крапки та 2 після неї'
})
.optional(), // ProductToStore
locales: z.array(productLocaleSchema),
meta: z.array(metaFormSchema)
})
//
// files: z
// .array(
// z.object({
// file: z.any(),
// alt: z.string().min(1, {message: 'Значення тегу Alt необхідне'}),
// title: z.string().min(1, {message: 'Значення тегу title необхідне'})
// })
// )
// .nonempty({message: 'Необхідно обрати хоча б один файл'})