224 lines
11 KiB
TypeScript
224 lines
11 KiB
TypeScript
// AK-P17b Interim-UI (AD-28) — generic HR requests composed from ~/ui (D-HR
|
|
// "Anträge", archetype A2 + A4/A5). Pure presentational: URL-driven tabs (own /
|
|
// approvals); new (from optional template) + clarify via real Dialogs; other
|
|
// actions injected (route owns the fetcher). Final Subframe optics = design-nachzug.
|
|
|
|
import { useState } from "react";
|
|
import { useTranslation } from "react-i18next";
|
|
import { FeatherPlus } from "@subframe/core";
|
|
import type { HrRequestApproverVM, HrRequestKind, HrRequestOwnVM } 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 { Tabs } from "~/ui/components/Tabs";
|
|
import { TextArea } from "~/ui/components/TextArea";
|
|
import { TextInput } from "~/ui/components/TextInput";
|
|
|
|
export type HrRequestsTab = "own" | "approvals";
|
|
export type HrRequestTemplateOption = { id: string; title: string; requestKind: HrRequestKind };
|
|
|
|
export type HrRequestsActions = {
|
|
onSubmit: (input: { templateId: string; requestKind: string; approverUserId: string; title: string; details: string }) => void;
|
|
onWithdraw: (requestId: string) => void;
|
|
onApprove: (requestId: string) => void;
|
|
onReject: (requestId: string) => void;
|
|
onClarify: (requestId: string, question: string) => void;
|
|
};
|
|
|
|
export type HrRequestsPageProps = {
|
|
tab: HrRequestsTab;
|
|
canApprove: boolean;
|
|
ownVm: HrRequestOwnVM;
|
|
approverVm: HrRequestApproverVM;
|
|
templates: readonly HrRequestTemplateOption[];
|
|
kinds: readonly HrRequestKind[];
|
|
tabHref: (tab: HrRequestsTab) => string;
|
|
submitting: boolean;
|
|
actions: HrRequestsActions;
|
|
};
|
|
|
|
const NO_TEMPLATE = "__none__";
|
|
|
|
export function HrRequestsPage({ tab, canApprove, ownVm, approverVm, templates, kinds, tabHref, submitting, actions }: HrRequestsPageProps) {
|
|
const { t } = useTranslation();
|
|
const [newOpen, setNewOpen] = useState(false);
|
|
const [clarifyFor, setClarifyFor] = useState<string | null>(null);
|
|
const [text, setText] = useState("");
|
|
const [form, setForm] = useState({ templateId: NO_TEMPLATE, requestKind: kinds[0] ?? "expense", approverUserId: "", title: "", details: "" });
|
|
|
|
const tabs: HrRequestsTab[] = canApprove ? ["own", "approvals"] : ["own"];
|
|
const ownRows = ownVm.data?.rows ?? [];
|
|
const approverRows = approverVm.data?.rows ?? [];
|
|
|
|
function submitNew() {
|
|
if (!form.title.trim()) return;
|
|
actions.onSubmit({ ...form, templateId: form.templateId === NO_TEMPLATE ? "" : form.templateId });
|
|
setNewOpen(false);
|
|
setForm({ templateId: NO_TEMPLATE, requestKind: kinds[0] ?? "expense", approverUserId: "", title: "", details: "" });
|
|
}
|
|
|
|
return (
|
|
<div className="flex w-full flex-col gap-6 p-6" data-ui-id="ui.hr.requests">
|
|
<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.title")}</span>
|
|
<span className="text-body-default-regular-150 font-body-default-regular-150 text-text-neutral-secondary">{t("hr.requests.subtitle")}</span>
|
|
</div>
|
|
{tab === "own" ? (
|
|
<Button icon={<FeatherPlus />} onClick={() => setNewOpen(true)} data-ui-id="ui.hr.requests.new">
|
|
{t("hr.requests.action.new")}
|
|
</Button>
|
|
) : null}
|
|
</div>
|
|
|
|
<div data-ui-id="ui.hr.requests.tabs">
|
|
<Tabs>
|
|
{tabs.map((entry) => (
|
|
<a key={entry} href={tabHref(entry)} className="contents no-underline">
|
|
<Tabs.Item active={tab === entry}>{t(`hr.requests.tab.${entry}`)}</Tabs.Item>
|
|
</a>
|
|
))}
|
|
</Tabs>
|
|
</div>
|
|
|
|
{tab === "own" ? (
|
|
ownRows.length === 0 ? (
|
|
<div data-ui-id="ui.hr.requests.own.empty">
|
|
<EmptyState title={t("hr.requests.own.empty.headline")} body={t("hr.requests.own.empty.body")} />
|
|
</div>
|
|
) : (
|
|
<div className="flex w-full flex-col gap-3" data-ui-id="ui.hr.requests.own.list">
|
|
{ownRows.map((row) => (
|
|
<Card key={row.id} data-row-id={row.id}>
|
|
<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.kindLabelKey)}</span>
|
|
</div>
|
|
<div className="flex items-center gap-2">
|
|
<BadgeFeedback farbe="subtle-neutral" size="small">
|
|
{t(row.statusLabelKey)}
|
|
</BadgeFeedback>
|
|
{row.canWithdraw ? (
|
|
<Button variant="tertiary" size="small" loading={submitting} onClick={() => actions.onWithdraw(row.id)}>
|
|
{t("hr.requests.action.withdraw")}
|
|
</Button>
|
|
) : null}
|
|
</div>
|
|
</div>
|
|
</Card>
|
|
))}
|
|
</div>
|
|
)
|
|
) : null}
|
|
|
|
{tab === "approvals" ? (
|
|
approverRows.length === 0 ? (
|
|
<div data-ui-id="ui.hr.requests.approvals.empty">
|
|
<EmptyState title={t("hr.requests.approver.empty.headline")} body={t("hr.requests.approver.empty.body")} />
|
|
</div>
|
|
) : (
|
|
<div className="flex w-full flex-col gap-3" data-ui-id="ui.hr.requests.approvals.list">
|
|
{approverRows.map((row) => (
|
|
<Card key={row.id} data-row-id={row.id}>
|
|
<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">
|
|
{row.employeeLabel} · {t(row.kindLabelKey)}
|
|
</span>
|
|
</div>
|
|
<div className="flex items-center gap-2">
|
|
<Button variant="tertiary" size="small" onClick={() => { setText(""); setClarifyFor(row.id); }}>
|
|
{t("hr.requests.action.clarify")}
|
|
</Button>
|
|
<Button variant="destructive" size="small" loading={submitting} onClick={() => actions.onReject(row.id)}>
|
|
{t("hr.requests.action.reject")}
|
|
</Button>
|
|
<Button size="small" loading={submitting} onClick={() => actions.onApprove(row.id)}>
|
|
{t("hr.requests.action.approve")}
|
|
</Button>
|
|
</div>
|
|
</div>
|
|
</Card>
|
|
))}
|
|
</div>
|
|
)
|
|
) : null}
|
|
|
|
{/* New request dialog */}
|
|
<Dialog open={newOpen} onOpenChange={setNewOpen}>
|
|
<Dialog.Content className="w-full max-w-[560px] p-4" data-ui-id="ui.hr.requests.newDialog">
|
|
<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.action.new")}</span>
|
|
<div className="flex w-full flex-col gap-4">
|
|
<Select label={t("hr.requests.field.template")} showLabel value={form.templateId} onValueChange={(v: string) => setForm((s) => ({ ...s, templateId: v }))}>
|
|
<Select.Item value={NO_TEMPLATE}>{t("hr.requests.field.noTemplate")}</Select.Item>
|
|
{templates.map((tpl) => (
|
|
<Select.Item key={tpl.id} value={tpl.id}>
|
|
{tpl.title}
|
|
</Select.Item>
|
|
))}
|
|
</Select>
|
|
<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.approver")} showLabel fillContainer>
|
|
<TextInput.Input value={form.approverUserId} onChange={(e) => setForm((s) => ({ ...s, approverUserId: e.target.value }))} />
|
|
</TextInput>
|
|
<TextArea label={t("hr.requests.field.details")} showLabel className="w-full">
|
|
<TextArea.Input value={form.details} onChange={(e) => setForm((s) => ({ ...s, details: e.target.value }))} />
|
|
</TextArea>
|
|
</div>
|
|
<div className="flex justify-end gap-2">
|
|
<Button variant="neutral" onClick={() => setNewOpen(false)}>
|
|
{t("hr.action.cancel")}
|
|
</Button>
|
|
<Button loading={submitting} disabled={!form.title.trim()} onClick={submitNew} data-ui-id="ui.hr.requests.newDialog.submit">
|
|
{t("hr.requests.action.submit")}
|
|
</Button>
|
|
</div>
|
|
</div>
|
|
</Dialog.Content>
|
|
</Dialog>
|
|
|
|
{/* Clarify dialog */}
|
|
<Dialog open={clarifyFor !== null} onOpenChange={(open) => !open && setClarifyFor(null)}>
|
|
<Dialog.Content className="w-full max-w-[560px] p-4" data-ui-id="ui.hr.requests.clarifyDialog">
|
|
<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.action.clarify")}</span>
|
|
<TextArea label={t("hr.requests.field.question")} showLabel className="w-full">
|
|
<TextArea.Input value={text} onChange={(e) => setText(e.target.value)} />
|
|
</TextArea>
|
|
<div className="flex justify-end gap-2">
|
|
<Button variant="neutral" onClick={() => setClarifyFor(null)}>
|
|
{t("hr.action.cancel")}
|
|
</Button>
|
|
<Button
|
|
loading={submitting}
|
|
disabled={text.trim().length === 0}
|
|
onClick={() => {
|
|
if (clarifyFor) actions.onClarify(clarifyFor, text);
|
|
setClarifyFor(null);
|
|
}}
|
|
>
|
|
{t("hr.action.confirm")}
|
|
</Button>
|
|
</div>
|
|
</div>
|
|
</Dialog.Content>
|
|
</Dialog>
|
|
</div>
|
|
);
|
|
}
|