diff --git a/web/src/i18n/en.json b/web/src/i18n/en.json index 054bf06..8982029 100644 --- a/web/src/i18n/en.json +++ b/web/src/i18n/en.json @@ -5,5 +5,5 @@ "objects": { "title": "Objects", "empty": "No objects yet", "loadError": "Could not load objects", "selectPrompt": "Select an object to view its details", "notFound": "Object not found", "prev": "Previous", "next": "Next", "of": "of" }, "fieldsLabels": { "objectNumber": "Object number", "objectName": "Name", "count": "Number of objects", "briefDescription": "Brief description", "currentLocation": "Current location", "currentOwner": "Current owner", "recorder": "Recorder", "recordingDate": "Recording date", "visibility": "Visibility", "flexible": "Catalogue fields" }, "visibility": { "draft": "Draft", "internal": "Internal", "public": "Public" }, - "form": { "selectPlaceholder": "— select —" } + "form": { "selectPlaceholder": "— select —", "create": "Create object", "save": "Save", "cancel": "Cancel", "visibility": "Visibility", "draft": "Draft", "internal": "Internal", "required": "This field is required", "rejected": "The server rejected the changes — check required and referenced fields", "flexibleHeading": "Catalogue fields" } } diff --git a/web/src/i18n/sv.json b/web/src/i18n/sv.json index 4432fd4..05a1d5d 100644 --- a/web/src/i18n/sv.json +++ b/web/src/i18n/sv.json @@ -5,5 +5,5 @@ "objects": { "title": "Föremål", "empty": "Inga föremål ännu", "loadError": "Kunde inte ladda föremål", "selectPrompt": "Välj ett föremål för att se detaljer", "notFound": "Föremålet hittades inte", "prev": "Föregående", "next": "Nästa", "of": "av" }, "fieldsLabels": { "objectNumber": "Föremålsnummer", "objectName": "Namn", "count": "Antal föremål", "briefDescription": "Kort beskrivning", "currentLocation": "Nuvarande plats", "currentOwner": "Nuvarande ägare", "recorder": "Registrerad av", "recordingDate": "Registreringsdatum", "visibility": "Synlighet", "flexible": "Katalogfält" }, "visibility": { "draft": "Utkast", "internal": "Intern", "public": "Publik" }, - "form": { "selectPlaceholder": "— välj —" } + "form": { "selectPlaceholder": "— välj —", "create": "Skapa föremål", "save": "Spara", "cancel": "Avbryt", "visibility": "Synlighet", "draft": "Utkast", "internal": "Intern", "required": "Fältet är obligatoriskt", "rejected": "Servern avvisade ändringarna — kontrollera obligatoriska och refererade fält", "flexibleHeading": "Katalogfält" } } diff --git a/web/src/objects/field-input.tsx b/web/src/objects/field-input.tsx index 78fae4a..859f919 100644 --- a/web/src/objects/field-input.tsx +++ b/web/src/objects/field-input.tsx @@ -1,4 +1,4 @@ -import { Controller, type UseFormReturn } from "react-hook-form"; +import { Controller, type Path, type UseFormReturn } from "react-hook-form"; import { useTranslation } from "react-i18next"; import type { components } from "../api/schema"; @@ -10,7 +10,13 @@ import { Label } from "@/components/ui/label"; type FieldDefinitionView = components["schemas"]["FieldDefinitionView"]; type LabelView = components["schemas"]["LabelView"]; -type FieldForm = UseFormReturn<{ fields: Record }>; +type FieldForm }> = UseFormReturn; + +function fieldPath }>( + key: string, +): Path { + return `fields.${key}` as Path; +} function labelIn(labels: LabelView[], lang: string): string { return ( @@ -56,17 +62,17 @@ function OptionsSelect({ ); } -export function FieldInput({ +export function FieldInput }>({ definition, form, }: { definition: FieldDefinitionView; - form: FieldForm; + form: FieldForm; }) { const { t, i18n } = useTranslation(); const lang = i18n.language.startsWith("sv") ? "sv" : "en"; const label = labelIn(definition.labels, lang); - const name = `fields.${definition.key}` as `fields.${string}`; + const name = fieldPath(definition.key); const placeholder = t("form.selectPlaceholder"); switch (definition.data_type) { @@ -133,7 +139,7 @@ export function FieldInput({ (`${definition.key}.en`), { required: definition.required })} />