// AK-P17a Interim-UI (AD-28) — "my documents" screen composed from ~/ui (D-HR // "Eigene Dokumente", archetype A2). Renders the server-built HrDocumentListVM; // office-uploaded docs are read-only (no archive action), the employee can always // open/download. Kind filter is client-side. Self-upload is wired: the dialog // collects metadata + a file and hands it to `actions.onUpload`; the route drives // the chunked upload (reusing the Files pipeline) and links the resulting File as // an HrEmployeeDocument. Upload progress is injected as `upload`. // Final Subframe optics = tracked design-nachzug. import { useEffect, useRef, useState } from "react"; import { useTranslation } from "react-i18next"; import { AppLink } from "~/components/app/AppLink"; import { FeatherFileText, FeatherUpload } from "@subframe/core"; import type { HrDocumentKind, HrDocumentListVM } from "@hivegrid/view-models"; import { PAGE_HEADER_ICON_CLASS, PageBody, PageHeader, PageShell, PageToolbar } from "../shared/PageShell"; import { Alert } from "~/ui/components/Alert"; import { BadgeFeedback } from "~/ui/components/BadgeFeedback"; import { Button } from "~/ui/components/Button"; import { Dialog } from "~/ui/components/Dialog"; import { EmptyState } from "~/ui/components/EmptyState"; import { Select } from "~/ui/components/Select"; import { Table } from "~/ui/components/Table"; import { TextInput } from "~/ui/components/TextInput"; import { APP_TIME_ZONE } from "~/locale/format"; /** Injected upload state (owned by the route, which posts the file multipart). */ export type HrDocumentUploadState = { status: "idle" | "uploading" | "done" | "error"; errorKey: string | null; }; export type HrMyDocumentsUploadInput = { file: File; title: string; documentKind: HrDocumentKind; validUntilIso: string | null; }; export type HrMyDocumentsActions = { /** POSTs intent=archive for an own (non-office) document. */ onArchive: (documentId: string) => void; /** Hand a picked file + metadata to the route (multipart upload → createDocument). */ onUpload: (input: HrMyDocumentsUploadInput) => void; /** Reset the injected upload state (called when a fresh dialog session opens). */ onResetUpload: () => void; }; export type HrMyDocumentsPageProps = { vm: HrDocumentListVM; submitting: boolean; upload: HrDocumentUploadState; actions: HrMyDocumentsActions; }; const FILTER_ALL = "__all__"; const KINDS: readonly HrDocumentKind[] = ["contract", "certificate", "identification", "qualification", "other"]; export function HrMyDocumentsPage({ vm, submitting, upload, actions }: HrMyDocumentsPageProps) { const { t, i18n } = useTranslation(); const [kind, setKind] = useState(null); const [uploadOpen, setUploadOpen] = useState(false); const [form, setForm] = useState<{ title: string; documentKind: HrDocumentKind; validUntil: string }>({ title: "", documentKind: "other", validUntil: "" }); const [file, setFile] = useState(null); const fileInputRef = useRef(null); // Close + reset the dialog once the route reports the upload finished. useEffect(() => { if (upload.status === "done" && uploadOpen) { setUploadOpen(false); setForm({ title: "", documentKind: "other", validUntil: "" }); setFile(null); if (fileInputRef.current) fileInputRef.current.value = ""; } }, [upload.status, uploadOpen]); if (vm.status !== "ready" || !vm.data) { return ( } title={t("hr.documents.title")} subtitle={t("hr.documents.subtitle")} /> {null} ); } const { rows, canUpload, emptyHeadlineKey, emptyBodyKey } = vm.data; const dateFormatter = new Intl.DateTimeFormat(i18n.language, { timeZone: APP_TIME_ZONE, dateStyle: "medium" }); const visible = rows.filter((row) => (kind ? row.documentKind === kind : true)); const busy = upload.status === "uploading"; function submitUpload() { if (!file || form.title.trim().length === 0) return; actions.onUpload({ file, title: form.title.trim(), documentKind: form.documentKind, validUntilIso: form.validUntil || null }); } return ( } title={t("hr.documents.title")} subtitle={t("hr.documents.subtitle")} actions={ canUpload ? ( ) : undefined } /> {/* --- Filter bar: full-bleed page chrome, same strip as the other list screens. Still only shown when there is something to filter. --- */} {rows.length > 0 ? ( ) : null} {rows.length === 0 ? (
) : visible.length === 0 ? ( ) : (
{t("hr.documents.column.title")}{t("hr.documents.column.kind")}{t("hr.documents.column.date")}{t("hr.documents.column.validity")} } > {visible.map((row) => (
{row.title} {row.readOnly ? ( {t("hr.documents.status.readOnly")} ) : null}
{t(row.kindKey)} {dateFormatter.format(new Date(row.createdAtIso))} {row.validUntilIso ? ( row.isExpired ? ( {t("hr.documents.status.expired")} ) : ( {dateFormatter.format(new Date(row.validUntilIso))} ) ) : ( — )} {!row.readOnly ? (
) : null}
))}
)} {/* Upload dialog (self-service). The route drives the chunked upload + link. */} { if (!busy) setUploadOpen(next); }}>
{t("hr.documents.upload.dialog.title")}
setForm((s) => ({ ...s, title: e.target.value }))} data-ui-id="ui.hr.documents.upload.title" /> {upload.status !== "idle" ? (
{upload.status === "error" ? ( ) : upload.status === "uploading" ? ( {t("hr.documents.upload.status.uploading")} ) : null}
) : null}
); }