171 lines
8.6 KiB
TypeScript
171 lines
8.6 KiB
TypeScript
// AK-P17b Interim-UI (AD-28) — upload-reminder editor (admin) composed from ~/ui
|
|
// (D-HR "Upload-Erinnerungen", archetype A2 + A5). Pure presentational: create via
|
|
// a real Dialog; pause/resume/archive via injected actions (dispatch runs in the
|
|
// worker cron). Final Subframe optics = tracked design-nachzug.
|
|
|
|
import { type MouseEvent, useState } from "react";
|
|
import { useTranslation } from "react-i18next";
|
|
import { FeatherPlus } from "@subframe/core";
|
|
import type { HrReminderCadenceKind, HrReminderListVM } from "@hivegrid/view-models";
|
|
import { BadgeFeedback } from "~/ui/components/BadgeFeedback";
|
|
import { Button } from "~/ui/components/Button";
|
|
import { Card } from "~/ui/components/Card";
|
|
import { Checkbox } from "~/ui/components/Checkbox";
|
|
import { Dialog } from "~/ui/components/Dialog";
|
|
import { EmptyState } from "~/ui/components/EmptyState";
|
|
import { Select } from "~/ui/components/Select";
|
|
import { TextInput } from "~/ui/components/TextInput";
|
|
import { DateField } from "~/components/screens/tasks/DateField";
|
|
|
|
export type HrAdminUploadRemindersActions = {
|
|
onCreate: (input: {
|
|
title: string;
|
|
documentKind: string;
|
|
cadenceKind: string;
|
|
intervalMonths: string;
|
|
audienceKind: string;
|
|
dueAt: string;
|
|
mandatory: boolean;
|
|
escalate: boolean;
|
|
}) => void;
|
|
onSetStatus: (reminderId: string, status: "active" | "paused") => void;
|
|
onArchive: (reminderId: string) => void;
|
|
};
|
|
|
|
export type HrAdminUploadRemindersPageProps = {
|
|
vm: HrReminderListVM;
|
|
cadences: readonly HrReminderCadenceKind[];
|
|
documentKinds: readonly string[];
|
|
audiences: readonly string[];
|
|
submitting: boolean;
|
|
actions: HrAdminUploadRemindersActions;
|
|
};
|
|
|
|
const EMPTY = { title: "", intervalMonths: "", mandatory: false, escalate: false };
|
|
|
|
export function HrAdminUploadRemindersPage({ vm, cadences, documentKinds, audiences, submitting, actions }: HrAdminUploadRemindersPageProps) {
|
|
const { t } = useTranslation();
|
|
const [open, setOpen] = useState(false);
|
|
const [form, setForm] = useState({ ...EMPTY, documentKind: documentKinds[0] ?? "other", cadenceKind: cadences[0] ?? "once", audienceKind: audiences[0] ?? "all" });
|
|
const rows = vm.data?.rows ?? [];
|
|
|
|
function reset() {
|
|
setForm({ ...EMPTY, documentKind: documentKinds[0] ?? "other", cadenceKind: cadences[0] ?? "once", audienceKind: audiences[0] ?? "all" });
|
|
}
|
|
|
|
function submit(event: MouseEvent<HTMLButtonElement>) {
|
|
const el = (event.currentTarget as HTMLElement).closest("[data-ui-id='ui.hr.admin.uploadReminders.new']");
|
|
const dueAt = el?.querySelector<HTMLInputElement>("input[name='dueAt']")?.value ?? "";
|
|
if (!form.title.trim()) return;
|
|
actions.onCreate({ ...form, dueAt });
|
|
setOpen(false);
|
|
reset();
|
|
}
|
|
|
|
return (
|
|
<div className="flex w-full flex-col gap-6 p-6" data-ui-id="ui.hr.admin.uploadReminders">
|
|
<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.reminders.title")}</span>
|
|
<span className="text-body-default-regular-150 font-body-default-regular-150 text-text-neutral-secondary">{t("hr.reminders.subtitle")}</span>
|
|
</div>
|
|
<Button icon={<FeatherPlus />} onClick={() => setOpen(true)} data-ui-id="ui.hr.admin.uploadReminders.newBtn">
|
|
{t("hr.reminders.action.create")}
|
|
</Button>
|
|
</div>
|
|
|
|
{rows.length === 0 ? (
|
|
<div data-ui-id="ui.hr.admin.uploadReminders.empty">
|
|
<EmptyState title={t("hr.reminders.empty.headline")} body={t("hr.reminders.empty.body")} />
|
|
</div>
|
|
) : (
|
|
<div className="flex w-full flex-col gap-2" data-ui-id="ui.hr.admin.uploadReminders.list">
|
|
{rows.map((row) => (
|
|
<Card key={row.id} data-row-id={row.id} data-status={row.status}>
|
|
<div className="flex w-full items-center justify-between gap-4">
|
|
<div className="flex flex-col gap-1">
|
|
<span className="text-body-default-medium-0 font-body-default-medium-0 text-text-neutral-primary">{row.title}</span>
|
|
<span className="text-body-small-regular-0 font-body-small-regular-0 text-text-neutral-tertiary">
|
|
{t(row.cadenceLabelKey)} · {t("hr.reminders.pending", { count: row.pendingCount })}
|
|
</span>
|
|
</div>
|
|
<div className="flex items-center gap-2">
|
|
<BadgeFeedback farbe={row.status === "active" ? "subtle-positive" : "subtle-neutral"} size="small">
|
|
{t(row.statusLabelKey)}
|
|
</BadgeFeedback>
|
|
{row.status === "active" ? (
|
|
<Button variant="tertiary" size="small" loading={submitting} onClick={() => actions.onSetStatus(row.id, "paused")}>
|
|
{t("hr.reminders.action.pause")}
|
|
</Button>
|
|
) : (
|
|
<Button variant="tertiary" size="small" loading={submitting} onClick={() => actions.onSetStatus(row.id, "active")}>
|
|
{t("hr.reminders.action.resume")}
|
|
</Button>
|
|
)}
|
|
<Button variant="tertiary" size="small" loading={submitting} onClick={() => actions.onArchive(row.id)}>
|
|
{t("hr.reminders.action.archive")}
|
|
</Button>
|
|
</div>
|
|
</div>
|
|
</Card>
|
|
))}
|
|
</div>
|
|
)}
|
|
|
|
<Dialog open={open} onOpenChange={setOpen}>
|
|
<Dialog.Content className="w-full max-w-[720px] p-4" data-ui-id="ui.hr.admin.uploadReminders.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.reminders.action.create")}</span>
|
|
<div className="flex w-full flex-col gap-4">
|
|
<TextInput label={t("hr.reminders.field.title")} showLabel fillContainer>
|
|
<TextInput.Input value={form.title} onChange={(e) => setForm((s) => ({ ...s, title: e.target.value }))} />
|
|
</TextInput>
|
|
<div className="flex flex-wrap gap-4">
|
|
<Select label={t("hr.reminders.field.documentKind")} showLabel value={form.documentKind} onValueChange={(v: string) => setForm((s) => ({ ...s, documentKind: v }))}>
|
|
{documentKinds.map((k) => (
|
|
<Select.Item key={k} value={k}>
|
|
{t(`hr.document.kind.${k}`)}
|
|
</Select.Item>
|
|
))}
|
|
</Select>
|
|
<Select label={t("hr.reminders.field.cadence")} showLabel value={form.cadenceKind} onValueChange={(v: string) => setForm((s) => ({ ...s, cadenceKind: v as HrReminderCadenceKind }))}>
|
|
{cadences.map((c) => (
|
|
<Select.Item key={c} value={c}>
|
|
{t(`hr.reminders.cadence.${c}`)}
|
|
</Select.Item>
|
|
))}
|
|
</Select>
|
|
<Select label={t("hr.reminders.field.audience")} showLabel value={form.audienceKind} onValueChange={(v: string) => setForm((s) => ({ ...s, audienceKind: v }))}>
|
|
{audiences.map((a) => (
|
|
<Select.Item key={a} value={a}>
|
|
{t(`hr.audience.${a}`)}
|
|
</Select.Item>
|
|
))}
|
|
</Select>
|
|
</div>
|
|
<div className="flex flex-wrap gap-4">
|
|
<TextInput label={t("hr.reminders.field.interval")} showLabel>
|
|
<TextInput.Input type="number" value={form.intervalMonths} onChange={(e) => setForm((s) => ({ ...s, intervalMonths: e.target.value }))} />
|
|
</TextInput>
|
|
<DateField label={t("hr.reminders.field.due")} name="dueAt" />
|
|
</div>
|
|
<div className="flex flex-wrap gap-4">
|
|
<Checkbox label={t("hr.reminders.field.mandatory")} checked={form.mandatory} onCheckedChange={(c: boolean) => setForm((s) => ({ ...s, mandatory: c }))} />
|
|
<Checkbox label={t("hr.reminders.field.escalate")} checked={form.escalate} onCheckedChange={(c: boolean) => setForm((s) => ({ ...s, escalate: c }))} />
|
|
</div>
|
|
</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.uploadReminders.new.submit">
|
|
{t("hr.reminders.action.create")}
|
|
</Button>
|
|
</div>
|
|
</div>
|
|
</Dialog.Content>
|
|
</Dialog>
|
|
</div>
|
|
);
|
|
}
|