fix: add /cases/new route to prevent dynamic [id] catch
The static "new" segment was missing, so Next.js treated "new" as a UUID parameter for [id]/page.tsx, causing a Postgres "invalid input syntax for type uuid" error. Adding cases/new/page.tsx with a create form resolves the server error. Co-Authored-By: Paperclip <noreply@paperclip.ing>
This commit is contained in:
215
src/app/(dashboard)/cases/new/page.tsx
Normal file
215
src/app/(dashboard)/cases/new/page.tsx
Normal file
@@ -0,0 +1,215 @@
|
||||
'use client';
|
||||
|
||||
import { useState } from 'react';
|
||||
import { useRouter } from 'next/navigation';
|
||||
import Link from 'next/link';
|
||||
|
||||
export default function NewCasePage() {
|
||||
const router = useRouter();
|
||||
const [loading, setLoading] = useState(false);
|
||||
const [error, setError] = useState('');
|
||||
|
||||
async function handleSubmit(e: React.FormEvent<HTMLFormElement>) {
|
||||
e.preventDefault();
|
||||
setError('');
|
||||
setLoading(true);
|
||||
|
||||
const form = new FormData(e.currentTarget);
|
||||
const body = {
|
||||
caseNumber: form.get('caseNumber'),
|
||||
title: form.get('title'),
|
||||
description: form.get('description') || undefined,
|
||||
clientName: form.get('clientName') || undefined,
|
||||
opposingParty: form.get('opposingParty') || undefined,
|
||||
venue: form.get('venue') || undefined,
|
||||
status: form.get('status') || 'active',
|
||||
filingDate: form.get('filingDate') || undefined,
|
||||
hearingDate: form.get('hearingDate') || undefined,
|
||||
};
|
||||
|
||||
try {
|
||||
const res = await fetch('/api/cases', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify(body),
|
||||
});
|
||||
|
||||
if (!res.ok) {
|
||||
const data = await res.json().catch(() => null);
|
||||
throw new Error(data?.error ?? 'Fall konnte nicht angelegt werden.');
|
||||
}
|
||||
|
||||
const data = await res.json();
|
||||
router.push(`/cases/${data.case.id}`);
|
||||
} catch (err) {
|
||||
setError(err instanceof Error ? err.message : 'Ein Fehler ist aufgetreten.');
|
||||
setLoading(false);
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="space-y-6">
|
||||
<div className="flex items-center gap-2 text-sm text-muted">
|
||||
<Link href="/cases" className="hover:text-primary transition-colors">
|
||||
Faelle
|
||||
</Link>
|
||||
<span>/</span>
|
||||
<span>Neuer Fall</span>
|
||||
</div>
|
||||
|
||||
<h1 className="text-xl font-bold text-foreground">Neuen Fall anlegen</h1>
|
||||
|
||||
{error && (
|
||||
<div className="bg-red-50 border border-red-200 text-red-700 rounded-lg px-4 py-3 text-sm">
|
||||
{error}
|
||||
</div>
|
||||
)}
|
||||
|
||||
<form onSubmit={handleSubmit} className="bg-card-bg border border-card-border rounded-xl p-6 space-y-4">
|
||||
<div className="grid grid-cols-1 sm:grid-cols-2 gap-4">
|
||||
<div>
|
||||
<label htmlFor="caseNumber" className="block text-sm font-medium text-foreground mb-1">
|
||||
Aktenzeichen *
|
||||
</label>
|
||||
<input
|
||||
id="caseNumber"
|
||||
name="caseNumber"
|
||||
type="text"
|
||||
required
|
||||
placeholder="z.B. 2026/001"
|
||||
className="w-full rounded-lg border border-card-border px-3 py-2.5 text-sm bg-white focus:outline-none focus:ring-2 focus:ring-primary/30 focus:border-primary"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label htmlFor="title" className="block text-sm font-medium text-foreground mb-1">
|
||||
Titel *
|
||||
</label>
|
||||
<input
|
||||
id="title"
|
||||
name="title"
|
||||
type="text"
|
||||
required
|
||||
placeholder="Kurztitel des Falls"
|
||||
className="w-full rounded-lg border border-card-border px-3 py-2.5 text-sm bg-white focus:outline-none focus:ring-2 focus:ring-primary/30 focus:border-primary"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label htmlFor="description" className="block text-sm font-medium text-foreground mb-1">
|
||||
Beschreibung
|
||||
</label>
|
||||
<textarea
|
||||
id="description"
|
||||
name="description"
|
||||
rows={3}
|
||||
placeholder="Optionale Beschreibung des Falls"
|
||||
className="w-full rounded-lg border border-card-border px-3 py-2.5 text-sm bg-white focus:outline-none focus:ring-2 focus:ring-primary/30 focus:border-primary"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className="grid grid-cols-1 sm:grid-cols-2 gap-4">
|
||||
<div>
|
||||
<label htmlFor="clientName" className="block text-sm font-medium text-foreground mb-1">
|
||||
Mandant
|
||||
</label>
|
||||
<input
|
||||
id="clientName"
|
||||
name="clientName"
|
||||
type="text"
|
||||
placeholder="Name des Mandanten"
|
||||
className="w-full rounded-lg border border-card-border px-3 py-2.5 text-sm bg-white focus:outline-none focus:ring-2 focus:ring-primary/30 focus:border-primary"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label htmlFor="opposingParty" className="block text-sm font-medium text-foreground mb-1">
|
||||
Gegenseite
|
||||
</label>
|
||||
<input
|
||||
id="opposingParty"
|
||||
name="opposingParty"
|
||||
type="text"
|
||||
placeholder="Name der Gegenseite"
|
||||
className="w-full rounded-lg border border-card-border px-3 py-2.5 text-sm bg-white focus:outline-none focus:ring-2 focus:ring-primary/30 focus:border-primary"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="grid grid-cols-1 sm:grid-cols-3 gap-4">
|
||||
<div>
|
||||
<label htmlFor="venue" className="block text-sm font-medium text-foreground mb-1">
|
||||
Buehne / Spielstaette
|
||||
</label>
|
||||
<input
|
||||
id="venue"
|
||||
name="venue"
|
||||
type="text"
|
||||
placeholder="z.B. Staatsoper Berlin"
|
||||
className="w-full rounded-lg border border-card-border px-3 py-2.5 text-sm bg-white focus:outline-none focus:ring-2 focus:ring-primary/30 focus:border-primary"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label htmlFor="status" className="block text-sm font-medium text-foreground mb-1">
|
||||
Status
|
||||
</label>
|
||||
<select
|
||||
id="status"
|
||||
name="status"
|
||||
defaultValue="active"
|
||||
className="w-full rounded-lg border border-card-border px-3 py-2.5 text-sm bg-white focus:outline-none focus:ring-2 focus:ring-primary/30 focus:border-primary"
|
||||
>
|
||||
<option value="active">Aktiv</option>
|
||||
<option value="closed">Abgeschlossen</option>
|
||||
<option value="archived">Archiviert</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="grid grid-cols-1 sm:grid-cols-2 gap-4">
|
||||
<div>
|
||||
<label htmlFor="filingDate" className="block text-sm font-medium text-foreground mb-1">
|
||||
Eingereicht am
|
||||
</label>
|
||||
<input
|
||||
id="filingDate"
|
||||
name="filingDate"
|
||||
type="date"
|
||||
className="w-full rounded-lg border border-card-border px-3 py-2.5 text-sm bg-white focus:outline-none focus:ring-2 focus:ring-primary/30 focus:border-primary"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label htmlFor="hearingDate" className="block text-sm font-medium text-foreground mb-1">
|
||||
Verhandlungstermin
|
||||
</label>
|
||||
<input
|
||||
id="hearingDate"
|
||||
name="hearingDate"
|
||||
type="date"
|
||||
className="w-full rounded-lg border border-card-border px-3 py-2.5 text-sm bg-white focus:outline-none focus:ring-2 focus:ring-primary/30 focus:border-primary"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="flex items-center gap-3 pt-2">
|
||||
<button
|
||||
type="submit"
|
||||
disabled={loading}
|
||||
className="px-4 py-2.5 bg-primary text-white rounded-lg text-sm font-medium hover:bg-primary-light transition-colors disabled:opacity-50 disabled:cursor-not-allowed"
|
||||
>
|
||||
{loading ? 'Wird angelegt...' : 'Fall anlegen'}
|
||||
</button>
|
||||
<Link
|
||||
href="/cases"
|
||||
className="px-4 py-2.5 border border-card-border rounded-lg text-sm font-medium text-muted hover:text-foreground transition-colors"
|
||||
>
|
||||
Abbrechen
|
||||
</Link>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user