126 lines
6.4 KiB
TypeScript
126 lines
6.4 KiB
TypeScript
// 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 }) => void;
|
|
onToggle: (templateId: string, isActive: boolean) => void;
|
|
onArchive: (templateId: string) => void;
|
|
};
|
|
|
|
export type HrAdminRequestTemplatesPageProps = {
|
|
vm: HrRequestTemplateListVM;
|
|
kinds: readonly HrRequestKind[];
|
|
submitting: boolean;
|
|
actions: HrAdminRequestTemplatesActions;
|
|
};
|
|
|
|
export function HrAdminRequestTemplatesPage({ vm, kinds, submitting, actions }: HrAdminRequestTemplatesPageProps) {
|
|
const { t } = useTranslation();
|
|
const [open, setOpen] = useState(false);
|
|
const [form, setForm] = useState({ requestKind: kinds[0] ?? "expense", defaultApproverUserId: "", title: "", description: "" });
|
|
const rows = vm.data?.rows ?? [];
|
|
|
|
function submit() {
|
|
if (!form.title.trim()) return;
|
|
actions.onCreate(form);
|
|
setOpen(false);
|
|
setForm({ requestKind: kinds[0] ?? "expense", defaultApproverUserId: "", title: "", description: "" });
|
|
}
|
|
|
|
return (
|
|
<div className="flex w-full flex-col gap-6 p-6" data-ui-id="ui.hr.admin.requestTemplates">
|
|
<div className="flex flex-wrap items-start justify-between gap-4">
|
|
<div className="flex flex-col gap-0">
|
|
<span className="text-heading-2 font-heading-2 text-text-neutral-primary">{t("hr.requests.templates.title")}</span>
|
|
<span className="text-body-default-regular-150 font-body-default-regular-150 text-text-neutral-secondary">{t("hr.requests.templates.subtitle")}</span>
|
|
</div>
|
|
<Button icon={<FeatherPlus />} onClick={() => setOpen(true)} data-ui-id="ui.hr.admin.requestTemplates.newBtn">
|
|
{t("hr.requests.templates.action.create")}
|
|
</Button>
|
|
</div>
|
|
|
|
{rows.length === 0 ? (
|
|
<div data-ui-id="ui.hr.admin.requestTemplates.empty">
|
|
<EmptyState title={t("hr.requests.templates.empty.headline")} body={t("hr.requests.templates.empty.body")} />
|
|
</div>
|
|
) : (
|
|
<div className="flex w-full flex-col gap-2" data-ui-id="ui.hr.admin.requestTemplates.list">
|
|
{rows.map((row) => (
|
|
<Card key={row.id} data-row-id={row.id} data-active={row.isActive}>
|
|
<div className="flex w-full items-center justify-between gap-4">
|
|
<div className="flex items-center gap-2">
|
|
<span className="text-body-default-medium-0 font-body-default-medium-0 text-text-neutral-primary">{row.title}</span>
|
|
<BadgeFeedback farbe="subtle-neutral" size="small">
|
|
{t(row.kindLabelKey)}
|
|
</BadgeFeedback>
|
|
{!row.isActive ? (
|
|
<BadgeFeedback farbe="subtle-warning" size="small">
|
|
{t("hr.requests.templates.inactive")}
|
|
</BadgeFeedback>
|
|
) : null}
|
|
</div>
|
|
<div className="flex items-center gap-2">
|
|
<Button variant="tertiary" size="small" loading={submitting} onClick={() => actions.onToggle(row.id, !row.isActive)}>
|
|
{row.isActive ? t("hr.requests.templates.action.deactivate") : t("hr.requests.templates.action.activate")}
|
|
</Button>
|
|
<Button variant="tertiary" size="small" loading={submitting} onClick={() => actions.onArchive(row.id)}>
|
|
{t("hr.requests.templates.action.archive")}
|
|
</Button>
|
|
</div>
|
|
</div>
|
|
</Card>
|
|
))}
|
|
</div>
|
|
)}
|
|
|
|
<Dialog open={open} onOpenChange={setOpen}>
|
|
<Dialog.Content className="w-full max-w-[560px] p-4" data-ui-id="ui.hr.admin.requestTemplates.new">
|
|
<div className="flex w-full flex-col gap-6 p-2">
|
|
<span className="text-heading-3 font-heading-3 text-text-neutral-primary">{t("hr.requests.templates.action.create")}</span>
|
|
<div className="flex w-full flex-col gap-4">
|
|
<Select label={t("hr.requests.field.kind")} showLabel value={form.requestKind} onValueChange={(v: string) => setForm((s) => ({ ...s, requestKind: v as HrRequestKind }))}>
|
|
{kinds.map((kind) => (
|
|
<Select.Item key={kind} value={kind}>
|
|
{t(`hr.requests.kind.${kind}`)}
|
|
</Select.Item>
|
|
))}
|
|
</Select>
|
|
<TextInput label={t("hr.requests.field.title")} showLabel fillContainer>
|
|
<TextInput.Input value={form.title} onChange={(e) => setForm((s) => ({ ...s, title: e.target.value }))} />
|
|
</TextInput>
|
|
<TextInput label={t("hr.requests.field.description")} showLabel fillContainer>
|
|
<TextInput.Input value={form.description} onChange={(e) => setForm((s) => ({ ...s, description: e.target.value }))} />
|
|
</TextInput>
|
|
<TextInput label={t("hr.requests.field.approver")} showLabel fillContainer>
|
|
<TextInput.Input value={form.defaultApproverUserId} onChange={(e) => setForm((s) => ({ ...s, defaultApproverUserId: e.target.value }))} />
|
|
</TextInput>
|
|
</div>
|
|
<div className="flex justify-end gap-2">
|
|
<Button variant="neutral" onClick={() => setOpen(false)}>
|
|
{t("hr.action.cancel")}
|
|
</Button>
|
|
<Button loading={submitting} disabled={!form.title.trim()} onClick={submit} data-ui-id="ui.hr.admin.requestTemplates.new.submit">
|
|
{t("hr.requests.templates.action.create")}
|
|
</Button>
|
|
</div>
|
|
</div>
|
|
</Dialog.Content>
|
|
</Dialog>
|
|
</div>
|
|
);
|
|
}
|