This commit is contained in:
phaichayon
2026-06-11 12:46:57 +07:00
parent 1993d88306
commit 7a390cf0df
720 changed files with 100919 additions and 0 deletions

View File

@@ -0,0 +1,27 @@
import * as z from 'zod';
const MAX_FILE_SIZE = 5_000_000;
const ACCEPTED_IMAGE_TYPES = ['image/jpeg', 'image/jpg', 'image/png', 'image/webp'];
export const productSchema = z.object({
image: z
.any()
.optional()
.refine((files) => !files?.length || files?.[0]?.size <= MAX_FILE_SIZE, 'Max file size is 5MB.')
.refine(
(files) => !files?.length || ACCEPTED_IMAGE_TYPES.includes(files?.[0]?.type),
'.jpg, .jpeg, .png and .webp files are accepted.'
),
name: z.string().min(2, 'Product name must be at least 2 characters.'),
category: z.string().min(1, 'Please select a category'),
price: z.number({ message: 'Price is required' }),
description: z.string().min(10, 'Description must be at least 10 characters.')
});
export type ProductFormValues = {
image?: File[];
name: string;
category: string;
price: number | undefined;
description: string;
};