init
This commit is contained in:
27
src/features/products/schemas/product.ts
Normal file
27
src/features/products/schemas/product.ts
Normal 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;
|
||||
};
|
||||
Reference in New Issue
Block a user