feat(web): highlight the offending field on a set_fields 422 (#28)
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -3,7 +3,7 @@ import { useNavigate } from "react-router-dom";
|
||||
import { useTranslation } from "react-i18next";
|
||||
|
||||
import { ObjectForm, type ObjectFormValues } from "./object-form";
|
||||
import { useCreateObject, useSetFields } from "../api/queries";
|
||||
import { useCreateObject, useSetFields, FieldRejection } from "../api/queries";
|
||||
|
||||
export function ObjectNewPage() {
|
||||
const { t } = useTranslation();
|
||||
@@ -32,8 +32,9 @@ export function ObjectNewPage() {
|
||||
if (Object.keys(values.fields).length > 0) {
|
||||
try {
|
||||
await setFields.mutateAsync({ id, fields: values.fields });
|
||||
} catch {
|
||||
navigate(`/objects/${id}/edit`, { state: { fieldsError: true } });
|
||||
} catch (e) {
|
||||
const fieldErrorKey = e instanceof FieldRejection ? e.field : undefined;
|
||||
navigate(`/objects/${id}/edit`, { state: { fieldsError: true, fieldErrorKey } });
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user