Additional work on user profile edit

This commit is contained in:
Aaron William Po
2023-12-02 13:58:17 -05:00
parent df55217bd0
commit d57623e705
10 changed files with 361 additions and 159 deletions

View File

@@ -0,0 +1,28 @@
import { z } from 'zod';
const UpdateProfileSchema = z.object({
bio: z.string().min(1, 'Bio cannot be empty'),
userAvatar: z.optional(
z
.instanceof(typeof FileList !== 'undefined' ? FileList : Object)
.refine((fileList) => fileList instanceof FileList, {
message: 'You must submit this form in a web browser.',
})
.refine(
(fileList) =>
[...(fileList as FileList)]
.map((file) => file.type)
.every((fileType) => fileType.startsWith('image/')),
{ message: 'You must upload only images.' },
)
.refine(
(fileList) =>
[...(fileList as FileList)]
.map((file) => file.size)
.every((fileSize) => fileSize < 15 * 1024 * 1024),
{ message: 'You must upload images smaller than 15MB.' },
),
),
});
export default UpdateProfileSchema;