222 lines
9.9 KiB
TypeScript
222 lines
9.9 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 { FeatherClipboard, FeatherPlus } from "@subframe/core";
|
|
import type { HrRequestApproverVM, HrRequestKind, HrRequestOwnVM } from "@hivegrid/view-models";
|
|
import type { FormDefinition } from "@hivegrid/form-widget";
|
|
import { PAGE_HEADER_ICON_CLASS, PageBody, PageHeader, PageShell } from "../shared/PageShell";
|
|
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 { AppLink } from "~/components/app/AppLink";
|
|
import {
|
|
InternalFormRenderer,
|
|
type InternalFormValues,
|
|
} from "~/modules/forms/internal/InternalFormRenderer";
|
|
|
|
export type HrRequestsTab = "own" | "approvals";
|
|
export type HrRequestTemplateOption = { id: string; title: string; requestKind: HrRequestKind; definition: FormDefinition };
|
|
|
|
export type HrRequestsActions = {
|
|
onSubmit: (input: { templateId: string; values: InternalFormValues }) => 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[];
|
|
defaultFormDefinition: FormDefinition;
|
|
tabHref: (tab: HrRequestsTab) => string;
|
|
submitting: boolean;
|
|
actions: HrRequestsActions;
|
|
};
|
|
|
|
const NO_TEMPLATE = "__none__";
|
|
|
|
export function HrRequestsPage({ tab, canApprove, ownVm, approverVm, templates, defaultFormDefinition, tabHref, submitting, actions }: HrRequestsPageProps) {
|
|
const { t } = useTranslation();
|
|
const [newOpen, setNewOpen] = useState(false);
|
|
const [clarifyFor, setClarifyFor] = useState<string | null>(null);
|
|
const [text, setText] = useState("");
|
|
const [templateId, setTemplateId] = useState(NO_TEMPLATE);
|
|
|
|
const tabs: HrRequestsTab[] = canApprove ? ["own", "approvals"] : ["own"];
|
|
const ownRows = ownVm.data?.rows ?? [];
|
|
const approverRows = approverVm.data?.rows ?? [];
|
|
|
|
const selectedTemplate =
|
|
templateId === NO_TEMPLATE
|
|
? null
|
|
: templates.find((template) => template.id === templateId) ?? null;
|
|
const activeDefinition = selectedTemplate?.definition ?? defaultFormDefinition;
|
|
|
|
return (
|
|
<PageShell uiId="ui.hr.requests">
|
|
<PageHeader
|
|
icon={<FeatherClipboard className={PAGE_HEADER_ICON_CLASS} />}
|
|
title={t("hr.requests.title")}
|
|
subtitle={t("hr.requests.subtitle")}
|
|
actions={
|
|
tab === "own" ? (
|
|
<Button icon={<FeatherPlus />} onClick={() => setNewOpen(true)} data-ui-id="ui.hr.requests.new">
|
|
{t("hr.requests.action.new")}
|
|
</Button>
|
|
) : undefined
|
|
}
|
|
/>
|
|
<PageBody>
|
|
<div data-ui-id="ui.hr.requests.tabs">
|
|
<Tabs>
|
|
{tabs.map((entry) => (
|
|
<AppLink key={entry} href={tabHref(entry)} className="contents no-underline">
|
|
<Tabs.Item active={tab === entry}>{t(`hr.requests.tab.${entry}`)}</Tabs.Item>
|
|
</AppLink>
|
|
))}
|
|
</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={templateId} onValueChange={setTemplateId}>
|
|
<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>
|
|
</div>
|
|
<InternalFormRenderer
|
|
key={templateId}
|
|
definition={activeDefinition}
|
|
submitting={submitting}
|
|
uiId="ui.hr.requests.m05"
|
|
onCancel={() => setNewOpen(false)}
|
|
onSubmit={(values) => {
|
|
actions.onSubmit({
|
|
templateId: selectedTemplate?.id ?? "",
|
|
values,
|
|
});
|
|
setNewOpen(false);
|
|
setTemplateId(NO_TEMPLATE);
|
|
}}
|
|
/>
|
|
</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>
|
|
</PageBody>
|
|
</PageShell>
|
|
);
|
|
}
|