Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/many-sails-hang.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@svenvw/fdm-app": patch
---

Migrate to zod v4
28 changes: 20 additions & 8 deletions fdm-app/app/components/blocks/cultivation/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,23 @@ import { z } from "zod"

export const CultivationDetailsFormSchema = z
.object({
b_lu_start: z.coerce.date({
required_error: "Zaaidatum is verplicht.",
}),
b_lu_start: z.preprocess(
(val) => (typeof val === "string" ? new Date(val) : val),
z.date({
error: (issue) =>
issue.input === undefined
? "Zaaidatum is verplicht."
: undefined,
}),
),
b_lu_end: z
.preprocess((value) => {
if (typeof value === "string") {
if (value.toLowerCase() === "null") return null
}
return value
}, z.coerce.date().optional().nullable())
.default(null),
.prefault(null),
m_cropresidue: z.preprocess((value) => {
if (typeof value === "string") {
if (value.toLowerCase() === "false") return false
Expand All @@ -36,8 +42,8 @@ export const CultivationDetailsFormSchema = z
return true
},
{
message: "Einddatum moet na de zaaidatum liggen.",
path: ["b_lu_end"],
error: "Einddatum moet na de zaaidatum liggen."
},
)

Expand All @@ -47,9 +53,15 @@ export type CultivationDetailsFormSchemaType = z.infer<

export const CultivationAddFormSchema = z.object({
b_lu_catalogue: z.string().min(1, "Gewas is verplicht."),
b_lu_start: z.coerce.date({
required_error: "Zaaidatum is verplicht.",
}),
b_lu_start: z.preprocess(
(val) => (typeof val === "string" ? new Date(val) : val),
z.date({
error: (issue) =>
issue.input === undefined
? "Zaaidatum is verplicht."
: undefined,
}),
),
b_lu_end: z.preprocess((value) => {
if (typeof value === "string") {
if (value.toLowerCase() === "null") return null
Expand Down
Original file line number Diff line number Diff line change
@@ -1,34 +1,43 @@
import { z } from "zod"

export const FormSchema = z.object({
p_app_amount: z.coerce
.number({
required_error: "Hoeveelheid is verplicht",
invalid_type_error: "Hoeveelheid moet een getal zijn",
})
.positive({
message: "Hoeveelheid moet positief zijn",
})
.finite({
message: "Hoeveelheid moet een geheel getal zijn",
p_app_amount: z.preprocess(
(val) => (typeof val === "string" && val !== "" ? Number(val) : val),
z.number({
error: (issue) =>
issue.input === undefined
? "Hoeveelheid is verplicht"
: "Hoeveelheid moet een getal zijn",
}).positive({
error: "Hoeveelheid moet positief zijn",
}),
),
p_app_method: z.string().min(1, "Toepassingsmethode is verplicht"),
p_app_date: z.coerce.date({
required_error: "Datum is verplicht",
invalid_type_error: "Datum is ongeldig",
}),
p_app_date: z.preprocess(
(val) => (typeof val === "string" ? new Date(val) : val),
z.date({
error: (issue) =>
issue.input === undefined
? "Datum is verplicht"
: "Datum is ongeldig",
}),
),
p_id: z.string({
// TODO: Validate against the options that are available
required_error: "Keuze van meststof is verplicht",
invalid_type_error: "Meststof is ongeldig",
error: (issue) =>
issue.input === undefined
? "Keuze van meststof is verplicht"
: "Meststof is ongeldig",
}),
})

export const FormSchemaModify = FormSchema.extend({
p_app_id: z.string({
// TODO: Validate against the options that are available
required_error: "Bemesting id is verplicht",
invalid_type_error: "Bemesting id is ongeldig",
error: (issue) =>
issue.input === undefined
? "Bemesting id is verplicht"
: "Bemesting id is ongeldig",
}),
})

Expand Down
Loading