refactor: url no need to end with .md

This commit is contained in:
Sosokker 2024-11-11 03:04:48 +07:00
parent 26fdf65779
commit 71c31e596e

View File

@ -4,12 +4,9 @@ const MAX_FILE_SIZE = 500000;
const ACCEPTED_IMAGE_TYPES = ["image/jpeg", "image/jpg", "image/png"]; const ACCEPTED_IMAGE_TYPES = ["image/jpeg", "image/jpg", "image/png"];
const imageSchema = z const imageSchema = z
.custom<File>( .custom<File>((val) => val && typeof val === "object" && "size" in val && "type" in val, {
(val) => val && typeof val === "object" && "size" in val && "type" in val, message: "Input must be a file.",
{ })
message: "Input must be a file.",
}
)
.refine((file) => file.size < MAX_FILE_SIZE, { .refine((file) => file.size < MAX_FILE_SIZE, {
message: "File can't be bigger than 5MB.", message: "File can't be bigger than 5MB.",
}) })
@ -32,12 +29,7 @@ const projectFormSchema = z.object({
message: "Short description must be at least 10 characters.", message: "Short description must be at least 10 characters.",
}), }),
projectPitchDeck: z.union([ projectPitchDeck: z.union([
z z.string().url("Pitch deck must be a valid URL."),
.string()
.url("Pitch deck must be a valid URL.")
.refine((url) => url.endsWith(".md"), {
message: "Pitch deck URL must link to a markdown file (.md).",
}),
z z
.custom<File>((val) => val instanceof File, { .custom<File>((val) => val instanceof File, {
message: "Input must be a file.", message: "Input must be a file.",
@ -53,16 +45,12 @@ const projectFormSchema = z.object({
projectPhotos: z.custom( projectPhotos: z.custom(
(value) => { (value) => {
if (value instanceof FileList || Array.isArray(value)) { if (value instanceof FileList || Array.isArray(value)) {
return ( return value.length > 0 && Array.from(value).every((item) => item instanceof File);
value.length > 0 &&
Array.from(value).every((item) => item instanceof File)
);
} }
return false; return false;
}, },
{ {
message: message: "Must be a FileList or an array of File objects with at least one file.",
"Must be a FileList or an array of File objects with at least one file.",
} }
), ),
@ -90,10 +78,7 @@ const projectFormSchema = z.object({
.refine((date) => date > new Date(), { .refine((date) => date > new Date(), {
message: "Deadline must be in the future.", message: "Deadline must be in the future.",
}), }),
tag: z tag: z.array(z.number()).min(1, "Please provide at least one tag.").max(5, "You can provide up to 5 tags."),
.array(z.number())
.min(1, "Please provide at least one tag.")
.max(5, "You can provide up to 5 tags."),
}); });
const businessFormSchema = z.object({ const businessFormSchema = z.object({