feat(persons): add birthYear, deathYear, notes fields to /persons/new form
Server action passes all 6 fields to POST /api/persons. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -15,14 +15,27 @@ export const actions = {
|
|||||||
const firstName = formData.get('firstName')?.toString().trim();
|
const firstName = formData.get('firstName')?.toString().trim();
|
||||||
const lastName = formData.get('lastName')?.toString().trim();
|
const lastName = formData.get('lastName')?.toString().trim();
|
||||||
const alias = formData.get('alias')?.toString().trim() || undefined;
|
const alias = formData.get('alias')?.toString().trim() || undefined;
|
||||||
|
const birthYearStr = formData.get('birthYear')?.toString().trim();
|
||||||
|
const deathYearStr = formData.get('deathYear')?.toString().trim();
|
||||||
|
const notes = formData.get('notes')?.toString().trim() || undefined;
|
||||||
|
|
||||||
if (!firstName || !lastName) {
|
if (!firstName || !lastName) {
|
||||||
return fail(400, { error: 'Vor- und Nachname sind Pflichtfelder.' });
|
return fail(400, { error: 'Vor- und Nachname sind Pflichtfelder.' });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const birthYear = birthYearStr ? parseInt(birthYearStr, 10) : undefined;
|
||||||
|
const deathYear = deathYearStr ? parseInt(deathYearStr, 10) : undefined;
|
||||||
|
|
||||||
const api = createApiClient(fetch);
|
const api = createApiClient(fetch);
|
||||||
const result = await api.POST('/api/persons', {
|
const result = await api.POST('/api/persons', {
|
||||||
body: { firstName, lastName, ...(alias ? { alias } : {}) }
|
body: {
|
||||||
|
firstName,
|
||||||
|
lastName,
|
||||||
|
...(alias ? { alias } : {}),
|
||||||
|
...(birthYear ? { birthYear } : {}),
|
||||||
|
...(deathYear ? { deathYear } : {}),
|
||||||
|
...(notes ? { notes } : {})
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!result.response.ok) {
|
if (!result.response.ok) {
|
||||||
|
|||||||
@@ -77,6 +77,49 @@ let { form } = $props();
|
|||||||
class="block w-full rounded border border-line p-2 text-sm shadow-sm focus:border-ink focus:ring-ink"
|
class="block w-full rounded border border-line p-2 text-sm shadow-sm focus:border-ink focus:ring-ink"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<label for="birthYear" class="mb-1 block text-sm font-medium text-ink-2"
|
||||||
|
>{m.person_label_birth_year()}</label
|
||||||
|
>
|
||||||
|
<input
|
||||||
|
id="birthYear"
|
||||||
|
name="birthYear"
|
||||||
|
type="number"
|
||||||
|
min="1"
|
||||||
|
max="2100"
|
||||||
|
placeholder={m.person_placeholder_year()}
|
||||||
|
class="block w-full rounded border border-line p-2 text-sm shadow-sm focus:border-ink focus:ring-ink"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<label for="deathYear" class="mb-1 block text-sm font-medium text-ink-2"
|
||||||
|
>{m.person_label_death_year()}</label
|
||||||
|
>
|
||||||
|
<input
|
||||||
|
id="deathYear"
|
||||||
|
name="deathYear"
|
||||||
|
type="number"
|
||||||
|
min="1"
|
||||||
|
max="2100"
|
||||||
|
placeholder={m.person_placeholder_year()}
|
||||||
|
class="block w-full rounded border border-line p-2 text-sm shadow-sm focus:border-ink focus:ring-ink"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="md:col-span-2">
|
||||||
|
<label for="notes" class="mb-1 block text-sm font-medium text-ink-2"
|
||||||
|
>{m.person_label_notes()}</label
|
||||||
|
>
|
||||||
|
<textarea
|
||||||
|
id="notes"
|
||||||
|
name="notes"
|
||||||
|
rows="4"
|
||||||
|
placeholder={m.person_placeholder_notes()}
|
||||||
|
class="block w-full resize-y rounded border border-line p-2 text-sm shadow-sm focus:border-ink focus:ring-ink"
|
||||||
|
></textarea>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user