feat(web): code-aware field errors + min count validation (#46)

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-06-07 23:20:30 +02:00
parent 3900bc362c
commit 537b847acb
6 changed files with 57 additions and 15 deletions
+13 -1
View File
@@ -30,7 +30,12 @@ function ObjectEditFormLoaded({ object, id }: { object: AdminObjectView; id: str
const update = useUpdateObject();
const setFields = useSetFields();
const locationState = location.state as { fieldsError?: boolean; fieldErrorKey?: string } | null;
const locationState = location.state as {
created?: boolean;
fieldsError?: boolean;
fieldErrorKey?: string;
fieldErrorCode?: string;
} | null;
const [error, setError] = useState<string | null>(() => {
if (locationState?.fieldErrorKey) return t("form.fieldRejected", { field: locationState.fieldErrorKey });
@@ -42,6 +47,10 @@ function ObjectEditFormLoaded({ object, id }: { object: AdminObjectView; id: str
locationState?.fieldErrorKey ?? null,
);
const [fieldErrorCode, setFieldErrorCode] = useState<string | null>(
locationState?.fieldErrorCode ?? null,
);
useBreadcrumb([
{ label: t("nav.objects"), to: "/objects" },
{ label: object.object_number, to: `/objects/${id}` },
@@ -64,6 +73,7 @@ function ObjectEditFormLoaded({ object, id }: { object: AdminObjectView; id: str
const onSubmit = async (values: ObjectFormValues): Promise<boolean> => {
setError(null);
setFieldErrorKey(null);
setFieldErrorCode(null);
try {
await update.mutateAsync({ id, body: values.core });
@@ -71,6 +81,7 @@ function ObjectEditFormLoaded({ object, id }: { object: AdminObjectView; id: str
} catch (e) {
if (e instanceof FieldRejection) {
setFieldErrorKey(e.field);
setFieldErrorCode(e.code);
setError(t("form.fieldRejected", { field: e.field }));
} else {
setError(t("form.rejected"));
@@ -89,6 +100,7 @@ function ObjectEditFormLoaded({ object, id }: { object: AdminObjectView; id: str
defaults={defaults}
formError={error}
fieldErrorKey={fieldErrorKey}
fieldErrorCode={fieldErrorCode}
onSubmit={onSubmit}
onCancel={() => navigate(`/objects/${id}`)}
/>