// AK-P17b Interim-UI (AD-28) — request-template editor (admin) composed from ~/ui // (D-HR "Antragsvorlagen", archetype A2 + A5). Pure presentational: create via a // real Dialog; activate/archive via injected actions. Final Subframe optics = // tracked design-nachzug. import { useState } from "react"; import { useTranslation } from "react-i18next"; import { FeatherPlus } from "@subframe/core"; import type { HrRequestKind, HrRequestTemplateListVM } from "@hivegrid/view-models"; import { BadgeFeedback } from "~/ui/components/BadgeFeedback"; import { Button } from "~/ui/components/Button"; import { Card } from "~/ui/components/Card"; import { Dialog } from "~/ui/components/Dialog"; import { EmptyState } from "~/ui/components/EmptyState"; import { Select } from "~/ui/components/Select"; import { TextInput } from "~/ui/components/TextInput"; export type HrAdminRequestTemplatesActions = { onCreate: (input: { requestKind: string; defaultApproverUserId: string; title: string; description: string; linkedFormId: string }) => void; onToggle: (templateId: string, isActive: boolean) => void; onArchive: (templateId: string) => void; }; /** Select sentinel — ~/ui Select items need a non-empty value. */ const NO_LINKED_FORM = "__none__"; const NO_APPROVER = "__none__"; export type HrAdminMemberOption = { userId: string; displayName: string; team: string | null; roleNames: readonly string[]; }; export type HrAdminRequestTemplatesPageProps = { vm: HrRequestTemplateListVM; kinds: readonly HrRequestKind[]; memberOptions: readonly HrAdminMemberOption[]; submitting: boolean; actions: HrAdminRequestTemplatesActions; }; export function HrAdminRequestTemplatesPage({ vm, kinds, memberOptions, submitting, actions }: HrAdminRequestTemplatesPageProps) { const { t } = useTranslation(); const [open, setOpen] = useState(false); const [form, setForm] = useState({ requestKind: kinds[0] ?? "expense", defaultApproverUserId: NO_APPROVER, title: "", description: "", linkedFormId: NO_LINKED_FORM }); const rows = vm.data?.rows ?? []; const linkableForms = vm.data?.linkableForms ?? []; function submit() { if (!form.title.trim()) return; actions.onCreate({ ...form, defaultApproverUserId: form.defaultApproverUserId === NO_APPROVER ? "" : form.defaultApproverUserId, linkedFormId: form.linkedFormId === NO_LINKED_FORM ? "" : form.linkedFormId, }); setOpen(false); setForm({ requestKind: kinds[0] ?? "expense", defaultApproverUserId: NO_APPROVER, title: "", description: "", linkedFormId: NO_LINKED_FORM }); } return (
{t("hr.requests.templates.title")} {t("hr.requests.templates.subtitle")}
{rows.length === 0 ? (
) : (
{rows.map((row) => (
{row.title} {t(row.kindLabelKey)} {!row.isActive ? ( {t("hr.requests.templates.inactive")} ) : null} {row.linkedFormLabel ? ( {t("hr.requests.templates.linkedForm", { name: row.linkedFormLabel })} ) : null}
))}
)}
{t("hr.requests.templates.action.create")}
setForm((s) => ({ ...s, title: e.target.value }))} /> setForm((s) => ({ ...s, description: e.target.value }))} /> {linkableForms.length > 0 ? ( ) : null}
); }