// 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(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 (
{t("hr.requests.title")} {t("hr.requests.subtitle")}
{tab === "own" ? ( ) : null}
{tabs.map((entry) => ( {t(`hr.requests.tab.${entry}`)} ))}
{tab === "own" ? ( ownRows.length === 0 ? (
) : (
{ownRows.map((row) => (
{row.title} {t(row.kindLabelKey)}
{t(row.statusLabelKey)} {row.canWithdraw ? ( ) : null}
))}
) ) : null} {tab === "approvals" ? ( approverRows.length === 0 ? (
) : (
{approverRows.map((row) => (
{row.title} {row.employeeLabel} · {t(row.kindLabelKey)}
))}
) ) : null} {/* New request dialog */}
{t("hr.requests.action.new")}
setForm((s) => ({ ...s, title: e.target.value }))} /> setForm((s) => ({ ...s, approverUserId: e.target.value }))} />
{/* Clarify dialog */} !open && setClarifyFor(null)}>
{t("hr.requests.action.clarify")}
); }