feat(web): set breadcrumb trails on all AppShell routes (#54)
This commit is contained in:
@@ -2,16 +2,31 @@ import { useState } from "react";
|
||||
import { useLocation, useNavigate, useParams } from "react-router-dom";
|
||||
import { useTranslation } from "react-i18next";
|
||||
|
||||
import type { components } from "../api/schema";
|
||||
import { useObject, useUpdateObject, useSetFields, FieldRejection } from "../api/queries";
|
||||
import { useBreadcrumb } from "../shell/use-breadcrumb";
|
||||
import { ObjectForm, type ObjectCore, type ObjectFormValues } from "./object-form";
|
||||
|
||||
type AdminObjectView = components["schemas"]["AdminObjectView"];
|
||||
|
||||
export function ObjectEditForm() {
|
||||
const { t } = useTranslation();
|
||||
const { id } = useParams();
|
||||
|
||||
const { data: object, isLoading } = useObject(id!);
|
||||
|
||||
if (isLoading) return <div className="p-4" role="status" aria-label="loading" />;
|
||||
|
||||
if (!object) return <p className="p-4 text-sm text-muted-foreground">{t("objects.notFound")}</p>;
|
||||
|
||||
return <ObjectEditFormLoaded object={object} id={id!} />;
|
||||
}
|
||||
|
||||
function ObjectEditFormLoaded({ object, id }: { object: AdminObjectView; id: string }) {
|
||||
const { t } = useTranslation();
|
||||
const navigate = useNavigate();
|
||||
const location = useLocation();
|
||||
|
||||
const { data: object, isLoading } = useObject(id!);
|
||||
const update = useUpdateObject();
|
||||
const setFields = useSetFields();
|
||||
|
||||
@@ -27,9 +42,11 @@ export function ObjectEditForm() {
|
||||
locationState?.fieldErrorKey ?? null,
|
||||
);
|
||||
|
||||
if (isLoading) return <div className="p-4" role="status" aria-label="loading" />;
|
||||
|
||||
if (!object) return <p className="p-4 text-sm text-muted-foreground">{t("objects.notFound")}</p>;
|
||||
useBreadcrumb([
|
||||
{ label: t("nav.objects"), to: "/objects" },
|
||||
{ label: object.object_number, to: `/objects/${id}` },
|
||||
{ label: t("actions.edit") },
|
||||
]);
|
||||
|
||||
const core: ObjectCore = {
|
||||
object_number: object.object_number,
|
||||
@@ -49,8 +66,8 @@ export function ObjectEditForm() {
|
||||
setFieldErrorKey(null);
|
||||
|
||||
try {
|
||||
await update.mutateAsync({ id: id!, body: values.core });
|
||||
await setFields.mutateAsync({ id: id!, fields: values.fields });
|
||||
await update.mutateAsync({ id, body: values.core });
|
||||
await setFields.mutateAsync({ id, fields: values.fields });
|
||||
} catch (e) {
|
||||
if (e instanceof FieldRejection) {
|
||||
setFieldErrorKey(e.field);
|
||||
|
||||
Reference in New Issue
Block a user