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
3 changes: 2 additions & 1 deletion fdm-app/app/components/blocks/auth/auth-formschema.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ import z from "zod"
export const FormSchema = z.object({
code: z
.string({
required_error: "Vul de verificatiecode in",
error: "Vul de verificatiecode in",
})
.trim()
.min(8, {
message: "De code moet uit 8 tekens bestaan",
})
Expand Down
2 changes: 1 addition & 1 deletion fdm-app/app/components/blocks/cultivation/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export type CultivationDetailsFormSchemaType = z.infer<
>

export const CultivationAddFormSchema = z.object({
b_lu_catalogue: z.string().min(1, "Gewas is verplicht."),
b_lu_catalogue: z.string().trim().min(1, "Gewas is verplicht."),
b_lu_start: z.preprocess(
(val) => (typeof val === "string" ? new Date(val) : val),
z.date({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const fields = {
error: "Hoeveelheid moet positief zijn",
}),
),
p_app_method: z.string().min(1, "Toepassingsmethode is verplicht"),
p_app_method: z.string().trim().min(1, "Toepassingsmethode is verplicht"),
p_app_date: z.preprocess(
(val) => (typeof val === "string" ? new Date(val) : val),
z.date({
Expand Down
1 change: 1 addition & 0 deletions fdm-app/app/components/blocks/fertilizer/formschema.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export const FormSchema = z
? "Naam is verplicht"
: "Ongeldige waarde",
})
.trim()
.min(1, {
error: "Geef een naam op voor deze meststof",
}),
Expand Down
1 change: 1 addition & 0 deletions fdm-app/app/components/blocks/field/schema.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const FormSchema = z.object({
? "Naam van perceel is verplicht"
: undefined,
})
.trim()
.min(3, {
error: "Naam van perceel moet minimaal 3 karakters bevatten",
}),
Expand Down
7 changes: 4 additions & 3 deletions fdm-app/app/components/blocks/fields-new/schema.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,19 @@ import z from "zod"
export const FormSchema = z.object({
b_name: z
.string({
required_error: "Naam van perceel is verplicht",
error: "Naam van perceel is verplicht",
})
.trim()
.min(3, {
message: "Naam van perceel moet minimaal 3 karakters bevatten",
}),
b_area: z.coerce
.number({
required_error: "Oppervlakte van perceel is verplicht",
error: "Oppervlakte van perceel is verplicht",
})
.optional(),
Comment on lines 12 to 16
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

🧩 Analysis chain

🏁 Script executed:

find . -type f -name "schema.tsx" | head -20

Repository: nmi-agro/fdm

Length of output: 209


🏁 Script executed:

# Get the file size first to understand what we're dealing with
wc -l fdm-app/app/components/blocks/fields-new/schema.tsx

Repository: nmi-agro/fdm

Length of output: 110


🏁 Script executed:

# Read the target file around lines 12-16
cat -n fdm-app/app/components/blocks/fields-new/schema.tsx | head -30

Repository: nmi-agro/fdm

Length of output: 734


🏁 Script executed:

# Search for similar preprocessing patterns in schema files to confirm the pattern usage
rg "z.preprocess.*z.coerce.number" --type typescript

Repository: nmi-agro/fdm

Length of output: 90


🏁 Script executed:

# Search for z.preprocess patterns more broadly
rg "z.preprocess" fdm-app/app/components/blocks/

Repository: nmi-agro/fdm

Length of output: 8696


🏁 Script executed:

# Check the field/schema.tsx to see how optional numeric fields are handled there
cat -n fdm-app/app/components/blocks/field/schema.tsx

Repository: nmi-agro/fdm

Length of output: 1316


🏁 Script executed:

# Check harvest/schema.tsx too
cat -n fdm-app/app/components/blocks/harvest/schema.tsx | head -50

Repository: nmi-agro/fdm

Length of output: 2111


Add empty-string normalization to b_area field to match the established pattern for optional numeric fields.

The b_area field should preprocess empty input to undefined before numeric coercion, consistent with how other optional numeric fields are handled throughout the codebase (e.g., b_lu_yield in harvest schema). Without this, empty strings may be coerced improperly.

Proposed fix
-    b_area: z.coerce
-        .number({
-            error: "Oppervlakte van perceel is verplicht",
-        })
-        .optional(),
+    b_area: z.preprocess(
+        (val) => (val === "" ? undefined : val),
+        z.coerce.number({
+            error: "Oppervlakte van perceel is verplicht",
+        }).optional(),
+    ),
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
b_area: z.coerce
.number({
required_error: "Oppervlakte van perceel is verplicht",
error: "Oppervlakte van perceel is verplicht",
})
.optional(),
b_area: z.preprocess(
(val) => (val === "" ? undefined : val),
z.coerce.number({
error: "Oppervlakte van perceel is verplicht",
}).optional(),
),
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@fdm-app/app/components/blocks/fields-new/schema.tsx` around lines 12 - 16,
Normalize empty-string inputs for the b_area field by preprocessing them to
undefined before coercion: update the b_area validator (the z.preprocess /
b_area schema that currently uses z.coerce.number(...).optional()) to first
convert "" to undefined and then apply z.coerce.number({ error: "Oppervlakte van
perceel is verplicht" }).optional(), preserving the existing error message and
optional behavior.

b_lu_catalogue: z.string({
required_error: "Hoofdgewas is verplicht",
error: "Hoofdgewas is verplicht",
}),
Comment on lines 17 to 19
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

b_lu_catalogue is marked required but still allows blank/whitespace payloads.

Line 17–19 currently only enforces string type. Add trim + non-empty validation to fully align with this PR’s blank-string objective.

Proposed fix
-    b_lu_catalogue: z.string({
-        error: "Hoofdgewas is verplicht",
-    }),
+    b_lu_catalogue: z
+        .string({
+            error: "Hoofdgewas is verplicht",
+        })
+        .trim()
+        .min(1, "Hoofdgewas is verplicht"),
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
b_lu_catalogue: z.string({
required_error: "Hoofdgewas is verplicht",
error: "Hoofdgewas is verplicht",
}),
b_lu_catalogue: z
.string({
error: "Hoofdgewas is verplicht",
})
.trim()
.min(1, "Hoofdgewas is verplicht"),
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@fdm-app/app/components/blocks/fields-new/schema.tsx` around lines 17 - 19,
b_lu_catalogue currently only enforces type but allows blank/whitespace strings;
change its Zod validator to trim input and require non-empty content (e.g.,
replace z.string({ error: "Hoofdgewas is verplicht" }) with a trimmed +
non-empty check such as using .trim().min(1, { message: "Hoofdgewas is
verplicht" }) or .trim().nonempty({ message: "Hoofdgewas is verplicht" })) so
whitespace-only payloads are rejected; update the validator for the
b_lu_catalogue field in schema.tsx accordingly.

b_bufferstrip: z.boolean().optional(),
})
2 changes: 2 additions & 0 deletions fdm-app/app/components/blocks/organization/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export const FormSchema = z.object({
? "Naam van de organisatie is verplicht"
: undefined,
})
.trim()
.min(3, {
error: "Naam van de organisatie moet minimaal 3 karakters bevatten",
}),
Expand All @@ -34,6 +35,7 @@ export const FormSchema = z.object({
? "ID van de organisatie is verplicht"
: undefined,
})
.trim()
.refine(isValidSlug, {
error: "ID moet minimaal 3 karakters bevatten, enkel kleine letters, cijfers of '-'",
}),
Expand Down
2 changes: 1 addition & 1 deletion fdm-app/app/lib/schemas/access.schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export const AccessFormSchema = z.object({
email: z.email().optional(),
username: z.string().optional(),
role: z.enum(["owner", "advisor", "researcher"]).optional(),
invitation_id: z.string().min(1).optional(),
invitation_id: z.string().trim().min(1).optional(),
intent: z.enum([
"invite_user",
"update_role",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ export async function action({ request, params }: ActionFunctionArgs) {
// Form Schema
const FormSchema = z
.object({
b_name: z.string().min(2, {
b_name: z.string().trim().min(2, {
error: "Naam van perceel moet minimaal 2 karakters bevatten",
}),
b_acquiring_method: z.string({
Expand Down
3 changes: 2 additions & 1 deletion fdm-app/app/routes/farm.$b_id_farm.settings.properties.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -326,13 +326,14 @@ export async function action({ request, params }: ActionFunctionArgs) {

// Form Schema
const FormSchema = z.object({
b_name_farm: z.string().min(3, {
b_name_farm: z.string().trim().min(3, {
error: "Naam van bedrijf moet minimaal 3 karakters bevatten",
}),
b_businessid_farm: z.string().optional(),
b_address_farm: z.string().optional(),
b_postalcode_farm: z
.string()
.trim()
.optional()
.refine((value) => !value || isPostalCode(value, "NL"), {
error: "Ongeldige postcode",
Expand Down
4 changes: 3 additions & 1 deletion fdm-app/app/routes/farm.create._index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ const FormSchema = z
? "Naam van bedrijf is verplicht"
: undefined,
})
.trim()
.min(3, {
error: "Naam van bedrijf moet minimaal 3 karakters bevatten",
}),
Expand All @@ -87,9 +88,10 @@ const FormSchema = z
}),
b_businessid_farm: z
.string()
.trim()
.regex(/^\d{8}$/, "KvK-nummer moet uit 8 cijfers bestaan")
.optional()
.or(z.literal("")),
.or(z.string().trim().length(0)),
has_derogation: z.coerce.boolean().default(false),
derogation_start_year: z.preprocess(
(val) => (val === "" ? undefined : val),
Expand Down
2 changes: 2 additions & 0 deletions fdm-app/app/routes/welcome.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ const FormSchema = z.object({
error: (issue) =>
issue.input === undefined ? "Vul je voornaam in" : undefined,
})
.trim()
.min(1, {
error: "Vul je voornaam in",
}),
Expand All @@ -60,6 +61,7 @@ const FormSchema = z.object({
error: (issue) =>
issue.input === undefined ? "Vul je achternaam in" : undefined,
})
.trim()
.min(1, {
error: "Vul je achternaam in",
}),
Expand Down