182 lines
8.8 KiB
TypeScript
182 lines
8.8 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; 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 (
|
|
<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}
|
|
{row.linkedFormLabel ? (
|
|
<BadgeFeedback farbe="subtle-positive" size="small" data-ui-id="ui.hr.admin.requestTemplates.linkedForm">
|
|
{t("hr.requests.templates.linkedForm", { name: row.linkedFormLabel })}
|
|
</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
|
|
triggerAriaLabel={t("hr.requests.field.kind")}
|
|
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>
|
|
<Select
|
|
label={t("hr.requests.field.approver")}
|
|
showLabel
|
|
triggerAriaLabel={t("hr.requests.field.approver")}
|
|
value={form.defaultApproverUserId}
|
|
onValueChange={(defaultApproverUserId: string) => setForm((current) => ({ ...current, defaultApproverUserId }))}
|
|
>
|
|
<Select.Item value={NO_APPROVER}>{t("hr.picker.noApprover")}</Select.Item>
|
|
{memberOptions.map((member) => (
|
|
<Select.Item key={member.userId} value={member.userId}>
|
|
{member.displayName} · {member.team ?? t("hr.picker.noTeam")} · {member.roleNames.join(", ") || t("hr.picker.noRole")}
|
|
</Select.Item>
|
|
))}
|
|
</Select>
|
|
{linkableForms.length > 0 ? (
|
|
<Select
|
|
label={t("hr.requests.field.linkedForm")}
|
|
showLabel
|
|
triggerAriaLabel={t("hr.requests.field.linkedForm")}
|
|
value={form.linkedFormId}
|
|
onValueChange={(v: string) => setForm((s) => ({ ...s, linkedFormId: v }))}
|
|
data-ui-id="ui.hr.admin.requestTemplates.new.linkedForm"
|
|
>
|
|
<Select.Item value={NO_LINKED_FORM}>{t("hr.requests.field.noLinkedForm")}</Select.Item>
|
|
{linkableForms.map((option) => (
|
|
<Select.Item key={option.id} value={option.id}>
|
|
{option.label}
|
|
</Select.Item>
|
|
))}
|
|
</Select>
|
|
) : null}
|
|
</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>
|
|
);
|
|
}
|