From 6677679eb948cb381dc6d13837d8a656083382af Mon Sep 17 00:00:00 2001 From: Jonny Date: Mon, 17 Aug 2026 16:08:19 +0200 Subject: [PATCH] fix: use onSubmit instead of form action to prevent field reset on error, rename ActionResult type Finding 1: React 19's native
resets uncontrolled fields once fn resolves without throwing, regardless of an app-level {success:false} result. Since handleSubmit never throws, every failed submit (e.g. duplicate Kennzeichen) silently wiped user edits. Switched all four Standorte/Fahrzeuge inline-edit and create forms to a plain onSubmit handler that calls event.preventDefault() and builds FormData from the submitted element manually, sidestepping React's action-reset machinery. Finding 2: web/app/standorte/actions.ts and web/app/fahrzeuge/actions.ts each declared their own MutationResult type shadowing the differently shaped MutationResult exported from lib/orte-fahrzeuge/mutations.ts. Renamed the local type to ActionResult in both files to remove the name collision. --- web/app/fahrzeuge/actions.ts | 6 +++--- web/app/standorte/actions.ts | 6 +++--- web/components/fahrzeuge/FahrzeugZeile.tsx | 6 ++++-- web/components/fahrzeuge/NeuerFahrzeug.tsx | 6 ++++-- web/components/standorte/NeuerStandort.tsx | 6 ++++-- web/components/standorte/StandortZeile.tsx | 6 ++++-- 6 files changed, 22 insertions(+), 14 deletions(-) diff --git a/web/app/fahrzeuge/actions.ts b/web/app/fahrzeuge/actions.ts index eb820f3..68782d9 100644 --- a/web/app/fahrzeuge/actions.ts +++ b/web/app/fahrzeuge/actions.ts @@ -5,9 +5,9 @@ import { kannStammdatenPflegen } from "@/lib/auth/roles"; import { validateFahrzeug } from "@/lib/orte-fahrzeuge/validate-fahrzeug"; import { insertFahrzeug, updateFahrzeugZeile } from "@/lib/orte-fahrzeuge/mutations"; -export type MutationResult = { success: true } | { success: false; error: string }; +export type ActionResult = { success: true } | { success: false; error: string }; -export async function createFahrzeug(formData: FormData): Promise { +export async function createFahrzeug(formData: FormData): Promise { const profileResult = await loadProfile(); if (profileResult.status !== "ok" || !kannStammdatenPflegen(profileResult.profile.role)) { return { success: false, error: "Nur Disponent/Admin duerfen Stammdaten pflegen." }; @@ -34,7 +34,7 @@ export async function createFahrzeug(formData: FormData): Promise { +export async function updateFahrzeug(fahrzeugId: string, formData: FormData): Promise { const profileResult = await loadProfile(); if (profileResult.status !== "ok" || !kannStammdatenPflegen(profileResult.profile.role)) { return { success: false, error: "Nur Disponent/Admin duerfen Stammdaten pflegen." }; diff --git a/web/app/standorte/actions.ts b/web/app/standorte/actions.ts index 8619297..0c10ec5 100644 --- a/web/app/standorte/actions.ts +++ b/web/app/standorte/actions.ts @@ -6,9 +6,9 @@ import { kannStammdatenPflegen } from "@/lib/auth/roles"; import { validateOrt } from "@/lib/orte-fahrzeuge/validate-ort"; import { insertOrt, updateOrtZeile } from "@/lib/orte-fahrzeuge/mutations"; -export type MutationResult = { success: true } | { success: false; error: string }; +export type ActionResult = { success: true } | { success: false; error: string }; -export async function createOrt(formData: FormData): Promise { +export async function createOrt(formData: FormData): Promise { const profileResult = await loadProfile(); if (profileResult.status !== "ok" || !kannStammdatenPflegen(profileResult.profile.role)) { return { success: false, error: "Nur Disponent/Admin duerfen Stammdaten pflegen." }; @@ -42,7 +42,7 @@ export async function createOrt(formData: FormData): Promise { return { success: true }; } -export async function updateOrt(ortId: string, formData: FormData): Promise { +export async function updateOrt(ortId: string, formData: FormData): Promise { const profileResult = await loadProfile(); if (profileResult.status !== "ok" || !kannStammdatenPflegen(profileResult.profile.role)) { return { success: false, error: "Nur Disponent/Admin duerfen Stammdaten pflegen." }; diff --git a/web/components/fahrzeuge/FahrzeugZeile.tsx b/web/components/fahrzeuge/FahrzeugZeile.tsx index 599575f..5bb24cc 100644 --- a/web/components/fahrzeuge/FahrzeugZeile.tsx +++ b/web/components/fahrzeuge/FahrzeugZeile.tsx @@ -15,7 +15,9 @@ export function FahrzeugZeile({ fahrzeug }: { fahrzeug: Fahrzeug }) { const [fehler, setFehler] = useState(null); const [isPending, startTransition] = useTransition(); - function handleSubmit(formData: FormData) { + function handleSubmit(event: React.FormEvent) { + event.preventDefault(); + const formData = new FormData(event.currentTarget); startTransition(async () => { const ergebnis = await updateFahrzeug(fahrzeug.id, formData); if (!ergebnis.success) { @@ -62,7 +64,7 @@ export function FahrzeugZeile({ fahrzeug }: { fahrzeug: Fahrzeug }) { return ( {fehler && ( diff --git a/web/components/fahrzeuge/NeuerFahrzeug.tsx b/web/components/fahrzeuge/NeuerFahrzeug.tsx index 229b9d1..1203d17 100644 --- a/web/components/fahrzeuge/NeuerFahrzeug.tsx +++ b/web/components/fahrzeuge/NeuerFahrzeug.tsx @@ -14,7 +14,9 @@ export function NeuerFahrzeug() { const [fehler, setFehler] = useState(null); const [isPending, startTransition] = useTransition(); - function handleSubmit(formData: FormData) { + function handleSubmit(event: React.FormEvent) { + event.preventDefault(); + const formData = new FormData(event.currentTarget); startTransition(async () => { const ergebnis = await createFahrzeug(formData); if (!ergebnis.success) { @@ -44,7 +46,7 @@ export function NeuerFahrzeug() { return ( {fehler && ( diff --git a/web/components/standorte/NeuerStandort.tsx b/web/components/standorte/NeuerStandort.tsx index 718f309..c042cd6 100644 --- a/web/components/standorte/NeuerStandort.tsx +++ b/web/components/standorte/NeuerStandort.tsx @@ -14,7 +14,9 @@ export function NeuerStandort() { const [fehler, setFehler] = useState(null); const [isPending, startTransition] = useTransition(); - function handleSubmit(formData: FormData) { + function handleSubmit(event: React.FormEvent) { + event.preventDefault(); + const formData = new FormData(event.currentTarget); startTransition(async () => { const ergebnis = await createOrt(formData); if (!ergebnis.success) { @@ -44,7 +46,7 @@ export function NeuerStandort() { return ( {fehler && ( diff --git a/web/components/standorte/StandortZeile.tsx b/web/components/standorte/StandortZeile.tsx index b5b5010..ada9372 100644 --- a/web/components/standorte/StandortZeile.tsx +++ b/web/components/standorte/StandortZeile.tsx @@ -15,7 +15,9 @@ export function StandortZeile({ ort }: { ort: Ort }) { const [fehler, setFehler] = useState(null); const [isPending, startTransition] = useTransition(); - function handleSubmit(formData: FormData) { + function handleSubmit(event: React.FormEvent) { + event.preventDefault(); + const formData = new FormData(event.currentTarget); startTransition(async () => { const ergebnis = await updateOrt(ort.id, formData); if (!ergebnis.success) { @@ -58,7 +60,7 @@ export function StandortZeile({ ort }: { ort: Ort }) { return ( {fehler && (