this is my implementation with RHF + Zod for both Client + Server side validation with server actions :
"use client";
....
const formSchema = z.object({
.....
});
const [loading, setLoading] = useState(false);
this is my implementation with RHF + Zod for both Client + Server side validation with server actions :
"use client";
....
const formSchema = z.object({
.....
});
const [loading, setLoading] = useState(false);
const MAX_FILE_SIZE = 500000; | |
const ACCEPTED_IMAGE_TYPES = ["image/jpeg", "image/jpg", "image/png", "image/webp"]; | |
const RegistrationSchema = z.object({ | |
profileImage: z | |
.any() | |
.refine((files) => files?.length == 1, "Image is required.") | |
.refine((files) => files?.[0]?.size <= MAX_FILE_SIZE, `Max file size is 5MB.`) | |
.refine( | |
(files) => ACCEPTED_IMAGE_TYPES.includes(files?.[0]?.type), |