import { FormDialog } from "@repo/shadcn-ui/components/form-dialog"; import { useTranslation } from "react-i18next"; import type { CatalogItemDTO } from "../common"; import { CatalogFieldForm } from "./catalog-form"; import { CatalogTemplateForm } from "./catalog-template-form"; export type CatalogEditor = { kind: "field" | "template"; item?: CatalogItemDTO; copy?: CatalogItemDTO; }; function editorTitle(editor: CatalogEditor) { if (editor.kind === "field") { return editor.item ? "editField" : "newField"; } return editor.item ? "editTemplate" : "newTemplate"; } export function CatalogEditorDialog({ editor, items, scope, csrfToken, onClose, }: { editor: CatalogEditor; items: readonly CatalogItemDTO[]; scope: string; csrfToken: string; onClose: () => void; }) { const { t } = useTranslation("resources"); return ( { if (!open) { onClose(); } }} open title={t(editorTitle(editor))} wide={editor.kind === "template"} > {editor.kind === "field" ? ( onClose()} scope={scope} /> ) : ( onClose()} scope={scope} /> )} ); }