Update hivegrid-cloud reference to latest main
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
1 parent
e98d38e716
commit
7b21524c86
3781 files changed
+373484
-225607
No files matched your search
+46
@@ -0,0 +1,46 @@
|
||||
import { vi, describe, it, expect } from "vitest";
|
||||
import "@testing-library/jest-dom";
|
||||
import { render } from "@testing-library/react";
|
||||
import { BrowserRouter as Router } from "react-router";
|
||||
import { buildAuditExportVM } from "@hivegrid/view-models";
|
||||
|
||||
import { AuditExportPage } from "./AuditExportPage";
|
||||
|
||||
vi.mock("react-i18next", () => ({
|
||||
useTranslation: () => ({ t: (str: string) => str, i18n: { language: "de" } }),
|
||||
}));
|
||||
|
||||
const vm = buildAuditExportVM({ defaultFrom: "2026-06-06", defaultTo: "2026-07-06", maxRows: 50000 });
|
||||
|
||||
function renderPage(result: Parameters<typeof AuditExportPage>[0]["result"] = null) {
|
||||
return render(
|
||||
<Router>
|
||||
<AuditExportPage vm={vm} result={result} />
|
||||
</Router>,
|
||||
);
|
||||
}
|
||||
|
||||
describe("AuditExportPage (interim-UI)", () => {
|
||||
it("renders the export form with purpose field and all three submit paths", () => {
|
||||
const { container } = renderPage();
|
||||
expect(container.querySelector('[data-ui-id="ui.audit.export"]')).toBeInTheDocument();
|
||||
expect(container.querySelector('[data-ui-id="ui.audit.export.form"]')).toBeInTheDocument();
|
||||
expect(container.querySelector('[data-ui-id="ui.audit.export.purpose"]')).toBeInTheDocument();
|
||||
expect(container.querySelector('[data-ui-id="ui.audit.export.csv"]')).toBeInTheDocument();
|
||||
expect(container.querySelector('[data-ui-id="ui.audit.export.pdf"]')).toBeInTheDocument();
|
||||
expect(container.querySelector('[data-ui-id="ui.audit.export.storage"]')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("renders the success panel with signed-URL download link", () => {
|
||||
const { container } = renderPage({ ok: true, url: "https://storage/x", rowCount: 12, integrityOk: true, expiresDays: 2 });
|
||||
expect(container.querySelector('[data-ui-id="ui.audit.export.result"]')).toBeInTheDocument();
|
||||
expect(container.querySelector('[data-ui-id="ui.audit.export.download"]')).toHaveAttribute("href", "https://storage/x");
|
||||
expect(container.querySelector('[data-ui-id="ui.audit.export.error"]')).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("renders the plain-text error banner for a rejected export", () => {
|
||||
const { container, getByText } = renderPage({ ok: false, errorKey: "auditExport.storage.errorPurpose" });
|
||||
expect(container.querySelector('[data-ui-id="ui.audit.export.error"]')).toBeInTheDocument();
|
||||
expect(getByText("settings:auditExport.storage.errorPurpose")).toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
+165
@@ -0,0 +1,165 @@
|
||||
// AK-P3 Interim-UI (AD-28) — Audit-Export preview screen composed from ~/ui.
|
||||
// Pure presentational component: renders the server-built AuditExportVM plus the
|
||||
// normalized action result passed as props. Submits are plain HTML forms against
|
||||
// the hosting route (GET streams CSV/PDF, POST runs the storage export) — no
|
||||
// useLoaderData/useFetcher in here. Final Subframe optics land as a tracked
|
||||
// design-nachzug once David's D-P3 ships.
|
||||
|
||||
import { useTranslation } from "react-i18next";
|
||||
import type { AuditExportResultVM, AuditExportVM } from "@hivegrid/view-models";
|
||||
import { Alert } from "~/ui/components/Alert";
|
||||
import { Button } from "~/ui/components/Button";
|
||||
import { Select } from "~/ui/components/Select";
|
||||
import { TextInput } from "~/ui/components/TextInput";
|
||||
import { DateField } from "../tasks/DateField";
|
||||
|
||||
const FILTER_ALL = "__all__";
|
||||
|
||||
export type AuditExportPageProps = {
|
||||
vm: AuditExportVM;
|
||||
/** Normalized storage-export action result (null = nothing submitted yet). */
|
||||
result: AuditExportResultVM | null;
|
||||
};
|
||||
|
||||
export function AuditExportPage({ vm, result }: AuditExportPageProps) {
|
||||
const { t, i18n } = useTranslation(["settings", "translations"]);
|
||||
|
||||
// Loading / not-ready: keep the marker so the shell + e2e see a stable surface.
|
||||
if (vm.status !== "ready" || !vm.data) {
|
||||
return <div className="flex w-full flex-col gap-6 p-6" data-ui-id="ui.audit.export" />;
|
||||
}
|
||||
|
||||
const data = vm.data;
|
||||
const numberFormatter = new Intl.NumberFormat(i18n.language);
|
||||
|
||||
return (
|
||||
<div className="flex w-full flex-col gap-6 p-6" data-ui-id="ui.audit.export">
|
||||
{/* Header: title + subtitle (0px rhythm) */}
|
||||
<div className="flex flex-col gap-0">
|
||||
<span className="text-heading-2 font-heading-2 text-text-neutral-primary">{t("translations:models.log.plural")}</span>
|
||||
<span className="text-body-default-regular-150 font-body-default-regular-150 text-text-neutral-secondary">
|
||||
{t("settings:auditExport.descriptionAdmin", { maxRows: numberFormatter.format(data.maxRows) })}
|
||||
</span>
|
||||
</div>
|
||||
|
||||
{/* One form, three submit paths: GET csv / GET pdf / POST storage export. */}
|
||||
<form method="get" className="flex flex-col gap-4" data-ui-id="ui.audit.export.form">
|
||||
<input type="hidden" name="export" value="csv" />
|
||||
<div className="flex flex-wrap items-end gap-4">
|
||||
<DateField label={t("settings:auditExport.filters.fromUtc")} name="from" defaultValue={data.defaultFrom} />
|
||||
<DateField label={t("settings:auditExport.filters.toUtc")} name="to" defaultValue={data.defaultTo} />
|
||||
<TextInput className="max-w-[240px]" label={t("settings:auditExport.filters.tenantIdOptional")} showLabel>
|
||||
<TextInput.Input name="tenantId" placeholder={t("settings:auditExport.filters.tenantIdPlaceholder")} />
|
||||
</TextInput>
|
||||
<SelectWithAny
|
||||
name="regulatoryScope"
|
||||
label={t("settings:auditExport.filters.regulatoryScope")}
|
||||
anyLabel={t("settings:auditExport.filters.any")}
|
||||
options={data.regulatoryScopeOptions.map((option) => ({ value: option.value, label: t(`settings:${option.labelKey}`) }))}
|
||||
/>
|
||||
<SelectWithAny
|
||||
name="actorType"
|
||||
label={t("settings:auditExport.filters.actorType")}
|
||||
anyLabel={t("settings:auditExport.filters.any")}
|
||||
options={data.actorTypeOptions.map((option) => ({ value: option.value, label: t(`settings:${option.labelKey}`) }))}
|
||||
/>
|
||||
<SelectWithAny
|
||||
name="outcome"
|
||||
label={t("settings:auditExport.filters.outcome")}
|
||||
anyLabel={t("settings:auditExport.filters.any")}
|
||||
options={data.outcomeOptions.map((option) => ({ value: option.value, label: t(`settings:${option.labelKey}`) }))}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className="flex flex-wrap items-end gap-4">
|
||||
{/* Purpose is mandatory for the storage export (DoD 3) — message slot names the rule. */}
|
||||
<TextInput
|
||||
className="w-full max-w-[480px]"
|
||||
label={t("settings:auditExport.storage.purpose")}
|
||||
showLabel
|
||||
message={t("settings:auditExport.storage.purposePlaceholder")}
|
||||
>
|
||||
<TextInput.Input name="purpose" data-ui-id="ui.audit.export.purpose" />
|
||||
</TextInput>
|
||||
<Select name="format" label={t("settings:auditExport.storage.format")} showLabel defaultValue="csv" className="max-w-[200px]">
|
||||
{data.formatOptions.map((option) => (
|
||||
<Select.Item key={option.value} value={option.value}>
|
||||
{t(`settings:${option.labelKey}`)}
|
||||
</Select.Item>
|
||||
))}
|
||||
</Select>
|
||||
</div>
|
||||
|
||||
<div className="flex flex-wrap gap-2">
|
||||
<Button type="submit" variant="secondary" data-ui-id="ui.audit.export.csv">
|
||||
{t("settings:auditExport.downloadCsv")}
|
||||
</Button>
|
||||
<Button type="submit" name="export" value="pdf" variant="secondary" data-ui-id="ui.audit.export.pdf">
|
||||
{t("settings:auditExport.downloadPdf")}
|
||||
</Button>
|
||||
<Button type="submit" formMethod="post" data-ui-id="ui.audit.export.storage">
|
||||
{t("settings:auditExport.storage.submit")}
|
||||
</Button>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
<AuditExportResultPanel result={result} />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function SelectWithAny({
|
||||
name,
|
||||
label,
|
||||
anyLabel,
|
||||
options,
|
||||
}: {
|
||||
name: string;
|
||||
label: string;
|
||||
anyLabel: string;
|
||||
options: readonly { value: string; label: string }[];
|
||||
}) {
|
||||
// Native form Select: the FILTER_ALL sentinel maps to "no filter" server-side
|
||||
// (the route drops it before parsing filters).
|
||||
return (
|
||||
<Select name={name} label={label} showLabel defaultValue={FILTER_ALL} className="max-w-[200px]">
|
||||
<Select.Item value={FILTER_ALL}>{anyLabel}</Select.Item>
|
||||
{options.map((option) => (
|
||||
<Select.Item key={option.value} value={option.value}>
|
||||
{option.label}
|
||||
</Select.Item>
|
||||
))}
|
||||
</Select>
|
||||
);
|
||||
}
|
||||
|
||||
function AuditExportResultPanel({ result }: { result: AuditExportResultVM | null }) {
|
||||
const { t, i18n } = useTranslation(["settings"]);
|
||||
if (!result) return null;
|
||||
if (!result.ok) {
|
||||
return (
|
||||
<div data-ui-id="ui.audit.export.error">
|
||||
<Alert variant="error" title={t(`settings:${result.errorKey}`)} />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
return (
|
||||
<div data-ui-id="ui.audit.export.result">
|
||||
<Alert
|
||||
variant={result.integrityOk ? "success" : "warning"}
|
||||
title={t("settings:auditExport.storage.success", {
|
||||
rowCount: new Intl.NumberFormat(i18n.language).format(result.rowCount),
|
||||
days: result.expiresDays,
|
||||
})}
|
||||
description={
|
||||
<span className="flex flex-wrap items-center gap-2">
|
||||
<a href={result.url} rel="noreferrer" className="text-text-feedback-link-default underline" data-ui-id="ui.audit.export.download">
|
||||
{t("settings:auditExport.storage.downloadLink")}
|
||||
</a>
|
||||
{!result.integrityOk ? <span>{t("settings:auditExport.storage.integrityWarning")}</span> : null}
|
||||
</span>
|
||||
}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
+99
@@ -0,0 +1,99 @@
|
||||
import { vi, describe, it, expect } from "vitest";
|
||||
import "@testing-library/jest-dom";
|
||||
import { fireEvent, render } from "@testing-library/react";
|
||||
import { BrowserRouter as Router } from "react-router";
|
||||
import { buildAuditListVM, type AuditListFilterState, type AuditListInputRow, type AuditListPagination } from "@hivegrid/view-models";
|
||||
|
||||
import { AuditListPage } from "./AuditListPage";
|
||||
|
||||
vi.mock("react-i18next", () => ({
|
||||
useTranslation: () => ({ t: (str: string) => str, i18n: { language: "de" } }),
|
||||
}));
|
||||
|
||||
const filter: AuditListFilterState = { from: null, to: null, actorType: null, action: null, outcome: null, targetType: null };
|
||||
const pagination: AuditListPagination = { page: 1, pageSize: 25, total: 2, totalPages: 1 };
|
||||
|
||||
function inputRow(overrides: Partial<AuditListInputRow> = {}): AuditListInputRow {
|
||||
return {
|
||||
id: "a1",
|
||||
createdAtIso: "2026-07-01T08:00:00.000Z",
|
||||
actorType: "user",
|
||||
actorEmail: "akeshan@example.com",
|
||||
actorId: "u1",
|
||||
action: "kontakt.updated",
|
||||
targetType: "Kontakt",
|
||||
targetId: "k1",
|
||||
outcome: "success",
|
||||
hasMetadata: false,
|
||||
...overrides,
|
||||
};
|
||||
}
|
||||
|
||||
function buildVM(rows: AuditListInputRow[]) {
|
||||
return buildAuditListVM({ rows, filter, pagination, canExport: true });
|
||||
}
|
||||
|
||||
function renderPage(vm: ReturnType<typeof buildVM>, onApply = vi.fn()) {
|
||||
return render(
|
||||
<Router>
|
||||
<AuditListPage vm={vm} exportHref="/admin/audit-export" actions={{ onApply }} />
|
||||
</Router>,
|
||||
);
|
||||
}
|
||||
|
||||
describe("AuditListPage (interim-UI)", () => {
|
||||
it("renders the list surface, filter bar, table rows and export CTA", () => {
|
||||
const { container } = renderPage(buildVM([inputRow(), inputRow({ id: "a2", actorType: "system", actorEmail: null, actorId: null })]));
|
||||
expect(container.querySelector('[data-ui-id="ui.audit.list"]')).toBeInTheDocument();
|
||||
expect(container.querySelector('[data-ui-id="ui.audit.list.filter"]')).toBeInTheDocument();
|
||||
expect(container.querySelector('[data-ui-id="ui.audit.list.table"]')).toBeInTheDocument();
|
||||
expect(container.querySelector('[data-row-id="a1"]')).toBeInTheDocument();
|
||||
expect(container.querySelector('[data-ui-id="ui.audit.list.export"]')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("prefers the persisted summary text over the derived key", () => {
|
||||
const { getByText } = renderPage(buildVM([inputRow({ summaryText: "Kontakt umbenannt" })]));
|
||||
expect(getByText("Kontakt umbenannt")).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("shows the empty state when there are no rows", () => {
|
||||
const { container } = renderPage(buildVM([]));
|
||||
expect(container.querySelector('[data-ui-id="ui.audit.list.empty"]')).toBeInTheDocument();
|
||||
expect(container.querySelector('[data-ui-id="ui.audit.list.table"]')).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("opens the detail drawer with a field-by-field diff and masked entries", () => {
|
||||
const { container } = renderPage(
|
||||
buildVM([
|
||||
inputRow({
|
||||
beforeDiff: { name: "Alt GmbH", apiKey: "[REDACTED]" },
|
||||
afterDiff: { name: "Neu GmbH", apiKey: "[REDACTED]" },
|
||||
summaryText: "Firma umbenannt",
|
||||
}),
|
||||
]),
|
||||
);
|
||||
const detailButton = container.querySelector('[data-ui-id="ui.audit.list.detail"]');
|
||||
expect(detailButton).toBeInTheDocument();
|
||||
fireEvent.click(detailButton!);
|
||||
|
||||
// Drawer content can live in a portal — query the document.
|
||||
expect(document.querySelector('[data-ui-id="ui.audit.list.drawer"]')).toBeInTheDocument();
|
||||
expect(document.querySelector('[data-diff-field="name"]')).toBeInTheDocument();
|
||||
const masked = document.querySelector('[data-diff-field="apiKey"]');
|
||||
expect(masked).toHaveAttribute("data-diff-masked", "true");
|
||||
expect(masked?.textContent).not.toContain("[REDACTED]");
|
||||
});
|
||||
|
||||
it("hides the detail button for rows without diff or metadata", () => {
|
||||
const { container } = renderPage(buildVM([inputRow()]));
|
||||
expect(container.querySelector('[data-ui-id="ui.audit.list.detail"]')).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("navigates server-side when the filter form is applied", () => {
|
||||
const onApply = vi.fn();
|
||||
const { container } = renderPage(buildVM([inputRow()]), onApply);
|
||||
const form = container.querySelector('[data-ui-id="ui.audit.list.filter"]');
|
||||
fireEvent.submit(form!);
|
||||
expect(onApply).toHaveBeenCalledWith(expect.objectContaining({ page: 1 }));
|
||||
});
|
||||
});
|
||||
+333
@@ -0,0 +1,333 @@
|
||||
// AK-P3 Interim-UI (AD-28) — Audit-Viewer preview screen composed from ~/ui.
|
||||
// Pure presentational component: renders the server-built AuditListVM passed as
|
||||
// a prop and reports filter/page changes through injected actions (server-side
|
||||
// navigation). No useLoaderData, no server imports. The detail drawer shows the
|
||||
// persisted field-by-field diff (DoD 2) with masked entries rendered as a
|
||||
// "value changed" placeholder. Final Subframe optics land as a tracked
|
||||
// design-nachzug once David's D-P3 ships.
|
||||
|
||||
import { useState } from "react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import type { AuditListFilterState, AuditListRow, AuditListVM } from "@hivegrid/view-models";
|
||||
import { Alert } from "~/ui/components/Alert";
|
||||
import { Button } from "~/ui/components/Button";
|
||||
import { Drawer } from "~/ui/components/Drawer";
|
||||
import { EmptyState } from "~/ui/components/EmptyState";
|
||||
import { Select } from "~/ui/components/Select";
|
||||
import { Table } from "~/ui/components/Table";
|
||||
import { Tag_Label } from "~/ui/components/Tag_Label";
|
||||
import { TextInput } from "~/ui/components/TextInput";
|
||||
import { DateField } from "../tasks/DateField";
|
||||
|
||||
// Non-empty sentinel for the "any" option (empty string is not a valid Select value).
|
||||
const FILTER_ALL = "__all__";
|
||||
|
||||
const ACTOR_TYPES = ["user", "admin", "api_key", "system", "plugin"] as const;
|
||||
const OUTCOMES = ["success", "failure", "blocked"] as const;
|
||||
|
||||
export type AuditListQuery = AuditListFilterState & { page: number };
|
||||
|
||||
export type AuditListActions = {
|
||||
/** Navigate (GET) to the same route with the given filter/page state. */
|
||||
onApply: (query: AuditListQuery) => void;
|
||||
};
|
||||
|
||||
export type AuditListPageProps = {
|
||||
vm: AuditListVM;
|
||||
/** Href of the export screen (shown when the VM allows exporting). */
|
||||
exportHref: string;
|
||||
actions: AuditListActions;
|
||||
};
|
||||
|
||||
function actorTypeKey(actorType: string): string {
|
||||
return actorType === "api_key" ? "apiKey" : actorType;
|
||||
}
|
||||
|
||||
export function AuditListPage({ vm, exportHref, actions }: AuditListPageProps) {
|
||||
const { t, i18n } = useTranslation(["settings", "translations"]);
|
||||
const [openRowId, setOpenRowId] = useState<string | null>(null);
|
||||
|
||||
// Loading / not-ready: keep the marker so the shell + e2e see a stable surface.
|
||||
if (vm.status !== "ready" || !vm.data) {
|
||||
return <div className="flex w-full flex-col gap-6 p-6" data-ui-id="ui.audit.list" />;
|
||||
}
|
||||
|
||||
const { rows, filter, pagination, canExport, emptyHeadlineKey, emptyBodyKey } = vm.data;
|
||||
const dateTimeFormatter = new Intl.DateTimeFormat(i18n.language, { dateStyle: "medium", timeStyle: "short" });
|
||||
const openRow = openRowId ? (rows.find((row) => row.id === openRowId) ?? null) : null;
|
||||
|
||||
const actorLabel = (raw: string) => (raw.startsWith("audit.") ? t(`settings:${raw}`) : raw);
|
||||
const summaryLabel = (row: AuditListRow) =>
|
||||
row.summaryText ?? t(`settings:${row.summaryKey}`, { ...row.summaryParams, actor: actorLabel(row.summaryParams.actor ?? "") });
|
||||
|
||||
function apply(patch: Partial<AuditListQuery>) {
|
||||
actions.onApply({ ...filter, page: 1, ...patch });
|
||||
}
|
||||
|
||||
function applyFilterForm(form: HTMLFormElement) {
|
||||
const data = new FormData(form);
|
||||
const text = (name: string) => {
|
||||
const value = data.get(name);
|
||||
return typeof value === "string" && value.trim().length > 0 ? value.trim() : null;
|
||||
};
|
||||
apply({
|
||||
from: text("from"),
|
||||
to: text("to"),
|
||||
action: text("action"),
|
||||
targetType: text("targetType"),
|
||||
});
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="flex w-full flex-col gap-6 p-6" data-ui-id="ui.audit.list">
|
||||
{/* Header: title + subtitle (0px rhythm) + export CTA */}
|
||||
<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("settings:audit.viewer.title")}</span>
|
||||
<span className="text-body-default-regular-150 font-body-default-regular-150 text-text-neutral-secondary">
|
||||
{t("settings:audit.viewer.subtitle")}
|
||||
</span>
|
||||
</div>
|
||||
{canExport ? (
|
||||
<a href={exportHref} className="no-underline" data-ui-id="ui.audit.list.export">
|
||||
<Button variant="secondary">{t("settings:audit.viewer.exportLink")}</Button>
|
||||
</a>
|
||||
) : null}
|
||||
</div>
|
||||
|
||||
{/* Filter bar: text/date fields submit via the apply button; selects navigate on change */}
|
||||
<form
|
||||
className="flex flex-wrap items-end gap-4"
|
||||
data-ui-id="ui.audit.list.filter"
|
||||
onSubmit={(event) => {
|
||||
event.preventDefault();
|
||||
applyFilterForm(event.currentTarget);
|
||||
}}
|
||||
>
|
||||
<DateField label={t("settings:auditExport.filters.fromUtc")} name="from" defaultValue={filter.from ?? ""} />
|
||||
<DateField label={t("settings:auditExport.filters.toUtc")} name="to" defaultValue={filter.to ?? ""} />
|
||||
<Select
|
||||
className="max-w-[200px]"
|
||||
label={t("settings:auditExport.filters.actorType")}
|
||||
showLabel
|
||||
value={filter.actorType ?? FILTER_ALL}
|
||||
onValueChange={(value: string) => apply({ actorType: value === FILTER_ALL ? null : value })}
|
||||
>
|
||||
<Select.Item value={FILTER_ALL}>{t("settings:auditExport.filters.any")}</Select.Item>
|
||||
{ACTOR_TYPES.map((actorType) => (
|
||||
<Select.Item key={actorType} value={actorType}>
|
||||
{t(`settings:auditExport.actorTypes.${actorTypeKey(actorType)}`)}
|
||||
</Select.Item>
|
||||
))}
|
||||
</Select>
|
||||
<Select
|
||||
className="max-w-[200px]"
|
||||
label={t("settings:auditExport.filters.outcome")}
|
||||
showLabel
|
||||
value={filter.outcome ?? FILTER_ALL}
|
||||
onValueChange={(value: string) => apply({ outcome: value === FILTER_ALL ? null : value })}
|
||||
>
|
||||
<Select.Item value={FILTER_ALL}>{t("settings:auditExport.filters.any")}</Select.Item>
|
||||
{OUTCOMES.map((outcome) => (
|
||||
<Select.Item key={outcome} value={outcome}>
|
||||
{t(`settings:auditExport.outcomes.${outcome}`)}
|
||||
</Select.Item>
|
||||
))}
|
||||
</Select>
|
||||
<TextInput className="max-w-[220px]" label={t("settings:audit.viewer.filters.action")} showLabel>
|
||||
<TextInput.Input name="action" defaultValue={filter.action ?? ""} placeholder={t("settings:audit.viewer.filters.actionPlaceholder")} />
|
||||
</TextInput>
|
||||
<TextInput className="max-w-[200px]" label={t("settings:audit.viewer.filters.targetType")} showLabel>
|
||||
<TextInput.Input name="targetType" defaultValue={filter.targetType ?? ""} />
|
||||
</TextInput>
|
||||
<Button type="submit" data-ui-id="ui.audit.list.filter.apply">
|
||||
{t("settings:audit.viewer.applyFilters")}
|
||||
</Button>
|
||||
</form>
|
||||
|
||||
{rows.length === 0 ? (
|
||||
<div data-ui-id="ui.audit.list.empty">
|
||||
<EmptyState title={t(`settings:${emptyHeadlineKey}`)} body={t(`settings:${emptyBodyKey}`)} />
|
||||
</div>
|
||||
) : (
|
||||
<div className="w-full overflow-x-auto" data-ui-id="ui.audit.list.table">
|
||||
<Table
|
||||
header={
|
||||
<Table.HeaderRow>
|
||||
<Table.HeaderCell>{t("settings:audit.viewer.columns.time")}</Table.HeaderCell>
|
||||
<Table.HeaderCell>{t("settings:audit.viewer.columns.actor")}</Table.HeaderCell>
|
||||
<Table.HeaderCell>{t("settings:audit.viewer.columns.action")}</Table.HeaderCell>
|
||||
<Table.HeaderCell>{t("settings:audit.viewer.columns.subject")}</Table.HeaderCell>
|
||||
<Table.HeaderCell>{t("settings:audit.viewer.columns.outcome")}</Table.HeaderCell>
|
||||
<Table.HeaderCell>{t("settings:audit.viewer.columns.summary")}</Table.HeaderCell>
|
||||
<Table.HeaderCell />
|
||||
</Table.HeaderRow>
|
||||
}
|
||||
>
|
||||
{rows.map((row) => (
|
||||
<Table.Row key={row.id} data-row-id={row.id}>
|
||||
<Table.Cell>
|
||||
<span className="whitespace-nowrap text-body-default-regular-0 font-body-default-regular-0 text-text-neutral-secondary">
|
||||
{dateTimeFormatter.format(new Date(row.createdAtIso))}
|
||||
</span>
|
||||
</Table.Cell>
|
||||
<Table.Cell>
|
||||
<div className="flex items-center gap-2">
|
||||
<Tag_Label tone="neutral-subtle" size="small" noAction>
|
||||
{t(`settings:${row.actorKindLabelKey}`)}
|
||||
</Tag_Label>
|
||||
<span className="text-body-default-regular-0 font-body-default-regular-0 text-text-neutral-primary">
|
||||
{actorLabel(row.actorLabel)}
|
||||
</span>
|
||||
</div>
|
||||
</Table.Cell>
|
||||
<Table.Cell>
|
||||
<span className="font-mono text-body-default-regular-0 text-text-neutral-secondary">{row.action}</span>
|
||||
</Table.Cell>
|
||||
<Table.Cell>
|
||||
<span className="text-body-default-regular-0 font-body-default-regular-0 text-text-neutral-secondary">
|
||||
{row.targetType ? `${row.targetType}${row.targetId ? ` #${row.targetId}` : ""}` : t("settings:audit.viewer.drawer.emptyValue")}
|
||||
</span>
|
||||
</Table.Cell>
|
||||
<Table.Cell>
|
||||
<span className="text-body-default-regular-0 font-body-default-regular-0 text-text-neutral-secondary">
|
||||
{t(`settings:auditExport.outcomes.${row.outcome}`, row.outcome)}
|
||||
</span>
|
||||
</Table.Cell>
|
||||
<Table.Cell>
|
||||
<span className="text-body-default-regular-0 font-body-default-regular-0 text-text-neutral-primary">{summaryLabel(row)}</span>
|
||||
</Table.Cell>
|
||||
<Table.Cell>
|
||||
{row.hasDetail ? (
|
||||
<Button variant="tertiary" size="small" onClick={() => setOpenRowId(row.id)} data-ui-id="ui.audit.list.detail">
|
||||
{t("settings:audit.viewer.detailButton")}
|
||||
</Button>
|
||||
) : null}
|
||||
</Table.Cell>
|
||||
</Table.Row>
|
||||
))}
|
||||
</Table>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* Server-side pagination */}
|
||||
<div className="flex items-center justify-between" data-ui-id="ui.audit.list.pagination">
|
||||
<span className="text-body-default-regular-0 font-body-default-regular-0 text-text-neutral-secondary">
|
||||
{t("settings:audit.viewer.pageInfo", {
|
||||
page: pagination.page,
|
||||
totalPages: pagination.totalPages,
|
||||
total: new Intl.NumberFormat(i18n.language).format(pagination.total),
|
||||
})}
|
||||
</span>
|
||||
<div className="flex gap-2">
|
||||
{pagination.page > 1 ? (
|
||||
<Button variant="tertiary" onClick={() => apply({ page: pagination.page - 1 })}>
|
||||
{t("settings:audit.viewer.prev")}
|
||||
</Button>
|
||||
) : null}
|
||||
{pagination.page < pagination.totalPages ? (
|
||||
<Button variant="tertiary" onClick={() => apply({ page: pagination.page + 1 })}>
|
||||
{t("settings:audit.viewer.next")}
|
||||
</Button>
|
||||
) : null}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<AuditDetailDrawer row={openRow} onClose={() => setOpenRowId(null)} />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function AuditDetailDrawer({ row, onClose }: { row: AuditListRow | null; onClose: () => void }) {
|
||||
const { t, i18n } = useTranslation(["settings", "translations"]);
|
||||
const dateTimeFormatter = new Intl.DateTimeFormat(i18n.language, { dateStyle: "medium", timeStyle: "short" });
|
||||
|
||||
return (
|
||||
<Drawer open={row !== null} onOpenChange={(open: boolean) => (open ? undefined : onClose())}>
|
||||
<Drawer.Content>
|
||||
{row ? (
|
||||
<div className="flex w-96 max-w-full flex-col gap-6 p-6" data-ui-id="ui.audit.list.drawer">
|
||||
<div className="flex flex-col gap-0">
|
||||
<span className="text-heading-3 font-heading-3 text-text-neutral-primary">{t("settings:audit.viewer.drawer.title")}</span>
|
||||
<span className="text-body-default-regular-150 font-body-default-regular-150 text-text-neutral-secondary">
|
||||
{dateTimeFormatter.format(new Date(row.createdAtIso))} · {row.action}
|
||||
</span>
|
||||
</div>
|
||||
|
||||
{row.summaryText ? (
|
||||
<span className="text-body-default-regular-150 font-body-default-regular-150 text-text-neutral-primary">{row.summaryText}</span>
|
||||
) : null}
|
||||
|
||||
{row.diff.length > 0 ? (
|
||||
<div className="flex flex-col gap-3" data-ui-id="ui.audit.list.drawer.diff">
|
||||
<span className="text-body-default-medium-0 font-body-default-medium-0 text-text-neutral-primary">
|
||||
{t("settings:audit.viewer.drawer.diffTitle")}
|
||||
</span>
|
||||
<Table
|
||||
header={
|
||||
<Table.HeaderRow>
|
||||
<Table.HeaderCell>{t("settings:audit.viewer.drawer.field")}</Table.HeaderCell>
|
||||
<Table.HeaderCell>{t("settings:audit.viewer.drawer.before")}</Table.HeaderCell>
|
||||
<Table.HeaderCell>{t("settings:audit.viewer.drawer.after")}</Table.HeaderCell>
|
||||
</Table.HeaderRow>
|
||||
}
|
||||
>
|
||||
{row.diff.map((entry) => (
|
||||
<Table.Row key={entry.field} data-diff-field={entry.field} data-diff-masked={entry.masked}>
|
||||
<Table.Cell>
|
||||
<span className="text-body-default-medium-0 font-body-default-medium-0 text-text-neutral-primary">{entry.field}</span>
|
||||
</Table.Cell>
|
||||
{entry.masked ? (
|
||||
<Table.Cell colSpan={2}>
|
||||
<Tag_Label tone="neutral-subtle" size="small" noAction>
|
||||
{t("settings:audit.viewer.drawer.masked")}
|
||||
</Tag_Label>
|
||||
</Table.Cell>
|
||||
) : (
|
||||
<>
|
||||
<Table.Cell>
|
||||
<span className="text-body-default-regular-0 font-body-default-regular-0 text-text-neutral-secondary">
|
||||
{entry.before ?? t("settings:audit.viewer.drawer.emptyValue")}
|
||||
</span>
|
||||
</Table.Cell>
|
||||
<Table.Cell>
|
||||
<span className="text-body-default-regular-0 font-body-default-regular-0 text-text-neutral-primary">
|
||||
{entry.after ?? t("settings:audit.viewer.drawer.emptyValue")}
|
||||
</span>
|
||||
</Table.Cell>
|
||||
</>
|
||||
)}
|
||||
</Table.Row>
|
||||
))}
|
||||
</Table>
|
||||
</div>
|
||||
) : null}
|
||||
|
||||
{row.metadataJson ? (
|
||||
<div className="flex flex-col gap-3" data-ui-id="ui.audit.list.drawer.metadata">
|
||||
<span className="text-body-default-medium-0 font-body-default-medium-0 text-text-neutral-primary">
|
||||
{t("settings:audit.viewer.drawer.metadataTitle")}
|
||||
</span>
|
||||
<pre className="max-h-80 w-full overflow-auto rounded-[4px] border border-solid border-border-default p-3 font-mono text-body-default-regular-0 text-text-neutral-secondary">
|
||||
{row.metadataJson}
|
||||
</pre>
|
||||
</div>
|
||||
) : null}
|
||||
|
||||
{row.diff.length === 0 && !row.metadataJson ? (
|
||||
<Alert variant="neutral" title={t("settings:audit.viewer.drawer.empty")} />
|
||||
) : null}
|
||||
|
||||
<div className="flex justify-end">
|
||||
<Button variant="secondary" onClick={onClose} data-ui-id="ui.audit.list.drawer.close">
|
||||
{t("settings:audit.viewer.drawer.close")}
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
) : (
|
||||
<div />
|
||||
)}
|
||||
</Drawer.Content>
|
||||
</Drawer>
|
||||
);
|
||||
}
|
||||
+53
@@ -0,0 +1,53 @@
|
||||
import { vi, describe, it, expect } from "vitest";
|
||||
import "@testing-library/jest-dom";
|
||||
import { render } from "@testing-library/react";
|
||||
import { BrowserRouter as Router } from "react-router";
|
||||
|
||||
import { CreateWorkspacePage, type CreateWorkspacePageProps } from "./CreateWorkspacePage";
|
||||
|
||||
vi.mock("react-i18next", () => ({
|
||||
useTranslation: () => ({ t: (str: string) => str, i18n: { language: "de" } }),
|
||||
}));
|
||||
|
||||
function baseProps(overrides: Partial<CreateWorkspacePageProps> = {}): CreateWorkspacePageProps {
|
||||
return {
|
||||
csrf: "csrf-token",
|
||||
error: undefined,
|
||||
backHref: "/select-tenant",
|
||||
...overrides,
|
||||
};
|
||||
}
|
||||
|
||||
describe("CreateWorkspacePage (interim-UI)", () => {
|
||||
it("renders the create surface + form/name/submit/back markers and the csrf field", () => {
|
||||
const { container } = render(
|
||||
<Router>
|
||||
<CreateWorkspacePage {...baseProps()} />
|
||||
</Router>,
|
||||
);
|
||||
expect(container.querySelector('[data-ui-id="ui.account.create.page"]')).toBeInTheDocument();
|
||||
expect(container.querySelector('[data-ui-id="ui.account.create.form"]')).toBeInTheDocument();
|
||||
expect(container.querySelector('[data-ui-id="ui.account.create.name"]')).toBeInTheDocument();
|
||||
expect(container.querySelector('[data-ui-id="ui.account.create.submit"]')).toBeInTheDocument();
|
||||
expect(container.querySelector('[data-ui-id="ui.account.create.back"]')).toBeInTheDocument();
|
||||
expect(container.querySelector('input[type="hidden"][name="csrf"][value="csrf-token"]')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("renders the error alert with its marker when an error is passed", () => {
|
||||
const { container } = render(
|
||||
<Router>
|
||||
<CreateWorkspacePage {...baseProps({ error: "Something went wrong" })} />
|
||||
</Router>,
|
||||
);
|
||||
expect(container.querySelector('[data-ui-id="ui.account.create.error"]')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("omits the error alert when there is no error", () => {
|
||||
const { container } = render(
|
||||
<Router>
|
||||
<CreateWorkspacePage {...baseProps()} />
|
||||
</Router>,
|
||||
);
|
||||
expect(container.querySelector('[data-ui-id="ui.account.create.error"]')).not.toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
+58
@@ -0,0 +1,58 @@
|
||||
// R-P2a Interim-UI (AD-28) — Create-workspace ("ohne Tenant") preview screen composed from ~/ui.
|
||||
// Presentational: the form posts to the /new-account route action (server-driven tenant create);
|
||||
// the route injects the csrf token, the idle-gated error message and the back target. No
|
||||
// useLoaderData / server imports here. Final Subframe optics land as a tracked design-nachzug
|
||||
// once David's D-P2 delta ships.
|
||||
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { FeatherArrowLeft } from "@subframe/core";
|
||||
import { AuthShell } from "~/components/auth/AuthShell";
|
||||
import { Alert } from "~/ui/components/Alert";
|
||||
import { Button } from "~/ui/components/Button";
|
||||
import { LinkButton } from "~/ui/components/LinkButton";
|
||||
import { TextInput } from "~/ui/components/TextInput";
|
||||
|
||||
export type CreateWorkspacePageProps = {
|
||||
/** CSRF token for the server-driven create action. */
|
||||
csrf: string;
|
||||
/** Error message from the last failed submit (route passes it only while idle). */
|
||||
error?: string;
|
||||
/** Back target: the tenant picker when the user already has workspaces, else login. */
|
||||
backHref: string;
|
||||
};
|
||||
|
||||
export function CreateWorkspacePage({ csrf, error, backHref }: CreateWorkspacePageProps) {
|
||||
const { t } = useTranslation();
|
||||
|
||||
return (
|
||||
<AuthShell
|
||||
title={t("app.tenants.create.title")}
|
||||
subtitle={t("app.tenants.create.headline")}
|
||||
titleAlign="start"
|
||||
dataUiId="ui.account.create.page"
|
||||
footer={
|
||||
<a href={backHref} className="no-underline" data-ui-id="ui.account.create.back">
|
||||
<LinkButton size="small" icon={<FeatherArrowLeft />}>
|
||||
{t("shared.goBack")}
|
||||
</LinkButton>
|
||||
</a>
|
||||
}
|
||||
>
|
||||
<form method="post" className="flex w-full flex-col gap-4" data-ui-id="ui.account.create.form">
|
||||
{/* The action intent is vestigial (the /new-account action reads only name+csrf) but stays
|
||||
in the wire payload as a stable contract other consumers/tests assert. */}
|
||||
<input type="hidden" name="action" value="create" readOnly />
|
||||
<input type="hidden" name="csrf" value={csrf} readOnly />
|
||||
<TextInput className="h-auto w-full flex-none" fillContainer showLabel label={t("shared.name")}>
|
||||
<TextInput.Input name="name" required placeholder={t("shared.name")} data-ui-id="ui.account.create.name" />
|
||||
</TextInput>
|
||||
|
||||
{error ? <Alert variant="error" notDismissible title={error} data-ui-id="ui.account.create.error" /> : null}
|
||||
|
||||
<Button type="submit" className="h-9 w-full flex-none" data-ui-id="ui.account.create.submit">
|
||||
{t("shared.create")}
|
||||
</Button>
|
||||
</form>
|
||||
</AuthShell>
|
||||
);
|
||||
}
|
||||
+85
@@ -0,0 +1,85 @@
|
||||
import { vi, describe, it, expect } from "vitest";
|
||||
import "@testing-library/jest-dom";
|
||||
import { render } from "@testing-library/react";
|
||||
import { BrowserRouter as Router } from "react-router";
|
||||
import { buildFileDetailVM } from "@hivegrid/view-models";
|
||||
|
||||
import { FileDetailPage } from "./FileDetailPage";
|
||||
|
||||
vi.mock("react-i18next", () => ({
|
||||
useTranslation: () => ({ t: (str: string) => str, i18n: { language: "de" } }),
|
||||
}));
|
||||
|
||||
const ENTITY_TYPES = ["contact", "company", "lead"] as const;
|
||||
|
||||
function detailData(overrides: Record<string, unknown> = {}) {
|
||||
const vm = buildFileDetailVM({
|
||||
id: "f1",
|
||||
displayName: "vertrag.pdf",
|
||||
mimeType: "application/pdf",
|
||||
sizeBytes: 4096,
|
||||
createdAtIso: "2026-01-02T10:00:00.000Z",
|
||||
tags: ["wichtig"],
|
||||
notes: "Bitte prüfen",
|
||||
source: "upload",
|
||||
previewStatus: "ready",
|
||||
scanStatus: "clean",
|
||||
previewUrl: "/acme/media/f1/preview",
|
||||
downloadUrl: "/acme/media/f1/original",
|
||||
assignedToUserId: null,
|
||||
linkedEntities: [{ entityType: "contact", entityId: "c1", linkRole: "owner", href: null }],
|
||||
canWrite: true,
|
||||
canDelete: true,
|
||||
canAdmin: false,
|
||||
...overrides,
|
||||
});
|
||||
if (vm.status !== "ready" || !vm.data) throw new Error("fixture VM not ready");
|
||||
return vm.data;
|
||||
}
|
||||
|
||||
describe("FileDetailPage (interim-UI)", () => {
|
||||
it("renders the detail surface, download link and linked entities", () => {
|
||||
const { container, getAllByText } = render(
|
||||
<Router>
|
||||
<FileDetailPage data={detailData()} entityTypes={ENTITY_TYPES} filesHref=".." />
|
||||
</Router>,
|
||||
);
|
||||
expect(container.querySelector('[data-ui-id="ui.files.detail"]')).toBeInTheDocument();
|
||||
expect(container.querySelector('[data-ui-id="ui.files.detail.download"]')).toBeInTheDocument();
|
||||
expect(container.querySelector('[data-ui-id="ui.files.detail.links"]')).toBeInTheDocument();
|
||||
expect(container.querySelector('[data-link-id="contact-c1"]')).toBeInTheDocument();
|
||||
// displayName appears in both the breadcrumb and the header.
|
||||
expect(getAllByText("vertrag.pdf").length).toBeGreaterThan(0);
|
||||
});
|
||||
|
||||
it("shows the scan notice (fail-closed) for infected files", () => {
|
||||
const { container } = render(
|
||||
<Router>
|
||||
<FileDetailPage data={detailData({ scanStatus: "infected" })} entityTypes={ENTITY_TYPES} filesHref=".." />
|
||||
</Router>,
|
||||
);
|
||||
expect(container.querySelector('[data-ui-id="ui.files.detail.scanNotice"]')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("renders the tag editor (updateMeta form, pre-filled) when the user can write", () => {
|
||||
const { container } = render(
|
||||
<Router>
|
||||
<FileDetailPage data={detailData()} entityTypes={ENTITY_TYPES} filesHref=".." />
|
||||
</Router>,
|
||||
);
|
||||
const form = container.querySelector('[data-ui-id="ui.files.detail.tags.edit"]');
|
||||
expect(form).toBeInTheDocument();
|
||||
expect(form?.querySelector('input[type="hidden"][name="intent"][value="updateMeta"]')).toBeInTheDocument();
|
||||
const input = form?.querySelector('input[name="tags"]') as HTMLInputElement | null;
|
||||
expect(input?.value).toBe("wichtig");
|
||||
});
|
||||
|
||||
it("hides the tag editor for read-only users", () => {
|
||||
const { container } = render(
|
||||
<Router>
|
||||
<FileDetailPage data={detailData({ canWrite: false })} entityTypes={ENTITY_TYPES} filesHref=".." />
|
||||
</Router>,
|
||||
);
|
||||
expect(container.querySelector('[data-ui-id="ui.files.detail.tags.edit"]')).not.toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
+254
@@ -0,0 +1,254 @@
|
||||
// AK-P4a Interim-UI (AD-28) — File detail preview screen composed from ~/ui.
|
||||
// Presentational: renders the unwrapped FileDetailData; mutations stay server-driven
|
||||
// (<form method="post"> + intent, exactly like the baseline route action). Modals are
|
||||
// real ~/ui Dialogs (David standard), not Card fakes. No useLoaderData / server imports.
|
||||
|
||||
import { useState } from "react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { FeatherArchive, FeatherDownload, FeatherLink, FeatherRefreshCw, FeatherTrash2, FeatherX } from "@subframe/core";
|
||||
import type { FileDetailData } from "@hivegrid/view-models";
|
||||
import { Alert } from "~/ui/components/Alert";
|
||||
import { Breadcrumbs } from "~/ui/components/Breadcrumbs";
|
||||
import { Button } from "~/ui/components/Button";
|
||||
import { Card } from "~/ui/components/Card";
|
||||
import { Dialog } from "~/ui/components/Dialog";
|
||||
import { IconButton } from "~/ui/components/IconButton";
|
||||
import { Select } from "~/ui/components/Select";
|
||||
import { Tag_Label } from "~/ui/components/Tag_Label";
|
||||
import { TextInput } from "~/ui/components/TextInput";
|
||||
|
||||
export type FileDetailPageProps = {
|
||||
data: FileDetailData;
|
||||
/** Allowed polymorphic entity types for the add-link form. */
|
||||
entityTypes: readonly string[];
|
||||
/** Href back to the files browser (breadcrumb). */
|
||||
filesHref: string;
|
||||
};
|
||||
|
||||
function formatBytes(bytes: number): string {
|
||||
if (bytes < 1024) return `${bytes} B`;
|
||||
const units = ["KB", "MB", "GB"];
|
||||
let value = bytes / 1024;
|
||||
let unitIndex = 0;
|
||||
while (value >= 1024 && unitIndex < units.length - 1) {
|
||||
value /= 1024;
|
||||
unitIndex += 1;
|
||||
}
|
||||
return `${value.toFixed(1)} ${units[unitIndex]}`;
|
||||
}
|
||||
|
||||
function MetaRow({ label, value }: { label: string; value: string }) {
|
||||
return (
|
||||
<div className="flex flex-col gap-1">
|
||||
<span className="text-body-small-medium-0 font-body-small-medium-0 text-text-neutral-tertiary">{label}</span>
|
||||
<span className="text-body-default-regular-0 font-body-default-regular-0 text-text-neutral-primary">{value}</span>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export function FileDetailPage({ data, entityTypes, filesHref }: FileDetailPageProps) {
|
||||
const { t, i18n } = useTranslation();
|
||||
const [addLinkOpen, setAddLinkOpen] = useState(false);
|
||||
const [deleteOpen, setDeleteOpen] = useState(false);
|
||||
const dateFormatter = new Intl.DateTimeFormat(i18n.language, { dateStyle: "medium" });
|
||||
|
||||
return (
|
||||
<div className="flex w-full max-w-[960px] flex-col gap-6 p-6" data-ui-id="ui.files.detail">
|
||||
<Breadcrumbs>
|
||||
<a href={filesHref} className="no-underline">
|
||||
<Breadcrumbs.Item>{t("files.nav.title")}</Breadcrumbs.Item>
|
||||
</a>
|
||||
<Breadcrumbs.Divider />
|
||||
<Breadcrumbs.Item active>{data.displayName}</Breadcrumbs.Item>
|
||||
</Breadcrumbs>
|
||||
|
||||
{/* Header + action bar */}
|
||||
<div className="flex flex-wrap items-start justify-between gap-4">
|
||||
<div className="flex flex-col gap-1">
|
||||
<span className="text-heading-2 font-heading-2 text-text-neutral-primary">{data.displayName}</span>
|
||||
<span className="text-body-small-regular-0 font-body-small-regular-0 text-text-neutral-tertiary">
|
||||
{data.mimeType} · {dateFormatter.format(new Date(data.createdAtIso))}
|
||||
</span>
|
||||
</div>
|
||||
<div className="flex flex-wrap items-center gap-2">
|
||||
<a href={data.downloadUrl} className="no-underline" data-ui-id="ui.files.detail.download">
|
||||
<Button variant="tertiary" icon={<FeatherDownload />}>
|
||||
{t("files.detail.actions.download")}
|
||||
</Button>
|
||||
</a>
|
||||
{data.canWrite && data.canRegeneratePreview ? (
|
||||
<form method="post">
|
||||
<Button type="submit" name="intent" value="regeneratePreview" variant="tertiary" icon={<FeatherRefreshCw />}>
|
||||
{t("files.detail.actions.regeneratePreview")}
|
||||
</Button>
|
||||
</form>
|
||||
) : null}
|
||||
{data.canWrite ? (
|
||||
<form method="post">
|
||||
<Button type="submit" name="intent" value="archive" variant="tertiary" icon={<FeatherArchive />} data-ui-id="ui.files.detail.archive">
|
||||
{t("files.detail.actions.archive")}
|
||||
</Button>
|
||||
</form>
|
||||
) : null}
|
||||
{data.canDelete ? (
|
||||
<Button type="button" variant="destructive" icon={<FeatherTrash2 />} onClick={() => setDeleteOpen(true)} data-ui-id="ui.files.detail.delete">
|
||||
{t("files.detail.actions.delete")}
|
||||
</Button>
|
||||
) : null}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{data.scanNoticeKey ? (
|
||||
<div data-ui-id="ui.files.detail.scanNotice">
|
||||
<Alert variant={data.scanStatus === "infected" ? "error" : "warning"} description={t(data.scanNoticeKey)} notDismissible />
|
||||
</div>
|
||||
) : null}
|
||||
|
||||
{/* Preview */}
|
||||
<div data-ui-id="ui.files.detail.preview">
|
||||
{data.previewUrl ? (
|
||||
<div className="flex w-full items-center justify-center overflow-hidden rounded-md border border-solid border-border-default bg-surface-neutral-tertiary p-4">
|
||||
<img src={data.previewUrl} alt={data.displayName} className="max-h-96 w-auto rounded-sm object-contain" />
|
||||
</div>
|
||||
) : data.previewFallbackKey ? (
|
||||
<Alert variant="neutral" description={t(data.previewFallbackKey)} notDismissible />
|
||||
) : null}
|
||||
</div>
|
||||
|
||||
{/* Metadata */}
|
||||
<Card>
|
||||
<span className="text-body-default-medium-0 font-body-default-medium-0 text-text-neutral-primary">{t("files.detail.section.metadata")}</span>
|
||||
<div className="grid w-full grid-cols-1 gap-4 sm:grid-cols-2">
|
||||
<MetaRow label={t("files.detail.meta.type")} value={data.mimeType} />
|
||||
<MetaRow label={t("files.detail.meta.size")} value={formatBytes(data.sizeBytes)} />
|
||||
<MetaRow label={t("files.detail.meta.created")} value={dateFormatter.format(new Date(data.createdAtIso))} />
|
||||
<MetaRow label={t("files.detail.meta.source")} value={data.source} />
|
||||
</div>
|
||||
{data.notes ? (
|
||||
<div className="flex flex-col gap-1">
|
||||
<span className="text-body-small-medium-0 font-body-small-medium-0 text-text-neutral-tertiary">{t("files.detail.section.notes")}</span>
|
||||
<span className="whitespace-pre-wrap text-body-default-regular-0 font-body-default-regular-0 text-text-neutral-primary">{data.notes}</span>
|
||||
</div>
|
||||
) : null}
|
||||
</Card>
|
||||
|
||||
{/* Tags */}
|
||||
{data.tags.length > 0 || data.canWrite ? (
|
||||
<div className="flex flex-col gap-2" data-ui-id="ui.files.detail.tags">
|
||||
<span className="text-body-small-medium-0 font-body-small-medium-0 text-text-neutral-tertiary">{t("files.detail.section.tags")}</span>
|
||||
{data.tags.length > 0 ? (
|
||||
<div className="flex flex-wrap items-center gap-1">
|
||||
{data.tags.map((tag) => (
|
||||
<Tag_Label key={tag} tone="neutral-subtle" size="small" noAction>
|
||||
{tag}
|
||||
</Tag_Label>
|
||||
))}
|
||||
</div>
|
||||
) : null}
|
||||
{data.canWrite ? (
|
||||
<form method="post" className="flex flex-wrap items-end gap-2" data-ui-id="ui.files.detail.tags.edit">
|
||||
<input type="hidden" name="intent" value="updateMeta" />
|
||||
<TextInput label={t("files.detail.tags.editLabel")} showLabel className="min-w-[240px] flex-1">
|
||||
<TextInput.Input name="tags" defaultValue={data.tags.join(", ")} placeholder={t("files.detail.tags.placeholder")} />
|
||||
</TextInput>
|
||||
<Button type="submit" variant="secondary">
|
||||
{t("files.detail.tags.save")}
|
||||
</Button>
|
||||
</form>
|
||||
) : null}
|
||||
</div>
|
||||
) : null}
|
||||
|
||||
{/* Linked entities */}
|
||||
<div className="flex flex-col gap-3" data-ui-id="ui.files.detail.links">
|
||||
<div className="flex items-center justify-between gap-3">
|
||||
<span className="text-body-small-medium-0 font-body-small-medium-0 text-text-neutral-tertiary">{t("files.detail.section.links")}</span>
|
||||
{data.canWrite ? (
|
||||
<Button type="button" variant="tertiary" size="small" icon={<FeatherLink />} onClick={() => setAddLinkOpen(true)}>
|
||||
{t("files.detail.actions.link")}
|
||||
</Button>
|
||||
) : null}
|
||||
</div>
|
||||
{data.linkedEntities.length > 0 ? (
|
||||
<ul className="flex flex-col gap-2">
|
||||
{data.linkedEntities.map((link) => (
|
||||
<li
|
||||
key={`${link.entityType}-${link.entityId}`}
|
||||
className="flex items-center justify-between gap-3 rounded-md border border-solid border-border-default bg-surface-neutral-primary px-3 py-2"
|
||||
data-link-id={`${link.entityType}-${link.entityId}`}
|
||||
>
|
||||
<span className="text-body-default-regular-0 font-body-default-regular-0 text-text-neutral-primary">
|
||||
{link.entityType}
|
||||
{link.linkRole ? ` · ${link.linkRole}` : ""}
|
||||
</span>
|
||||
{data.canWrite ? (
|
||||
<form method="post">
|
||||
<input type="hidden" name="intent" value="unlink" />
|
||||
<input type="hidden" name="entityType" value={link.entityType} />
|
||||
<input type="hidden" name="entityId" value={link.entityId} />
|
||||
<IconButton type="submit" variant="ghost" size="small" icon={<FeatherX />} aria-label={t("files.detail.actions.unlink")} />
|
||||
</form>
|
||||
) : null}
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
) : (
|
||||
<span className="text-body-small-regular-150 font-body-small-regular-150 text-text-neutral-tertiary">{t("files.detail.links.empty")}</span>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{/* Add-link dialog (real ~/ui Dialog, size S) */}
|
||||
<Dialog open={addLinkOpen} onOpenChange={setAddLinkOpen}>
|
||||
<Dialog.Content className="w-[560px] max-w-[90vw] p-8">
|
||||
<form method="post" className="flex w-full flex-col gap-6" data-ui-id="ui.files.detail.linkForm">
|
||||
<input type="hidden" name="intent" value="link" />
|
||||
<span className="text-heading-3 font-heading-3 text-text-neutral-primary">{t("files.detail.addLink.title")}</span>
|
||||
<div className="flex flex-col gap-4">
|
||||
<Select name="entityType" label={t("files.detail.link.entityType")} showLabel defaultValue={entityTypes[0]}>
|
||||
{entityTypes.map((type) => (
|
||||
<Select.Item key={type} value={type}>
|
||||
{type}
|
||||
</Select.Item>
|
||||
))}
|
||||
</Select>
|
||||
<TextInput label={t("files.detail.link.entityId")} showLabel>
|
||||
<TextInput.Input name="entityId" required />
|
||||
</TextInput>
|
||||
<TextInput label={t("files.detail.link.role")} showLabel>
|
||||
<TextInput.Input name="linkRole" />
|
||||
</TextInput>
|
||||
</div>
|
||||
<div className="flex items-center justify-end gap-2">
|
||||
<Button type="button" variant="tertiary" onClick={() => setAddLinkOpen(false)}>
|
||||
{t("files.detail.dialog.cancel")}
|
||||
</Button>
|
||||
<Button type="submit">{t("files.detail.actions.link")}</Button>
|
||||
</div>
|
||||
</form>
|
||||
</Dialog.Content>
|
||||
</Dialog>
|
||||
|
||||
{/* Delete confirmation dialog (real ~/ui Dialog, size XS) */}
|
||||
<Dialog open={deleteOpen} onOpenChange={setDeleteOpen}>
|
||||
<Dialog.Content className="w-[420px] max-w-[90vw] p-8">
|
||||
<div className="flex w-full flex-col gap-6">
|
||||
<div className="flex flex-col gap-2">
|
||||
<span className="text-heading-3 font-heading-3 text-text-neutral-primary">{t("files.detail.delete.title")}</span>
|
||||
<span className="text-body-default-regular-150 font-body-default-regular-150 text-text-neutral-secondary">{t("files.detail.delete.body")}</span>
|
||||
</div>
|
||||
<div className="flex items-center justify-end gap-2">
|
||||
<Button type="button" variant="tertiary" onClick={() => setDeleteOpen(false)}>
|
||||
{t("files.detail.dialog.cancel")}
|
||||
</Button>
|
||||
<form method="post">
|
||||
<Button type="submit" name="intent" value="delete" variant="destructive" icon={<FeatherTrash2 />}>
|
||||
{t("files.detail.delete.confirm")}
|
||||
</Button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</Dialog.Content>
|
||||
</Dialog>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
+42
@@ -0,0 +1,42 @@
|
||||
import { vi, describe, it, expect } from "vitest";
|
||||
import "@testing-library/jest-dom";
|
||||
import { render } from "@testing-library/react";
|
||||
import { BrowserRouter as Router } from "react-router";
|
||||
import { buildFileUploadVM } from "@hivegrid/view-models";
|
||||
|
||||
import { FileUploadPage, type FileUploadDisplayItem } from "./FileUploadPage";
|
||||
|
||||
vi.mock("react-i18next", () => ({
|
||||
useTranslation: () => ({ t: (str: string) => str, i18n: { language: "de" } }),
|
||||
}));
|
||||
|
||||
describe("FileUploadPage (interim-UI)", () => {
|
||||
it("renders the dropzone + empty queue", () => {
|
||||
const vm = buildFileUploadVM({ canWrite: true });
|
||||
const { container } = render(
|
||||
<Router>
|
||||
<FileUploadPage vm={vm} items={[]} actions={{ onFiles: vi.fn() }} />
|
||||
</Router>,
|
||||
);
|
||||
expect(container.querySelector('[data-ui-id="ui.files.upload"]')).toBeInTheDocument();
|
||||
expect(container.querySelector('[data-ui-id="ui.files.upload.dropzone"]')).toBeInTheDocument();
|
||||
expect(container.querySelector('[data-ui-id="ui.files.upload.input"]')).toBeInTheDocument();
|
||||
expect(container.querySelector('[data-ui-id="ui.files.upload.queue"]')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("renders per-file queue items with status markers", () => {
|
||||
const items: FileUploadDisplayItem[] = [
|
||||
{ clientId: "a-1-2", filename: "rechnung.pdf", sizeBytes: 1024, status: "uploading", progressPercent: 40, errorKey: null },
|
||||
{ clientId: "b-3-4", filename: "kaputt.pdf", sizeBytes: 512, status: "error", progressPercent: 0, errorKey: "files.error.uploadIncomplete" },
|
||||
];
|
||||
const vm = buildFileUploadVM({ canWrite: true });
|
||||
const { container, getByText } = render(
|
||||
<Router>
|
||||
<FileUploadPage vm={vm} items={items} actions={{ onFiles: vi.fn() }} />
|
||||
</Router>,
|
||||
);
|
||||
expect(container.querySelector('[data-row-id="a-1-2"][data-status="uploading"]')).toBeInTheDocument();
|
||||
expect(container.querySelector('[data-row-id="b-3-4"][data-status="error"]')).toBeInTheDocument();
|
||||
expect(getByText("rechnung.pdf")).toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
+114
@@ -0,0 +1,114 @@
|
||||
// AK-P4a Interim-UI (AD-28) — Files upload preview screen composed from ~/ui.
|
||||
// Presentational: the chunked upload pipeline + queue state live in the route and are
|
||||
// injected as `items` + `onFiles`. The dashed dropzone is a custom interactive target
|
||||
// (no i18n-able ~/ui dropzone exists — the ~/ui FileUpload component bakes in English
|
||||
// copy), everything else (Button, Progress, Alert) is composed from ~/ui.
|
||||
|
||||
import { useRef } from "react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { FeatherUpload } from "@subframe/core";
|
||||
import type { FileUploadVM } from "@hivegrid/view-models";
|
||||
import { Alert } from "~/ui/components/Alert";
|
||||
import { Button } from "~/ui/components/Button";
|
||||
import { Progress } from "~/ui/components/Progress";
|
||||
|
||||
export type FileUploadDisplayItem = {
|
||||
clientId: string;
|
||||
filename: string;
|
||||
sizeBytes: number;
|
||||
status: "queued" | "uploading" | "processing" | "done" | "error";
|
||||
progressPercent: number;
|
||||
errorKey: string | null;
|
||||
};
|
||||
|
||||
export type FileUploadActions = {
|
||||
onFiles: (files: FileList | null) => void;
|
||||
};
|
||||
|
||||
export type FileUploadPageProps = {
|
||||
vm: FileUploadVM;
|
||||
items: readonly FileUploadDisplayItem[];
|
||||
actions: FileUploadActions;
|
||||
};
|
||||
|
||||
function progressState(status: FileUploadDisplayItem["status"]): "uploading" | "success" | "error" {
|
||||
if (status === "done") return "success";
|
||||
if (status === "error") return "error";
|
||||
return "uploading";
|
||||
}
|
||||
|
||||
export function FileUploadPage({ vm, items, actions }: FileUploadPageProps) {
|
||||
const { t } = useTranslation();
|
||||
const inputRef = useRef<HTMLInputElement>(null);
|
||||
|
||||
if (vm.status !== "ready" || !vm.data) {
|
||||
return <div className="flex w-full flex-col gap-6 p-6" data-ui-id="ui.files.upload" />;
|
||||
}
|
||||
|
||||
const { dropzoneHeadlineKey, dropzoneBodyKey, heicNoticeKey } = vm.data;
|
||||
|
||||
function statusText(item: FileUploadDisplayItem): string {
|
||||
if (item.status === "error") return t(item.errorKey ?? "files.error.uploadIncomplete");
|
||||
if (item.status === "done") return t("files.upload.status.done");
|
||||
if (item.status === "processing") return t("files.upload.status.processing");
|
||||
if (item.status === "queued") return t("files.upload.status.queued");
|
||||
return `${item.progressPercent}%`;
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="flex w-full max-w-[720px] flex-col gap-6 p-6" data-ui-id="ui.files.upload">
|
||||
<div className="flex flex-col gap-0">
|
||||
<span className="text-heading-2 font-heading-2 text-text-neutral-primary">{t("files.upload.title")}</span>
|
||||
</div>
|
||||
|
||||
{/* Dropzone (custom interactive target; i18n copy from the VM) */}
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => inputRef.current?.click()}
|
||||
onDragOver={(event) => event.preventDefault()}
|
||||
onDrop={(event) => {
|
||||
event.preventDefault();
|
||||
actions.onFiles(event.dataTransfer.files);
|
||||
}}
|
||||
className="flex w-full flex-col items-center gap-4 rounded-lg border-2 border-dashed border-border-strong bg-surface-neutral-primary px-6 py-16 hover:border-brand-brand-border-solid-hover hover:bg-surface-neutral-secondary"
|
||||
data-ui-id="ui.files.upload.dropzone"
|
||||
>
|
||||
<FeatherUpload className="text-heading-1 font-heading-1 text-icon-neutral-secondary" />
|
||||
<div className="flex flex-col items-center gap-1">
|
||||
<span className="text-body-default-medium-0 font-body-default-medium-0 text-text-neutral-primary">{t(dropzoneHeadlineKey)}</span>
|
||||
<span className="text-body-small-regular-150 font-body-small-regular-150 text-text-neutral-secondary">{t(dropzoneBodyKey)}</span>
|
||||
</div>
|
||||
<Button icon={<FeatherUpload />} variant="tertiary">
|
||||
{t("files.upload.actions.select")}
|
||||
</Button>
|
||||
</button>
|
||||
<input ref={inputRef} type="file" multiple className="hidden" onChange={(event) => actions.onFiles(event.target.files)} data-ui-id="ui.files.upload.input" />
|
||||
|
||||
<Alert variant="information" textSize="small" description={t(heicNoticeKey)} notDismissible />
|
||||
|
||||
<ul className="flex flex-col gap-4" data-ui-id="ui.files.upload.queue">
|
||||
{items.length === 0 ? (
|
||||
<li className="text-body-small-regular-150 font-body-small-regular-150 text-text-neutral-tertiary">{t("files.upload.queue.empty")}</li>
|
||||
) : (
|
||||
items.map((item) => (
|
||||
<li key={item.clientId} className="flex flex-col gap-2" data-row-id={item.clientId} data-status={item.status}>
|
||||
<div className="flex items-center justify-between gap-3">
|
||||
<span className="line-clamp-1 text-body-default-regular-0 font-body-default-regular-0 text-text-neutral-primary">{item.filename}</span>
|
||||
<span
|
||||
className={
|
||||
item.status === "error"
|
||||
? "text-body-small-regular-0 font-body-small-regular-0 text-text-feedback-negative"
|
||||
: "text-body-small-regular-0 font-body-small-regular-0 text-text-neutral-tertiary"
|
||||
}
|
||||
>
|
||||
{statusText(item)}
|
||||
</span>
|
||||
</div>
|
||||
<Progress className="w-full" value={item.progressPercent} state={progressState(item.status)} hideLabel />
|
||||
</li>
|
||||
))
|
||||
)}
|
||||
</ul>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
+119
@@ -0,0 +1,119 @@
|
||||
import { vi, describe, it, expect } from "vitest";
|
||||
import "@testing-library/jest-dom";
|
||||
import { render } from "@testing-library/react";
|
||||
import { BrowserRouter as Router } from "react-router";
|
||||
import { buildFileBrowserVM, type FileBrowserFilterOptions, type FileBrowserRow } from "@hivegrid/view-models";
|
||||
|
||||
import { FilesBrowserPage } from "./FilesBrowserPage";
|
||||
|
||||
vi.mock("react-i18next", () => ({
|
||||
useTranslation: () => ({ t: (str: string) => str, i18n: { language: "de" } }),
|
||||
}));
|
||||
|
||||
function row(overrides: Partial<FileBrowserRow> = {}): FileBrowserRow {
|
||||
return {
|
||||
id: "f1",
|
||||
displayName: "foto.heic",
|
||||
mimeType: "image/heic",
|
||||
sizeBytes: 2048,
|
||||
createdAtIso: "2026-01-02T10:00:00.000Z",
|
||||
tags: ["monteur"],
|
||||
source: "upload",
|
||||
previewStatus: "ready",
|
||||
scanStatus: "clean",
|
||||
thumbnailUrl: "/acme/media/f1/thumb",
|
||||
detailHref: "/acme/files/f1",
|
||||
linkedEntityLabelKey: null,
|
||||
...overrides,
|
||||
};
|
||||
}
|
||||
|
||||
const filter = { entityType: null, mimeGroup: null, tags: [], assignedToUserId: null, includeArchived: false };
|
||||
|
||||
// Shared defaults for the props added by extended filters + bulk-ZIP selection.
|
||||
function baseProps(selectedIds: string[] = []) {
|
||||
return {
|
||||
uploadHref: "upload",
|
||||
nextHref: null,
|
||||
bulkZipAction: "/acme/files/bulk-zip",
|
||||
selectedIds,
|
||||
actions: { onApply: vi.fn(), onToggleSelect: vi.fn(), onToggleSelectAll: vi.fn() },
|
||||
};
|
||||
}
|
||||
|
||||
describe("FilesBrowserPage (interim-UI)", () => {
|
||||
it("renders the browser surface + table rows from the VM", () => {
|
||||
const vm = buildFileBrowserVM({ rows: [row()], filter, canWrite: true, canDelete: false });
|
||||
const { container, getByText } = render(
|
||||
<Router>
|
||||
<FilesBrowserPage vm={vm} {...baseProps()} />
|
||||
</Router>,
|
||||
);
|
||||
expect(container.querySelector('[data-ui-id="ui.files.browser"]')).toBeInTheDocument();
|
||||
expect(container.querySelector('[data-ui-id="ui.files.browser.table"]')).toBeInTheDocument();
|
||||
expect(container.querySelector('[data-row-id="f1"]')).toBeInTheDocument();
|
||||
expect(getByText("foto.heic")).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("shows the empty state when there are no rows", () => {
|
||||
const vm = buildFileBrowserVM({ rows: [], filter, canWrite: true, canDelete: false });
|
||||
const { container } = render(
|
||||
<Router>
|
||||
<FilesBrowserPage vm={vm} {...baseProps()} />
|
||||
</Router>,
|
||||
);
|
||||
expect(container.querySelector('[data-ui-id="ui.files.browser.empty"]')).toBeInTheDocument();
|
||||
expect(container.querySelector('[data-ui-id="ui.files.browser.table"]')).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("renders the grid view when viewMode=grid", () => {
|
||||
const vm = buildFileBrowserVM({ viewMode: "grid", rows: [row()], filter, canWrite: true, canDelete: false });
|
||||
const { container } = render(
|
||||
<Router>
|
||||
<FilesBrowserPage vm={vm} {...baseProps()} />
|
||||
</Router>,
|
||||
);
|
||||
expect(container.querySelector('[data-ui-id="ui.files.browser.grid"]')).toBeInTheDocument();
|
||||
expect(container.querySelector('[data-ui-id="ui.files.browser.table"]')).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("renders the entity/tag/assignee filter selects when options are present", () => {
|
||||
const filterOptions: FileBrowserFilterOptions = {
|
||||
entityTypes: ["contact", "project"],
|
||||
tags: ["monteur", "rechnung"],
|
||||
assignees: [{ id: "u1", name: "Alex Meier" }],
|
||||
};
|
||||
const vm = buildFileBrowserVM({ rows: [row()], filter, filterOptions, canWrite: true, canDelete: false });
|
||||
const { getByText } = render(
|
||||
<Router>
|
||||
<FilesBrowserPage vm={vm} {...baseProps()} />
|
||||
</Router>,
|
||||
);
|
||||
expect(getByText("files.browser.filter.entity.label")).toBeInTheDocument();
|
||||
expect(getByText("files.browser.filter.tag.label")).toBeInTheDocument();
|
||||
expect(getByText("files.browser.filter.assignee.label")).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("shows the bulk-ZIP bar (posting to the action URL) when rows are selected", () => {
|
||||
const vm = buildFileBrowserVM({ rows: [row()], filter, canWrite: true, canDelete: false });
|
||||
const { container } = render(
|
||||
<Router>
|
||||
<FilesBrowserPage vm={vm} {...baseProps(["f1"])} />
|
||||
</Router>,
|
||||
);
|
||||
const bar = container.querySelector('[data-ui-id="ui.files.browser.bulkbar"]');
|
||||
expect(bar).toBeInTheDocument();
|
||||
expect(bar?.getAttribute("action")).toBe("/acme/files/bulk-zip");
|
||||
expect(container.querySelector('input[type="hidden"][name="fileIds"][value="f1"]')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("hides the bulk-ZIP bar when nothing is selected", () => {
|
||||
const vm = buildFileBrowserVM({ rows: [row()], filter, canWrite: true, canDelete: false });
|
||||
const { container } = render(
|
||||
<Router>
|
||||
<FilesBrowserPage vm={vm} {...baseProps([])} />
|
||||
</Router>,
|
||||
);
|
||||
expect(container.querySelector('[data-ui-id="ui.files.browser.bulkbar"]')).not.toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
+408
@@ -0,0 +1,408 @@
|
||||
// AK-P4a Interim-UI (AD-28) — Files browser preview screen composed from ~/ui.
|
||||
// Pure presentational component: renders the server-built FileBrowserVM passed as
|
||||
// a prop and reports filter/view changes through injected actions. No useLoaderData,
|
||||
// no server imports. The final Subframe optics land as a tracked design-nachzug once
|
||||
// David's D-P4 delta ships; this interim screen keeps the VM/loader boundary stable.
|
||||
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { FeatherDownload, FeatherFile, FeatherGrid, FeatherList, FeatherUpload } from "@subframe/core";
|
||||
import type { FileBrowserRow, FileBrowserVM, FilePreviewStatus, FileScanStatus, FileViewMode } 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 { Select } from "~/ui/components/Select";
|
||||
import { Table } from "~/ui/components/Table";
|
||||
import { Tag_Label } from "~/ui/components/Tag_Label";
|
||||
import { ToggleGroup } from "~/ui/components/ToggleGroup";
|
||||
|
||||
export type FilesBrowserQuery = {
|
||||
mimeGroup: string | null;
|
||||
entityType: string | null;
|
||||
tag: string | null;
|
||||
assignedToUserId: string | null;
|
||||
includeArchived: boolean;
|
||||
viewMode: FileViewMode;
|
||||
};
|
||||
|
||||
export type FilesBrowserActions = {
|
||||
/** Navigate (GET) to the same route with the given filter/view state. */
|
||||
onApply: (query: FilesBrowserQuery) => void;
|
||||
/** Toggle a single row in the bulk selection. */
|
||||
onToggleSelect: (id: string) => void;
|
||||
/** Select or clear all currently-listed rows. */
|
||||
onToggleSelectAll: (ids: readonly string[], selectAll: boolean) => void;
|
||||
};
|
||||
|
||||
export type FilesBrowserPageProps = {
|
||||
vm: FileBrowserVM;
|
||||
uploadHref: string;
|
||||
/** Href for the next cursor page, or null on the last page. */
|
||||
nextHref: string | null;
|
||||
/** Absolute action URL the bulk-ZIP form POSTs to. */
|
||||
bulkZipAction: string;
|
||||
/** Currently selected row ids (for the bulk-ZIP download). */
|
||||
selectedIds: readonly string[];
|
||||
actions: FilesBrowserActions;
|
||||
};
|
||||
|
||||
const MIME_ALL = "all";
|
||||
// Shared "no filter" sentinel for the entity/tag/assignee Selects (empty string
|
||||
// is not a valid Select value, so a non-empty sentinel maps back to null).
|
||||
const FILTER_ALL = "__all__";
|
||||
|
||||
type StatusBadge = { farbe: "subtle-positive" | "subtle-warning" | "subtle-negative" | "subtle-neutral"; key: string };
|
||||
|
||||
function previewBadge(status: FilePreviewStatus): StatusBadge {
|
||||
switch (status) {
|
||||
case "ready":
|
||||
return { farbe: "subtle-positive", key: "files.browser.status.preview.ready" };
|
||||
case "generating":
|
||||
return { farbe: "subtle-warning", key: "files.browser.status.preview.generating" };
|
||||
case "failed":
|
||||
return { farbe: "subtle-negative", key: "files.browser.status.preview.failed" };
|
||||
case "not_supported":
|
||||
return { farbe: "subtle-neutral", key: "files.browser.status.preview.notSupported" };
|
||||
case "pending":
|
||||
default:
|
||||
return { farbe: "subtle-warning", key: "files.browser.status.preview.pending" };
|
||||
}
|
||||
}
|
||||
|
||||
function scanBadge(status: FileScanStatus): StatusBadge | null {
|
||||
if (status === "infected") return { farbe: "subtle-negative", key: "files.browser.status.scan.infected" };
|
||||
if (status === "pending") return { farbe: "subtle-warning", key: "files.browser.status.scan.pending" };
|
||||
return null;
|
||||
}
|
||||
|
||||
function formatBytes(bytes: number): string {
|
||||
if (bytes < 1024) return `${bytes} B`;
|
||||
const units = ["KB", "MB", "GB"];
|
||||
let value = bytes / 1024;
|
||||
let unitIndex = 0;
|
||||
while (value >= 1024 && unitIndex < units.length - 1) {
|
||||
value /= 1024;
|
||||
unitIndex += 1;
|
||||
}
|
||||
return `${value.toFixed(1)} ${units[unitIndex]}`;
|
||||
}
|
||||
|
||||
export function FilesBrowserPage({ vm, uploadHref, nextHref, bulkZipAction, selectedIds, actions }: FilesBrowserPageProps) {
|
||||
const { t, i18n } = useTranslation();
|
||||
|
||||
// Loading / not-ready: keep the marker so the shell + e2e see a stable surface.
|
||||
if (vm.status !== "ready" || !vm.data) {
|
||||
return <div className="flex w-full flex-col gap-6 p-6" data-ui-id="ui.files.browser" />;
|
||||
}
|
||||
|
||||
const { rows, viewMode, filter, filterOptions, canWrite } = vm.data;
|
||||
const dateFormatter = new Intl.DateTimeFormat(i18n.language, { dateStyle: "medium" });
|
||||
|
||||
function applyPatch(patch: Partial<FilesBrowserQuery>) {
|
||||
actions.onApply({
|
||||
mimeGroup: filter.mimeGroup,
|
||||
entityType: filter.entityType,
|
||||
tag: filter.tags[0] ?? null,
|
||||
assignedToUserId: filter.assignedToUserId,
|
||||
includeArchived: filter.includeArchived,
|
||||
viewMode,
|
||||
...patch,
|
||||
});
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="flex w-full flex-col gap-6 p-6" data-ui-id="ui.files.browser">
|
||||
{/* Header: title + subtitle (0px rhythm), view toggle + upload CTA */}
|
||||
<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("files.browser.title")}</span>
|
||||
<span className="text-body-default-regular-150 font-body-default-regular-150 text-text-neutral-secondary">
|
||||
{t("files.browser.subtitle")}
|
||||
</span>
|
||||
</div>
|
||||
<div className="flex items-center gap-3">
|
||||
<ToggleGroup
|
||||
value={viewMode}
|
||||
onValueChange={(value: string) => {
|
||||
if (value === "table" || value === "grid") applyPatch({ viewMode: value });
|
||||
}}
|
||||
>
|
||||
<ToggleGroup.Item icon={<FeatherList />} value="table" aria-label={t("files.browser.viewMode.table")}>
|
||||
{t("files.browser.viewMode.table")}
|
||||
</ToggleGroup.Item>
|
||||
<ToggleGroup.Item icon={<FeatherGrid />} value="grid" aria-label={t("files.browser.viewMode.grid")}>
|
||||
{t("files.browser.viewMode.grid")}
|
||||
</ToggleGroup.Item>
|
||||
</ToggleGroup>
|
||||
{canWrite ? (
|
||||
<a href={uploadHref} className="no-underline" data-ui-id="ui.files.browser.upload">
|
||||
<Button icon={<FeatherUpload />}>{t("files.browser.actions.upload")}</Button>
|
||||
</a>
|
||||
) : null}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Filter bar (server-side, navigation on change) */}
|
||||
<div className="flex flex-wrap items-center gap-4" data-ui-id="ui.files.browser.filter">
|
||||
<Select
|
||||
className="max-w-[240px]"
|
||||
label={t("files.browser.filter.mime.label")}
|
||||
showLabel
|
||||
value={filter.mimeGroup ?? MIME_ALL}
|
||||
onValueChange={(value: string) => applyPatch({ mimeGroup: value === MIME_ALL ? null : value })}
|
||||
>
|
||||
<Select.Item value={MIME_ALL}>{t("files.browser.filter.mime.all")}</Select.Item>
|
||||
<Select.Item value="image">{t("files.browser.filter.mime.image")}</Select.Item>
|
||||
<Select.Item value="pdf">{t("files.browser.filter.mime.pdf")}</Select.Item>
|
||||
<Select.Item value="text">{t("files.browser.filter.mime.text")}</Select.Item>
|
||||
</Select>
|
||||
{filterOptions.entityTypes.length > 0 ? (
|
||||
<Select
|
||||
className="max-w-[240px]"
|
||||
label={t("files.browser.filter.entity.label")}
|
||||
showLabel
|
||||
value={filter.entityType ?? FILTER_ALL}
|
||||
onValueChange={(value: string) => applyPatch({ entityType: value === FILTER_ALL ? null : value })}
|
||||
>
|
||||
<Select.Item value={FILTER_ALL}>{t("files.browser.filter.entity.all")}</Select.Item>
|
||||
{filterOptions.entityTypes.map((type) => (
|
||||
<Select.Item key={type} value={type}>
|
||||
{t(`files.entityType.${type}`, { defaultValue: type })}
|
||||
</Select.Item>
|
||||
))}
|
||||
</Select>
|
||||
) : null}
|
||||
{filterOptions.tags.length > 0 ? (
|
||||
<Select
|
||||
className="max-w-[240px]"
|
||||
label={t("files.browser.filter.tag.label")}
|
||||
showLabel
|
||||
value={filter.tags[0] ?? FILTER_ALL}
|
||||
onValueChange={(value: string) => applyPatch({ tag: value === FILTER_ALL ? null : value })}
|
||||
>
|
||||
<Select.Item value={FILTER_ALL}>{t("files.browser.filter.tag.all")}</Select.Item>
|
||||
{filterOptions.tags.map((tag) => (
|
||||
<Select.Item key={tag} value={tag}>
|
||||
{tag}
|
||||
</Select.Item>
|
||||
))}
|
||||
</Select>
|
||||
) : null}
|
||||
{filterOptions.assignees.length > 0 ? (
|
||||
<Select
|
||||
className="max-w-[240px]"
|
||||
label={t("files.browser.filter.assignee.label")}
|
||||
showLabel
|
||||
value={filter.assignedToUserId ?? FILTER_ALL}
|
||||
onValueChange={(value: string) => applyPatch({ assignedToUserId: value === FILTER_ALL ? null : value })}
|
||||
>
|
||||
<Select.Item value={FILTER_ALL}>{t("files.browser.filter.assignee.all")}</Select.Item>
|
||||
{filterOptions.assignees.map((assignee) => (
|
||||
<Select.Item key={assignee.id} value={assignee.id}>
|
||||
{assignee.name}
|
||||
</Select.Item>
|
||||
))}
|
||||
</Select>
|
||||
) : null}
|
||||
<Checkbox
|
||||
label={t("files.browser.filter.archived")}
|
||||
checked={filter.includeArchived}
|
||||
onCheckedChange={(checked: boolean) => applyPatch({ includeArchived: checked })}
|
||||
/>
|
||||
</div>
|
||||
|
||||
{rows.length > 0 && viewMode === "table" && selectedIds.length > 0 ? (
|
||||
<form
|
||||
method="post"
|
||||
action={bulkZipAction}
|
||||
className="flex flex-wrap items-center gap-3 rounded-md border border-solid border-border-default bg-surface-neutral-secondary px-4 py-3"
|
||||
data-ui-id="ui.files.browser.bulkbar"
|
||||
>
|
||||
{selectedIds.map((id) => (
|
||||
<input key={id} type="hidden" name="fileIds" value={id} />
|
||||
))}
|
||||
<span className="text-body-default-medium-0 font-body-default-medium-0 text-text-neutral-primary">
|
||||
{t("files.browser.bulk.selected", { count: selectedIds.length })}
|
||||
</span>
|
||||
<Button type="submit" variant="secondary" icon={<FeatherDownload />}>
|
||||
{t("files.browser.bulk.downloadZip")}
|
||||
</Button>
|
||||
</form>
|
||||
) : null}
|
||||
|
||||
{rows.length === 0 ? (
|
||||
<EmptyBrowser canWrite={canWrite} uploadHref={uploadHref} vm={vm} />
|
||||
) : viewMode === "grid" ? (
|
||||
<GridView rows={rows} />
|
||||
) : (
|
||||
<TableView
|
||||
rows={rows}
|
||||
dateFormatter={dateFormatter}
|
||||
selectedIds={selectedIds}
|
||||
onToggleSelect={actions.onToggleSelect}
|
||||
onToggleSelectAll={actions.onToggleSelectAll}
|
||||
/>
|
||||
)}
|
||||
|
||||
{nextHref ? (
|
||||
<div className="flex justify-center pt-2" data-ui-id="ui.files.browser.pagination">
|
||||
<a href={nextHref} className="no-underline">
|
||||
<Button variant="tertiary">{t("files.browser.pagination.next")}</Button>
|
||||
</a>
|
||||
</div>
|
||||
) : null}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function StatusBadges({ row }: { row: FileBrowserRow }) {
|
||||
const { t } = useTranslation();
|
||||
const preview = previewBadge(row.previewStatus);
|
||||
const scan = scanBadge(row.scanStatus);
|
||||
return (
|
||||
<div className="flex flex-wrap items-center gap-1">
|
||||
{scan ? (
|
||||
<BadgeFeedback farbe={scan.farbe} size="small">
|
||||
{t(scan.key)}
|
||||
</BadgeFeedback>
|
||||
) : null}
|
||||
<BadgeFeedback farbe={preview.farbe} size="small">
|
||||
{t(preview.key)}
|
||||
</BadgeFeedback>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function RowTags({ tags }: { tags: readonly string[] }) {
|
||||
if (tags.length === 0) return null;
|
||||
return (
|
||||
<div className="flex flex-wrap items-center gap-1">
|
||||
{tags.map((tag) => (
|
||||
<Tag_Label key={tag} tone="neutral-subtle" size="small" noAction>
|
||||
{tag}
|
||||
</Tag_Label>
|
||||
))}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function TableView({
|
||||
rows,
|
||||
dateFormatter,
|
||||
selectedIds,
|
||||
onToggleSelect,
|
||||
onToggleSelectAll,
|
||||
}: {
|
||||
rows: readonly FileBrowserRow[];
|
||||
dateFormatter: Intl.DateTimeFormat;
|
||||
selectedIds: readonly string[];
|
||||
onToggleSelect: (id: string) => void;
|
||||
onToggleSelectAll: (ids: readonly string[], selectAll: boolean) => void;
|
||||
}) {
|
||||
const { t } = useTranslation();
|
||||
const selectedSet = new Set(selectedIds);
|
||||
const allIds = rows.map((row) => row.id);
|
||||
const allSelected = allIds.length > 0 && allIds.every((id) => selectedSet.has(id));
|
||||
return (
|
||||
<div className="w-full overflow-x-auto" data-ui-id="ui.files.browser.table">
|
||||
<Table
|
||||
header={
|
||||
<Table.HeaderRow>
|
||||
<Table.HeaderCell>
|
||||
<Checkbox
|
||||
aria-label={t("files.browser.select.all")}
|
||||
checked={allSelected}
|
||||
onCheckedChange={(checked: boolean) => onToggleSelectAll(allIds, checked)}
|
||||
/>
|
||||
</Table.HeaderCell>
|
||||
<Table.HeaderCell>{t("files.browser.column.name")}</Table.HeaderCell>
|
||||
<Table.HeaderCell>{t("files.browser.column.type")}</Table.HeaderCell>
|
||||
<Table.HeaderCell>{t("files.browser.column.size")}</Table.HeaderCell>
|
||||
<Table.HeaderCell>{t("files.browser.column.date")}</Table.HeaderCell>
|
||||
<Table.HeaderCell>{t("files.browser.column.status")}</Table.HeaderCell>
|
||||
<Table.HeaderCell>{t("files.browser.column.tags")}</Table.HeaderCell>
|
||||
</Table.HeaderRow>
|
||||
}
|
||||
>
|
||||
{rows.map((row) => (
|
||||
<Table.Row key={row.id} data-row-id={row.id}>
|
||||
<Table.Cell>
|
||||
<Checkbox
|
||||
aria-label={t("files.browser.select.row")}
|
||||
checked={selectedSet.has(row.id)}
|
||||
onCheckedChange={() => onToggleSelect(row.id)}
|
||||
/>
|
||||
</Table.Cell>
|
||||
<Table.Cell>
|
||||
<a href={row.detailHref} className="text-body-default-medium-0 font-body-default-medium-0 text-text-feedback-link-default">
|
||||
{row.displayName}
|
||||
</a>
|
||||
</Table.Cell>
|
||||
<Table.Cell>
|
||||
<span className="text-body-default-regular-0 font-body-default-regular-0 text-text-neutral-secondary">{row.mimeType}</span>
|
||||
</Table.Cell>
|
||||
<Table.Cell>
|
||||
<span className="text-body-default-regular-0 font-body-default-regular-0 text-text-neutral-secondary">{formatBytes(row.sizeBytes)}</span>
|
||||
</Table.Cell>
|
||||
<Table.Cell>
|
||||
<span className="text-body-default-regular-0 font-body-default-regular-0 text-text-neutral-secondary">
|
||||
{dateFormatter.format(new Date(row.createdAtIso))}
|
||||
</span>
|
||||
</Table.Cell>
|
||||
<Table.Cell>
|
||||
<StatusBadges row={row} />
|
||||
</Table.Cell>
|
||||
<Table.Cell>
|
||||
<RowTags tags={row.tags} />
|
||||
</Table.Cell>
|
||||
</Table.Row>
|
||||
))}
|
||||
</Table>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function GridView({ rows }: { rows: readonly FileBrowserRow[] }) {
|
||||
return (
|
||||
<div className="grid grid-cols-1 gap-4 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4" data-ui-id="ui.files.browser.grid">
|
||||
{rows.map((row) => (
|
||||
<a key={row.id} href={row.detailHref} className="no-underline" data-row-id={row.id}>
|
||||
<Card>
|
||||
<div className="flex h-32 w-full items-center justify-center overflow-hidden rounded-md bg-surface-neutral-tertiary">
|
||||
{row.thumbnailUrl ? (
|
||||
<img src={row.thumbnailUrl} alt={row.displayName} className="h-full w-full object-cover" />
|
||||
) : (
|
||||
<FeatherFile className="text-heading-1 font-heading-1 text-icon-neutral-tertiary" />
|
||||
)}
|
||||
</div>
|
||||
<div className="flex w-full flex-col gap-2">
|
||||
<span className="line-clamp-1 text-body-default-medium-0 font-body-default-medium-0 text-text-neutral-primary">{row.displayName}</span>
|
||||
<StatusBadges row={row} />
|
||||
<RowTags tags={row.tags} />
|
||||
</div>
|
||||
</Card>
|
||||
</a>
|
||||
))}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function EmptyBrowser({ canWrite, uploadHref, vm }: { canWrite: boolean; uploadHref: string; vm: Extract<FileBrowserVM, { status: "ready" }> }) {
|
||||
const { t } = useTranslation();
|
||||
const headlineKey = vm.data.emptyHeadlineKey;
|
||||
const bodyKey = vm.data.emptyBodyKey;
|
||||
return (
|
||||
<div className="flex flex-col items-center gap-4 rounded-md border border-solid border-border-default bg-surface-neutral-primary px-6 py-16 text-center" data-ui-id="ui.files.browser.empty">
|
||||
<FeatherFile className="text-heading-1 font-heading-1 text-icon-neutral-tertiary" />
|
||||
<div className="flex flex-col gap-1">
|
||||
<span className="text-body-large-0 font-body-large-0 text-text-neutral-primary">{t(headlineKey)}</span>
|
||||
<span className="text-body-default-regular-150 font-body-default-regular-150 text-text-neutral-secondary">{t(bodyKey)}</span>
|
||||
</div>
|
||||
{canWrite ? (
|
||||
<a href={uploadHref} className="no-underline">
|
||||
<Button icon={<FeatherUpload />}>{t("files.browser.actions.upload")}</Button>
|
||||
</a>
|
||||
) : null}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
+161
@@ -0,0 +1,161 @@
|
||||
// AK-P17b Interim-UI (AD-28) — announcements editor (admin) composed from ~/ui
|
||||
// (D-HR "Ankündigungen verwalten", archetype A2 + A4/A5). Pure presentational:
|
||||
// create (audience, ack, pin, schedule/expiry) via a real Dialog; archive via the
|
||||
// injected action. Final Subframe optics = tracked design-nachzug.
|
||||
|
||||
import { type MouseEvent, useState } from "react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { FeatherPin, FeatherPlus } from "@subframe/core";
|
||||
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 { TextArea } from "~/ui/components/TextArea";
|
||||
import { TextInput } from "~/ui/components/TextInput";
|
||||
import { DateField } from "~/components/screens/tasks/DateField";
|
||||
|
||||
export type AdminAnnouncementRow = {
|
||||
id: string;
|
||||
title: string;
|
||||
audienceKind: string;
|
||||
requiresAck: boolean;
|
||||
pinned: boolean;
|
||||
publishedIso: string | null;
|
||||
};
|
||||
|
||||
export type HrAdminAnnouncementsActions = {
|
||||
onCreate: (input: {
|
||||
title: string;
|
||||
body: string;
|
||||
audienceKind: string;
|
||||
audienceRef: string;
|
||||
requiresAck: boolean;
|
||||
pinned: boolean;
|
||||
publishAt: string;
|
||||
expiresAt: string;
|
||||
}) => void;
|
||||
onArchive: (announcementId: string) => void;
|
||||
};
|
||||
|
||||
export type HrAdminAnnouncementsPageProps = {
|
||||
rows: readonly AdminAnnouncementRow[];
|
||||
audiences: readonly string[];
|
||||
submitting: boolean;
|
||||
actions: HrAdminAnnouncementsActions;
|
||||
};
|
||||
|
||||
const EMPTY = { title: "", body: "", audienceRef: "", requiresAck: false, pinned: false };
|
||||
|
||||
export function HrAdminAnnouncementsPage({ rows, audiences, submitting, actions }: HrAdminAnnouncementsPageProps) {
|
||||
const { t } = useTranslation();
|
||||
const [open, setOpen] = useState(false);
|
||||
const [form, setForm] = useState({ ...EMPTY, audienceKind: audiences[0] ?? "all" });
|
||||
|
||||
function submit(event: MouseEvent<HTMLButtonElement>) {
|
||||
const el = (event.currentTarget as HTMLElement).closest("[data-ui-id='ui.hr.admin.announcements.new']");
|
||||
const publishAt = el?.querySelector<HTMLInputElement>("input[name='publishAt']")?.value ?? "";
|
||||
const expiresAt = el?.querySelector<HTMLInputElement>("input[name='expiresAt']")?.value ?? "";
|
||||
if (!form.title.trim() || !form.body.trim()) return;
|
||||
actions.onCreate({ ...form, publishAt, expiresAt });
|
||||
setOpen(false);
|
||||
setForm({ ...EMPTY, audienceKind: audiences[0] ?? "all" });
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="flex w-full flex-col gap-6 p-6" data-ui-id="ui.hr.admin.announcements">
|
||||
<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.announcements.admin.title")}</span>
|
||||
<span className="text-body-default-regular-150 font-body-default-regular-150 text-text-neutral-secondary">
|
||||
{t("hr.announcements.admin.subtitle")}
|
||||
</span>
|
||||
</div>
|
||||
<Button icon={<FeatherPlus />} onClick={() => setOpen(true)} data-ui-id="ui.hr.admin.announcements.newBtn">
|
||||
{t("hr.announcements.action.create")}
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
{rows.length === 0 ? (
|
||||
<div data-ui-id="ui.hr.admin.announcements.empty">
|
||||
<EmptyState title={t("hr.announcements.admin.empty.headline")} body={t("hr.announcements.admin.empty.body")} />
|
||||
</div>
|
||||
) : (
|
||||
<div className="flex w-full flex-col gap-2" data-ui-id="ui.hr.admin.announcements.list">
|
||||
{rows.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 items-center gap-2">
|
||||
{row.pinned ? <FeatherPin className="text-body-default-regular-0 font-body-default-regular-0 text-icon-neutral-tertiary" /> : null}
|
||||
<span className="text-body-default-medium-0 font-body-default-medium-0 text-text-neutral-primary">{row.title}</span>
|
||||
<BadgeFeedback farbe="subtle-neutral" size="small">
|
||||
{t(`hr.audience.${row.audienceKind}`)}
|
||||
</BadgeFeedback>
|
||||
{row.requiresAck ? (
|
||||
<BadgeFeedback farbe="subtle-warning" size="small">
|
||||
{t("hr.announcements.ackRequired")}
|
||||
</BadgeFeedback>
|
||||
) : null}
|
||||
</div>
|
||||
<Button variant="tertiary" size="small" loading={submitting} onClick={() => actions.onArchive(row.id)}>
|
||||
{t("hr.announcements.action.archive")}
|
||||
</Button>
|
||||
</div>
|
||||
</Card>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
|
||||
<Dialog open={open} onOpenChange={setOpen}>
|
||||
<Dialog.Content className="w-full max-w-[720px] p-4" data-ui-id="ui.hr.admin.announcements.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.announcements.action.create")}</span>
|
||||
<div className="flex w-full flex-col gap-4">
|
||||
<TextInput label={t("hr.announcements.field.title")} showLabel fillContainer>
|
||||
<TextInput.Input value={form.title} onChange={(e) => setForm((s) => ({ ...s, title: e.target.value }))} />
|
||||
</TextInput>
|
||||
<TextArea label={t("hr.announcements.field.body")} showLabel className="w-full">
|
||||
<TextArea.Input value={form.body} onChange={(e) => setForm((s) => ({ ...s, body: e.target.value }))} />
|
||||
</TextArea>
|
||||
<div className="flex flex-wrap gap-4">
|
||||
<Select
|
||||
label={t("hr.announcements.field.audience")}
|
||||
showLabel
|
||||
value={form.audienceKind}
|
||||
onValueChange={(value: string) => setForm((s) => ({ ...s, audienceKind: value }))}
|
||||
>
|
||||
{audiences.map((a) => (
|
||||
<Select.Item key={a} value={a}>
|
||||
{t(`hr.audience.${a}`)}
|
||||
</Select.Item>
|
||||
))}
|
||||
</Select>
|
||||
<TextInput label={t("hr.announcements.field.audienceRef")} showLabel>
|
||||
<TextInput.Input value={form.audienceRef} onChange={(e) => setForm((s) => ({ ...s, audienceRef: e.target.value }))} />
|
||||
</TextInput>
|
||||
</div>
|
||||
<div className="flex flex-wrap gap-4">
|
||||
<DateField label={t("hr.announcements.field.publishAt")} name="publishAt" />
|
||||
<DateField label={t("hr.announcements.field.expiresAt")} name="expiresAt" />
|
||||
</div>
|
||||
<div className="flex flex-wrap gap-4">
|
||||
<Checkbox label={t("hr.announcements.field.requiresAck")} checked={form.requiresAck} onCheckedChange={(c: boolean) => setForm((s) => ({ ...s, requiresAck: c }))} />
|
||||
<Checkbox label={t("hr.announcements.field.pin")} checked={form.pinned} onCheckedChange={(c: boolean) => setForm((s) => ({ ...s, pinned: 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() || !form.body.trim()} onClick={submit} data-ui-id="ui.hr.admin.announcements.new.submit">
|
||||
{t("hr.announcements.action.create")}
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
</Dialog.Content>
|
||||
</Dialog>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
+94
@@ -0,0 +1,94 @@
|
||||
// AK-P17a Interim-UI (AD-28) — tenant-wide password-safe ADMIN view composed from
|
||||
// ~/ui (D-HR "Passwort-Safe-Verwaltung", archetype A2/A6). Pure presentational:
|
||||
// lists ALL tenant vaults with entry/access counts for oversight but NEVER grants
|
||||
// content access (no secret values reachable here). Archive runs through the
|
||||
// injected action. Final Subframe optics = tracked design-nachzug.
|
||||
|
||||
import { useTranslation } from "react-i18next";
|
||||
import type { AdminVaultListVM } from "@hivegrid/view-models";
|
||||
import { BadgeFeedback } from "~/ui/components/BadgeFeedback";
|
||||
import { Button } from "~/ui/components/Button";
|
||||
import { EmptyState } from "~/ui/components/EmptyState";
|
||||
import { Table } from "~/ui/components/Table";
|
||||
|
||||
export type HrAdminPasswordSafeActions = {
|
||||
onArchiveVault: (vaultId: string) => void;
|
||||
};
|
||||
|
||||
export type HrAdminPasswordSafePageProps = {
|
||||
vm: AdminVaultListVM;
|
||||
submitting: boolean;
|
||||
actions: HrAdminPasswordSafeActions;
|
||||
};
|
||||
|
||||
export function HrAdminPasswordSafePage({ vm, submitting, actions }: HrAdminPasswordSafePageProps) {
|
||||
const { t } = useTranslation();
|
||||
|
||||
if (vm.status !== "ready" || !vm.data) {
|
||||
return <div className="flex w-full flex-col gap-6 p-6" data-ui-id="ui.hr.admin.passwordSafe" />;
|
||||
}
|
||||
|
||||
const { rows, emptyHeadlineKey, emptyBodyKey } = vm.data;
|
||||
|
||||
return (
|
||||
<div className="flex w-full flex-col gap-6 p-6" data-ui-id="ui.hr.admin.passwordSafe">
|
||||
<div className="flex flex-col gap-0">
|
||||
<span className="text-heading-2 font-heading-2 text-text-neutral-primary">{t("hr.admin.passwordSafe.title")}</span>
|
||||
<span className="text-body-default-regular-150 font-body-default-regular-150 text-text-neutral-secondary">
|
||||
{t("hr.admin.passwordSafe.subtitle")}
|
||||
</span>
|
||||
</div>
|
||||
|
||||
{rows.length === 0 ? (
|
||||
<div data-ui-id="ui.hr.admin.passwordSafe.empty">
|
||||
<EmptyState title={t(emptyHeadlineKey)} body={t(emptyBodyKey)} />
|
||||
</div>
|
||||
) : (
|
||||
<div className="w-full overflow-x-auto">
|
||||
<Table
|
||||
data-ui-id="ui.hr.admin.passwordSafe.table"
|
||||
header={
|
||||
<Table.HeaderRow>
|
||||
<Table.HeaderCell>{t("hr.admin.passwordSafe.column.name")}</Table.HeaderCell>
|
||||
<Table.HeaderCell>{t("hr.admin.passwordSafe.column.entries")}</Table.HeaderCell>
|
||||
<Table.HeaderCell>{t("hr.admin.passwordSafe.column.access")}</Table.HeaderCell>
|
||||
<Table.HeaderCell>{t("hr.admin.passwordSafe.column.status")}</Table.HeaderCell>
|
||||
<Table.HeaderCell> </Table.HeaderCell>
|
||||
</Table.HeaderRow>
|
||||
}
|
||||
>
|
||||
{rows.map((row) => (
|
||||
<Table.Row key={row.id} data-row-id={row.id} data-archived={row.archived}>
|
||||
<Table.Cell>
|
||||
<a href={row.detailHref} className="text-body-default-medium-0 font-body-default-medium-0 text-text-feedback-link-default">
|
||||
{row.name}
|
||||
</a>
|
||||
</Table.Cell>
|
||||
<Table.Cell>
|
||||
<span className="text-body-default-regular-0 font-body-default-regular-0 text-text-neutral-secondary">{row.entryCount}</span>
|
||||
</Table.Cell>
|
||||
<Table.Cell>
|
||||
<span className="text-body-default-regular-0 font-body-default-regular-0 text-text-neutral-secondary">{row.accessCount}</span>
|
||||
</Table.Cell>
|
||||
<Table.Cell>
|
||||
<BadgeFeedback farbe={row.archived ? "subtle-neutral" : "subtle-positive"} size="small">
|
||||
{row.archived ? t("hr.admin.passwordSafe.status.archived") : t("hr.admin.passwordSafe.status.active")}
|
||||
</BadgeFeedback>
|
||||
</Table.Cell>
|
||||
<Table.Cell>
|
||||
{!row.archived ? (
|
||||
<div className="flex justify-end">
|
||||
<Button variant="tertiary" size="small" loading={submitting} onClick={() => actions.onArchiveVault(row.id)}>
|
||||
{t("hr.admin.passwordSafe.action.archive")}
|
||||
</Button>
|
||||
</div>
|
||||
) : null}
|
||||
</Table.Cell>
|
||||
</Table.Row>
|
||||
))}
|
||||
</Table>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
+168
@@ -0,0 +1,168 @@
|
||||
// AK-P17b Interim-UI (AD-28) — payslip administration composed from ~/ui (D-HR
|
||||
// "Lohnabrechnungen verwalten", archetype A2 + A4). Pure presentational: bulk
|
||||
// auto-match preview (hard/soft/none confidence) with a per-row confirm, plus the
|
||||
// existing-payslips list. Match/confirm run through injected actions (route owns
|
||||
// the fetcher). Final Subframe optics = tracked design-nachzug.
|
||||
|
||||
import { useState } from "react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { BadgeFeedback } from "~/ui/components/BadgeFeedback";
|
||||
import { Button } from "~/ui/components/Button";
|
||||
import { Card } from "~/ui/components/Card";
|
||||
import { EmptyState } from "~/ui/components/EmptyState";
|
||||
import { Table } from "~/ui/components/Table";
|
||||
import { TextArea } from "~/ui/components/TextArea";
|
||||
import { TextInput } from "~/ui/components/TextInput";
|
||||
|
||||
export type PayslipPreviewRow = {
|
||||
fileId: string;
|
||||
fileName: string;
|
||||
confidence: string;
|
||||
confidenceKey: string;
|
||||
confidenceTone: string;
|
||||
employeeUserId: string | null;
|
||||
employeeLabel: string | null;
|
||||
};
|
||||
|
||||
export type PayslipAdminRow = { id: string; employeeLabel: string; periodLabel: string; isRead: boolean };
|
||||
|
||||
export type HrAdminPayslipsActions = {
|
||||
onMatch: (input: { periodYear: string; periodMonth: string; files: string }) => void;
|
||||
onConfirm: (input: { fileId: string; employeeUserId: string; periodYear: string; periodMonth: string }) => void;
|
||||
};
|
||||
|
||||
export type HrAdminPayslipsPageProps = {
|
||||
rows: readonly PayslipAdminRow[];
|
||||
preview: readonly PayslipPreviewRow[];
|
||||
period: { year: string; month: string };
|
||||
submitting: boolean;
|
||||
actions: HrAdminPayslipsActions;
|
||||
};
|
||||
|
||||
function toneFarbe(tone: string): "subtle-positive" | "subtle-warning" | "subtle-neutral" {
|
||||
if (tone === "success") return "subtle-positive";
|
||||
if (tone === "warning") return "subtle-warning";
|
||||
return "subtle-neutral";
|
||||
}
|
||||
|
||||
export function HrAdminPayslipsPage({ rows, preview, period, submitting, actions }: HrAdminPayslipsPageProps) {
|
||||
const { t } = useTranslation();
|
||||
const [year, setYear] = useState("");
|
||||
const [month, setMonth] = useState("");
|
||||
const [files, setFiles] = useState("");
|
||||
const [assignees, setAssignees] = useState<Record<string, string>>({});
|
||||
|
||||
return (
|
||||
<div className="flex w-full flex-col gap-6 p-6" data-ui-id="ui.hr.admin.payslips">
|
||||
<div className="flex flex-col gap-0">
|
||||
<span className="text-heading-2 font-heading-2 text-text-neutral-primary">{t("hr.payslips.admin.title")}</span>
|
||||
<span className="text-body-default-regular-150 font-body-default-regular-150 text-text-neutral-secondary">{t("hr.payslips.admin.subtitle")}</span>
|
||||
</div>
|
||||
|
||||
{/* Bulk auto-match */}
|
||||
<Card>
|
||||
<div className="flex w-full flex-col gap-4" data-ui-id="ui.hr.admin.payslips.match">
|
||||
<div className="flex flex-wrap gap-4">
|
||||
<TextInput label={t("hr.payslips.field.year")} showLabel>
|
||||
<TextInput.Input type="number" value={year} onChange={(e) => setYear(e.target.value)} />
|
||||
</TextInput>
|
||||
<TextInput label={t("hr.payslips.field.month")} showLabel>
|
||||
<TextInput.Input type="number" value={month} onChange={(e) => setMonth(e.target.value)} />
|
||||
</TextInput>
|
||||
</div>
|
||||
<TextArea label={t("hr.payslips.field.filesHint")} showLabel className="w-full">
|
||||
<TextArea.Input value={files} onChange={(e) => setFiles(e.target.value)} />
|
||||
</TextArea>
|
||||
<div className="flex justify-end">
|
||||
<Button
|
||||
variant="secondary"
|
||||
loading={submitting}
|
||||
disabled={!year.trim() || !month.trim() || !files.trim()}
|
||||
onClick={() => actions.onMatch({ periodYear: year, periodMonth: month, files })}
|
||||
data-ui-id="ui.hr.admin.payslips.match.submit"
|
||||
>
|
||||
{t("hr.payslips.action.match")}
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
</Card>
|
||||
|
||||
{preview.length > 0 ? (
|
||||
<div className="flex w-full flex-col gap-3" data-ui-id="ui.hr.admin.payslips.preview">
|
||||
<span className="text-body-default-medium-0 font-body-default-medium-0 text-text-neutral-primary">{t("hr.payslips.match.title")}</span>
|
||||
{preview.map((row) => (
|
||||
<Card key={row.fileId} data-row-id={row.fileId} data-confidence={row.confidence}>
|
||||
<div className="flex w-full flex-col gap-3">
|
||||
<div className="flex items-center justify-between gap-3">
|
||||
<span className="text-body-default-medium-0 font-body-default-medium-0 text-text-neutral-primary">{row.fileName}</span>
|
||||
<BadgeFeedback farbe={toneFarbe(row.confidenceTone)} size="small">
|
||||
{t(row.confidenceKey)}
|
||||
</BadgeFeedback>
|
||||
</div>
|
||||
<div className="flex items-end gap-2">
|
||||
<TextInput label={t("hr.payslips.field.employee")} showLabel fillContainer className="max-w-none">
|
||||
<TextInput.Input
|
||||
value={assignees[row.fileId] ?? row.employeeUserId ?? ""}
|
||||
onChange={(e) => setAssignees((s) => ({ ...s, [row.fileId]: e.target.value }))}
|
||||
/>
|
||||
</TextInput>
|
||||
<Button
|
||||
loading={submitting}
|
||||
onClick={() =>
|
||||
actions.onConfirm({
|
||||
fileId: row.fileId,
|
||||
employeeUserId: assignees[row.fileId] ?? row.employeeUserId ?? "",
|
||||
periodYear: period.year,
|
||||
periodMonth: period.month,
|
||||
})
|
||||
}
|
||||
>
|
||||
{t("hr.payslips.action.assign")}
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
</Card>
|
||||
))}
|
||||
</div>
|
||||
) : null}
|
||||
|
||||
<div className="flex w-full flex-col gap-2">
|
||||
<span className="text-body-default-medium-0 font-body-default-medium-0 text-text-neutral-primary">{t("hr.payslips.admin.existing")}</span>
|
||||
{rows.length === 0 ? (
|
||||
<div data-ui-id="ui.hr.admin.payslips.empty">
|
||||
<EmptyState title={t("hr.payslips.admin.empty.headline")} body={t("hr.payslips.admin.empty.body")} />
|
||||
</div>
|
||||
) : (
|
||||
<div className="w-full overflow-x-auto">
|
||||
<Table
|
||||
data-ui-id="ui.hr.admin.payslips.list"
|
||||
header={
|
||||
<Table.HeaderRow>
|
||||
<Table.HeaderCell>{t("hr.payslips.column.employee")}</Table.HeaderCell>
|
||||
<Table.HeaderCell>{t("hr.payslips.column.period")}</Table.HeaderCell>
|
||||
<Table.HeaderCell>{t("hr.payslips.column.status")}</Table.HeaderCell>
|
||||
</Table.HeaderRow>
|
||||
}
|
||||
>
|
||||
{rows.map((row) => (
|
||||
<Table.Row key={row.id} data-row-id={row.id}>
|
||||
<Table.Cell>
|
||||
<span className="text-body-default-regular-0 font-body-default-regular-0 text-text-neutral-primary">{row.employeeLabel}</span>
|
||||
</Table.Cell>
|
||||
<Table.Cell>
|
||||
<span className="text-body-default-regular-0 font-body-default-regular-0 text-text-neutral-secondary">{row.periodLabel}</span>
|
||||
</Table.Cell>
|
||||
<Table.Cell>
|
||||
<BadgeFeedback farbe={row.isRead ? "subtle-positive" : "subtle-warning"} size="small">
|
||||
{row.isRead ? t("hr.payslips.read") : t("hr.payslips.unread")}
|
||||
</BadgeFeedback>
|
||||
</Table.Cell>
|
||||
</Table.Row>
|
||||
))}
|
||||
</Table>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
+125
@@ -0,0 +1,125 @@
|
||||
// AK-P17b Interim-UI (AD-28) — request-template editor (admin) composed from ~/ui
|
||||
// (D-HR "Antragsvorlagen", archetype A2 + A5). Pure presentational: create via a
|
||||
// real Dialog; activate/archive via injected actions. Final Subframe optics =
|
||||
// tracked design-nachzug.
|
||||
|
||||
import { useState } from "react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { FeatherPlus } from "@subframe/core";
|
||||
import type { HrRequestKind, HrRequestTemplateListVM } 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 { TextInput } from "~/ui/components/TextInput";
|
||||
|
||||
export type HrAdminRequestTemplatesActions = {
|
||||
onCreate: (input: { requestKind: string; defaultApproverUserId: string; title: string; description: string }) => void;
|
||||
onToggle: (templateId: string, isActive: boolean) => void;
|
||||
onArchive: (templateId: string) => void;
|
||||
};
|
||||
|
||||
export type HrAdminRequestTemplatesPageProps = {
|
||||
vm: HrRequestTemplateListVM;
|
||||
kinds: readonly HrRequestKind[];
|
||||
submitting: boolean;
|
||||
actions: HrAdminRequestTemplatesActions;
|
||||
};
|
||||
|
||||
export function HrAdminRequestTemplatesPage({ vm, kinds, submitting, actions }: HrAdminRequestTemplatesPageProps) {
|
||||
const { t } = useTranslation();
|
||||
const [open, setOpen] = useState(false);
|
||||
const [form, setForm] = useState({ requestKind: kinds[0] ?? "expense", defaultApproverUserId: "", title: "", description: "" });
|
||||
const rows = vm.data?.rows ?? [];
|
||||
|
||||
function submit() {
|
||||
if (!form.title.trim()) return;
|
||||
actions.onCreate(form);
|
||||
setOpen(false);
|
||||
setForm({ requestKind: kinds[0] ?? "expense", defaultApproverUserId: "", title: "", description: "" });
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="flex w-full flex-col gap-6 p-6" data-ui-id="ui.hr.admin.requestTemplates">
|
||||
<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.templates.title")}</span>
|
||||
<span className="text-body-default-regular-150 font-body-default-regular-150 text-text-neutral-secondary">{t("hr.requests.templates.subtitle")}</span>
|
||||
</div>
|
||||
<Button icon={<FeatherPlus />} onClick={() => setOpen(true)} data-ui-id="ui.hr.admin.requestTemplates.newBtn">
|
||||
{t("hr.requests.templates.action.create")}
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
{rows.length === 0 ? (
|
||||
<div data-ui-id="ui.hr.admin.requestTemplates.empty">
|
||||
<EmptyState title={t("hr.requests.templates.empty.headline")} body={t("hr.requests.templates.empty.body")} />
|
||||
</div>
|
||||
) : (
|
||||
<div className="flex w-full flex-col gap-2" data-ui-id="ui.hr.admin.requestTemplates.list">
|
||||
{rows.map((row) => (
|
||||
<Card key={row.id} data-row-id={row.id} data-active={row.isActive}>
|
||||
<div className="flex w-full items-center justify-between gap-4">
|
||||
<div className="flex items-center gap-2">
|
||||
<span className="text-body-default-medium-0 font-body-default-medium-0 text-text-neutral-primary">{row.title}</span>
|
||||
<BadgeFeedback farbe="subtle-neutral" size="small">
|
||||
{t(row.kindLabelKey)}
|
||||
</BadgeFeedback>
|
||||
{!row.isActive ? (
|
||||
<BadgeFeedback farbe="subtle-warning" size="small">
|
||||
{t("hr.requests.templates.inactive")}
|
||||
</BadgeFeedback>
|
||||
) : null}
|
||||
</div>
|
||||
<div className="flex items-center gap-2">
|
||||
<Button variant="tertiary" size="small" loading={submitting} onClick={() => actions.onToggle(row.id, !row.isActive)}>
|
||||
{row.isActive ? t("hr.requests.templates.action.deactivate") : t("hr.requests.templates.action.activate")}
|
||||
</Button>
|
||||
<Button variant="tertiary" size="small" loading={submitting} onClick={() => actions.onArchive(row.id)}>
|
||||
{t("hr.requests.templates.action.archive")}
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
</Card>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
|
||||
<Dialog open={open} onOpenChange={setOpen}>
|
||||
<Dialog.Content className="w-full max-w-[560px] p-4" data-ui-id="ui.hr.admin.requestTemplates.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.requests.templates.action.create")}</span>
|
||||
<div className="flex w-full flex-col gap-4">
|
||||
<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.description")} showLabel fillContainer>
|
||||
<TextInput.Input value={form.description} onChange={(e) => setForm((s) => ({ ...s, description: e.target.value }))} />
|
||||
</TextInput>
|
||||
<TextInput label={t("hr.requests.field.approver")} showLabel fillContainer>
|
||||
<TextInput.Input value={form.defaultApproverUserId} onChange={(e) => setForm((s) => ({ ...s, defaultApproverUserId: e.target.value }))} />
|
||||
</TextInput>
|
||||
</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.requestTemplates.new.submit">
|
||||
{t("hr.requests.templates.action.create")}
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
</Dialog.Content>
|
||||
</Dialog>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
+170
@@ -0,0 +1,170 @@
|
||||
// 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>
|
||||
);
|
||||
}
|
||||
+146
@@ -0,0 +1,146 @@
|
||||
// AK-P17b Interim-UI (AD-28) — announcement detail composed from ~/ui (D-HR
|
||||
// "Ankündigung Detail", archetype A3). Pure presentational: markdown body,
|
||||
// reaction toggles, single-level comments, acknowledgement, and a manager
|
||||
// read-receipt table. Actions run through injected callbacks (route owns the
|
||||
// fetcher). Final Subframe optics = tracked design-nachzug.
|
||||
|
||||
import { useState } from "react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import type { HrAnnouncementDetailVM } from "@hivegrid/view-models";
|
||||
import { BadgeFeedback } from "~/ui/components/BadgeFeedback";
|
||||
import { Button } from "~/ui/components/Button";
|
||||
import { Card } from "~/ui/components/Card";
|
||||
import { Table } from "~/ui/components/Table";
|
||||
import { TextInput } from "~/ui/components/TextInput";
|
||||
|
||||
const REACTIONS = ["👍", "❤️", "🎉", "👀"] as const;
|
||||
|
||||
export type HrAnnouncementDetailActions = {
|
||||
onAck: () => void;
|
||||
onReact: (reaction: string) => void;
|
||||
onComment: (body: string) => void;
|
||||
};
|
||||
|
||||
export type HrAnnouncementDetailPageProps = {
|
||||
vm: HrAnnouncementDetailVM;
|
||||
submitting: boolean;
|
||||
actions: HrAnnouncementDetailActions;
|
||||
};
|
||||
|
||||
export function HrAnnouncementDetailPage({ vm, submitting, actions }: HrAnnouncementDetailPageProps) {
|
||||
const { t } = useTranslation();
|
||||
const [comment, setComment] = useState("");
|
||||
const data = vm.data;
|
||||
if (vm.status !== "ready" || !data) {
|
||||
return <div className="flex w-full flex-col gap-6 p-6" data-ui-id="ui.hr.announcement.detail" />;
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="flex w-full flex-col gap-6 p-6" data-ui-id="ui.hr.announcement.detail" data-row-id={data.id}>
|
||||
<div className="flex flex-col gap-0">
|
||||
<span className="text-heading-2 font-heading-2 text-text-neutral-primary">{data.title}</span>
|
||||
<span className="text-body-small-regular-0 font-body-small-regular-0 text-text-neutral-tertiary">{data.authorLabel}</span>
|
||||
</div>
|
||||
|
||||
<Card>
|
||||
<span className="whitespace-pre-wrap text-body-default-regular-150 font-body-default-regular-150 text-text-neutral-primary">
|
||||
{data.bodyMarkdown}
|
||||
</span>
|
||||
</Card>
|
||||
|
||||
{data.requiresAcknowledgement ? (
|
||||
<div data-ui-id="ui.hr.announcement.ack">
|
||||
{data.isAcknowledged ? (
|
||||
<BadgeFeedback farbe="subtle-positive" size="small">
|
||||
{t("hr.announcements.acknowledged")}
|
||||
</BadgeFeedback>
|
||||
) : (
|
||||
<Button loading={submitting} onClick={() => actions.onAck()}>
|
||||
{t("hr.announcements.action.acknowledge")}
|
||||
</Button>
|
||||
)}
|
||||
</div>
|
||||
) : null}
|
||||
|
||||
<div className="flex flex-wrap items-center gap-2" data-ui-id="ui.hr.announcement.reactions">
|
||||
{REACTIONS.map((emoji) => {
|
||||
const group = data.reactions.find((r) => r.reaction === emoji);
|
||||
return (
|
||||
<Button
|
||||
key={emoji}
|
||||
variant={group?.mine ? "secondary" : "tertiary"}
|
||||
size="small"
|
||||
onClick={() => actions.onReact(emoji)}
|
||||
>
|
||||
{`${emoji} ${group?.count ?? 0}`}
|
||||
</Button>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
|
||||
<div className="flex w-full flex-col gap-3" data-ui-id="ui.hr.announcement.comments">
|
||||
<span className="text-body-default-medium-0 font-body-default-medium-0 text-text-neutral-primary">{t("hr.announcements.comments.title")}</span>
|
||||
{data.comments.length === 0 ? (
|
||||
<span className="text-body-default-regular-150 font-body-default-regular-150 text-text-neutral-secondary">{t(data.commentEmptyKey)}</span>
|
||||
) : (
|
||||
data.comments.map((c) => (
|
||||
<Card key={c.id} data-row-id={c.id}>
|
||||
<div className="flex w-full flex-col gap-1">
|
||||
<span className="text-body-small-regular-0 font-body-small-regular-0 text-text-neutral-tertiary">{c.authorLabel}</span>
|
||||
<span className="text-body-default-regular-150 font-body-default-regular-150 text-text-neutral-primary">{c.body}</span>
|
||||
</div>
|
||||
</Card>
|
||||
))
|
||||
)}
|
||||
<div className="flex items-end gap-2">
|
||||
<TextInput label={t("hr.announcements.comments.add")} showLabel fillContainer className="max-w-none">
|
||||
<TextInput.Input value={comment} onChange={(e) => setComment(e.target.value)} placeholder={t("hr.announcements.comments.placeholder")} />
|
||||
</TextInput>
|
||||
<Button
|
||||
loading={submitting}
|
||||
disabled={comment.trim().length === 0}
|
||||
onClick={() => {
|
||||
actions.onComment(comment);
|
||||
setComment("");
|
||||
}}
|
||||
>
|
||||
{t("hr.announcements.comments.add")}
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{data.canManage && data.readReceipts.length > 0 ? (
|
||||
<div className="flex w-full flex-col gap-2" data-ui-id="ui.hr.announcement.receipts">
|
||||
<span className="text-body-default-medium-0 font-body-default-medium-0 text-text-neutral-primary">{t("hr.announcements.receipts.title")}</span>
|
||||
<div className="w-full overflow-x-auto">
|
||||
<Table
|
||||
header={
|
||||
<Table.HeaderRow>
|
||||
<Table.HeaderCell>{t("hr.announcements.receipts.user")}</Table.HeaderCell>
|
||||
<Table.HeaderCell>{t("hr.announcements.receipts.acknowledged")}</Table.HeaderCell>
|
||||
</Table.HeaderRow>
|
||||
}
|
||||
>
|
||||
{data.readReceipts.map((receipt) => (
|
||||
<Table.Row key={receipt.userLabel}>
|
||||
<Table.Cell>
|
||||
<span className="text-body-default-regular-0 font-body-default-regular-0 text-text-neutral-secondary">{receipt.userLabel}</span>
|
||||
</Table.Cell>
|
||||
<Table.Cell>
|
||||
{receipt.acknowledged ? (
|
||||
<BadgeFeedback farbe="subtle-positive" size="small">
|
||||
{t("hr.announcements.acknowledged")}
|
||||
</BadgeFeedback>
|
||||
) : (
|
||||
<span className="text-body-default-regular-0 font-body-default-regular-0 text-text-neutral-tertiary">—</span>
|
||||
)}
|
||||
</Table.Cell>
|
||||
</Table.Row>
|
||||
))}
|
||||
</Table>
|
||||
</div>
|
||||
</div>
|
||||
) : null}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
+80
@@ -0,0 +1,80 @@
|
||||
// AK-P17b Interim-UI (AD-28) — announcements feed composed from ~/ui (D-HR
|
||||
// "Ankündigungen", archetype A2). Pure presentational: pinned first, URL-driven
|
||||
// unread filter. Final Subframe optics = tracked design-nachzug.
|
||||
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { FeatherPin } from "@subframe/core";
|
||||
import type { HrAnnouncementFeedVM } from "@hivegrid/view-models";
|
||||
import { BadgeFeedback } from "~/ui/components/BadgeFeedback";
|
||||
import { Card } from "~/ui/components/Card";
|
||||
import { EmptyState } from "~/ui/components/EmptyState";
|
||||
import { LinkButton } from "~/ui/components/LinkButton";
|
||||
import { Tabs } from "~/ui/components/Tabs";
|
||||
|
||||
export type HrAnnouncementsFeedPageProps = { vm: HrAnnouncementFeedVM };
|
||||
|
||||
export function HrAnnouncementsFeedPage({ vm }: HrAnnouncementsFeedPageProps) {
|
||||
const { t } = useTranslation();
|
||||
const data = vm.data;
|
||||
if (vm.status !== "ready" || !data) {
|
||||
return <div className="flex w-full flex-col gap-6 p-6" data-ui-id="ui.hr.announcements" />;
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="flex w-full flex-col gap-6 p-6" data-ui-id="ui.hr.announcements">
|
||||
<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.announcements.title")}</span>
|
||||
<span className="text-body-default-regular-150 font-body-default-regular-150 text-text-neutral-secondary">
|
||||
{t("hr.announcements.subtitle")}
|
||||
</span>
|
||||
</div>
|
||||
{data.canManage ? (
|
||||
<a href={data.manageHref} className="contents no-underline" data-ui-id="ui.hr.announcements.manage">
|
||||
<LinkButton variant="subtle">{t("hr.announcements.action.manage")}</LinkButton>
|
||||
</a>
|
||||
) : null}
|
||||
</div>
|
||||
|
||||
<div data-ui-id="ui.hr.announcements.filter">
|
||||
<Tabs>
|
||||
<a href="?" className="contents no-underline">
|
||||
<Tabs.Item active={!data.unreadOnly}>{t("hr.announcements.filter.all")}</Tabs.Item>
|
||||
</a>
|
||||
<a href="?unread=1" className="contents no-underline">
|
||||
<Tabs.Item active={data.unreadOnly}>{t("hr.announcements.filter.unread")}</Tabs.Item>
|
||||
</a>
|
||||
</Tabs>
|
||||
</div>
|
||||
|
||||
{data.rows.length === 0 ? (
|
||||
<div data-ui-id="ui.hr.announcements.empty">
|
||||
<EmptyState title={t("hr.announcements.empty.headline")} body={t("hr.announcements.empty.body")} />
|
||||
</div>
|
||||
) : (
|
||||
<div className="flex w-full flex-col gap-3" data-ui-id="ui.hr.announcements.list">
|
||||
{data.rows.map((row) => (
|
||||
<a key={row.id} href={row.detailHref} className="no-underline" data-row-id={row.id} data-pinned={row.pinned} data-read={row.isRead}>
|
||||
<Card>
|
||||
<div className="flex w-full flex-col gap-1">
|
||||
<div className="flex items-center justify-between gap-3">
|
||||
<div className="flex items-center gap-2">
|
||||
{row.pinned ? <FeatherPin className="text-body-default-regular-0 font-body-default-regular-0 text-icon-neutral-tertiary" /> : null}
|
||||
<span className="text-body-default-medium-0 font-body-default-medium-0 text-text-neutral-primary">{row.title}</span>
|
||||
</div>
|
||||
{row.requiresAcknowledgement && !row.isAcknowledged ? (
|
||||
<BadgeFeedback farbe="subtle-warning" size="small">
|
||||
{t("hr.announcements.ackRequired")}
|
||||
</BadgeFeedback>
|
||||
) : null}
|
||||
</div>
|
||||
<span className="line-clamp-2 text-body-default-regular-150 font-body-default-regular-150 text-text-neutral-secondary">{row.snippet}</span>
|
||||
</div>
|
||||
</Card>
|
||||
</a>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
+51
@@ -0,0 +1,51 @@
|
||||
import { vi, describe, it, expect } from "vitest";
|
||||
import "@testing-library/jest-dom";
|
||||
import { render, fireEvent } from "@testing-library/react";
|
||||
|
||||
import { HrDirectoryDetailPage, type HrDirectoryDetailPageProps } from "./HrDirectoryDetailPage";
|
||||
|
||||
vi.mock("react-i18next", () => ({
|
||||
useTranslation: () => ({ t: (str: string) => str, i18n: { language: "de" } }),
|
||||
}));
|
||||
|
||||
function props(overrides: Partial<HrDirectoryDetailPageProps> = {}): HrDirectoryDetailPageProps {
|
||||
return {
|
||||
backHref: "..",
|
||||
name: "Ada Lovelace",
|
||||
email: "ada@acme.test",
|
||||
position: "Engineer",
|
||||
team: "Core",
|
||||
isSelf: true,
|
||||
canRevealEmergency: true,
|
||||
canEditEmergency: true,
|
||||
hasEmergencyContact: false,
|
||||
revealedContact: null,
|
||||
revealing: false,
|
||||
saving: false,
|
||||
savingEmergency: false,
|
||||
actions: { onSaveProfile: vi.fn(), onRevealEmergency: vi.fn(), onSetEmergency: vi.fn() },
|
||||
...overrides,
|
||||
};
|
||||
}
|
||||
|
||||
describe("HrDirectoryDetailPage (interim-UI, emergency-contact editing)", () => {
|
||||
it("lets an editor set a new emergency contact via the dialog", () => {
|
||||
const onSetEmergency = vi.fn();
|
||||
const { container } = render(<HrDirectoryDetailPage {...props({ actions: { onSaveProfile: vi.fn(), onRevealEmergency: vi.fn(), onSetEmergency } })} />);
|
||||
|
||||
// With no contact on file the edit control offers "add".
|
||||
fireEvent.click(container.querySelector('[data-ui-id="ui.hr.directory.detail.emergency.edit"]') as HTMLElement);
|
||||
// Dialog content is portalled to document.body.
|
||||
fireEvent.change(document.querySelector('[data-ui-id="ui.hr.directory.detail.emergency.dialog.name"]') as HTMLInputElement, { target: { value: " Tom Davis " } });
|
||||
fireEvent.change(document.querySelector('[data-ui-id="ui.hr.directory.detail.emergency.dialog.phone"]') as HTMLInputElement, { target: { value: "+49 172 8899001" } });
|
||||
fireEvent.change(document.querySelector('[data-ui-id="ui.hr.directory.detail.emergency.dialog.relation"]') as HTMLInputElement, { target: { value: "Ehepartner" } });
|
||||
fireEvent.click(document.querySelector('[data-ui-id="ui.hr.directory.detail.emergency.dialog.submit"]') as HTMLElement);
|
||||
|
||||
expect(onSetEmergency).toHaveBeenCalledWith({ name: "Tom Davis", phone: "+49 172 8899001", relation: "Ehepartner" });
|
||||
});
|
||||
|
||||
it("hides the emergency card entirely when the viewer can neither reveal nor edit", () => {
|
||||
const { container } = render(<HrDirectoryDetailPage {...props({ isSelf: false, canRevealEmergency: false, canEditEmergency: false })} />);
|
||||
expect(container.querySelector('[data-ui-id="ui.hr.directory.detail.emergency"]')).not.toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
+218
@@ -0,0 +1,218 @@
|
||||
// AK-P17a Interim-UI (AD-28) — employee detail screen composed from ~/ui (D-HR
|
||||
// "MA-Detail", archetype A3). Pure presentational: master data, inline self-edit
|
||||
// of the self-editable fields (position/team), and an ON-DEMAND emergency-contact
|
||||
// reveal (self or hr.read_all only, audited server-side). The route owns the
|
||||
// fetchers and injects callbacks + revealed data; this screen never fetches.
|
||||
// Final Subframe optics = tracked design-nachzug.
|
||||
|
||||
import { useState } from "react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { Breadcrumbs } from "~/ui/components/Breadcrumbs";
|
||||
import { Button } from "~/ui/components/Button";
|
||||
import { Card } from "~/ui/components/Card";
|
||||
import { Dialog } from "~/ui/components/Dialog";
|
||||
import { TextInput } from "~/ui/components/TextInput";
|
||||
|
||||
/** Decrypted emergency-contact triple (mirrors the server EmergencyContact). */
|
||||
export type RevealedEmergencyContact = { name: string; phone: string; relation: string };
|
||||
|
||||
export type HrDirectoryDetailActions = {
|
||||
/** POSTs intent=update-own-profile with the self-editable fields. */
|
||||
onSaveProfile: (input: { position: string; team: string }) => void;
|
||||
/** POSTs intent=reveal-emergency (audited). */
|
||||
onRevealEmergency: () => void;
|
||||
/** POSTs intent=set-emergency; stores the envelope-encrypted contact. */
|
||||
onSetEmergency: (input: RevealedEmergencyContact) => void;
|
||||
};
|
||||
|
||||
export type HrDirectoryDetailPageProps = {
|
||||
backHref: string;
|
||||
name: string;
|
||||
email: string;
|
||||
position: string | null;
|
||||
team: string | null;
|
||||
isSelf: boolean;
|
||||
canRevealEmergency: boolean;
|
||||
/** Self or HR with hr.write — may create/overwrite the emergency contact. */
|
||||
canEditEmergency: boolean;
|
||||
hasEmergencyContact: boolean;
|
||||
/** Populated once the reveal fetcher returns; null before reveal. */
|
||||
revealedContact: RevealedEmergencyContact | null;
|
||||
revealing: boolean;
|
||||
saving: boolean;
|
||||
savingEmergency: boolean;
|
||||
actions: HrDirectoryDetailActions;
|
||||
};
|
||||
|
||||
function DataRow({ label, value }: { label: string; value: string }) {
|
||||
return (
|
||||
<div className="flex flex-col gap-0">
|
||||
<span className="text-body-small-regular-0 font-body-small-regular-0 text-text-neutral-tertiary">{label}</span>
|
||||
<span className="text-body-default-regular-0 font-body-default-regular-0 text-text-neutral-primary">{value}</span>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export function HrDirectoryDetailPage({
|
||||
backHref,
|
||||
name,
|
||||
email,
|
||||
position,
|
||||
team,
|
||||
isSelf,
|
||||
canRevealEmergency,
|
||||
canEditEmergency,
|
||||
hasEmergencyContact,
|
||||
revealedContact,
|
||||
revealing,
|
||||
saving,
|
||||
savingEmergency,
|
||||
actions,
|
||||
}: HrDirectoryDetailPageProps) {
|
||||
const { t } = useTranslation();
|
||||
const [positionDraft, setPositionDraft] = useState(position ?? "");
|
||||
const [teamDraft, setTeamDraft] = useState(team ?? "");
|
||||
const [emergencyOpen, setEmergencyOpen] = useState(false);
|
||||
const [emergencyDraft, setEmergencyDraft] = useState<RevealedEmergencyContact>({ name: "", phone: "", relation: "" });
|
||||
|
||||
function openEmergencyDialog() {
|
||||
// Prefill from the revealed contact if the viewer has already revealed it;
|
||||
// otherwise start blank (we never auto-decrypt just to edit).
|
||||
setEmergencyDraft(revealedContact ?? { name: "", phone: "", relation: "" });
|
||||
setEmergencyOpen(true);
|
||||
}
|
||||
function submitEmergency() {
|
||||
actions.onSetEmergency({ name: emergencyDraft.name.trim(), phone: emergencyDraft.phone.trim(), relation: emergencyDraft.relation.trim() });
|
||||
setEmergencyOpen(false);
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="flex w-full flex-col gap-6 p-6" data-ui-id="ui.hr.directory.detail">
|
||||
<Breadcrumbs>
|
||||
<a href={backHref} className="contents no-underline" data-ui-id="ui.hr.directory.detail.back">
|
||||
<Breadcrumbs.Item>{t("hr.directory.detail.back")}</Breadcrumbs.Item>
|
||||
</a>
|
||||
<Breadcrumbs.Divider />
|
||||
<Breadcrumbs.Item active>{name}</Breadcrumbs.Item>
|
||||
</Breadcrumbs>
|
||||
|
||||
<div className="flex flex-col gap-0">
|
||||
<span className="text-heading-2 font-heading-2 text-text-neutral-primary">{name}</span>
|
||||
<span className="text-body-default-regular-150 font-body-default-regular-150 text-text-neutral-secondary">
|
||||
{email || "—"}
|
||||
</span>
|
||||
</div>
|
||||
|
||||
{/* Master data — self-editable fields become inputs for the employee. */}
|
||||
<Card>
|
||||
{isSelf ? (
|
||||
<div className="flex w-full flex-col gap-4" data-ui-id="ui.hr.directory.detail.edit">
|
||||
<TextInput label={t("hr.directory.column.position")} showLabel fillContainer>
|
||||
<TextInput.Input
|
||||
value={positionDraft}
|
||||
onChange={(event) => setPositionDraft(event.target.value)}
|
||||
data-ui-id="ui.hr.directory.detail.position"
|
||||
/>
|
||||
</TextInput>
|
||||
<TextInput label={t("hr.directory.column.team")} showLabel fillContainer>
|
||||
<TextInput.Input
|
||||
value={teamDraft}
|
||||
onChange={(event) => setTeamDraft(event.target.value)}
|
||||
data-ui-id="ui.hr.directory.detail.team"
|
||||
/>
|
||||
</TextInput>
|
||||
<div className="flex justify-end">
|
||||
<Button
|
||||
loading={saving}
|
||||
onClick={() => actions.onSaveProfile({ position: positionDraft, team: teamDraft })}
|
||||
data-ui-id="ui.hr.directory.detail.save"
|
||||
>
|
||||
{t("hr.directory.detail.save")}
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
) : (
|
||||
<div className="flex w-full flex-col gap-4">
|
||||
<DataRow label={t("hr.directory.column.position")} value={position ?? "—"} />
|
||||
<DataRow label={t("hr.directory.column.team")} value={team ?? "—"} />
|
||||
<DataRow label={t("hr.directory.detail.email")} value={email || "—"} />
|
||||
</div>
|
||||
)}
|
||||
</Card>
|
||||
|
||||
{/* Emergency contact — never shown automatically, revealed on demand.
|
||||
Editable by self or HR (hr.write) via the dialog. */}
|
||||
{canRevealEmergency || canEditEmergency ? (
|
||||
<Card data-ui-id="ui.hr.directory.detail.emergency">
|
||||
<div className="flex w-full items-center justify-between gap-4">
|
||||
<span className="text-body-default-medium-0 font-body-default-medium-0 text-text-neutral-primary">
|
||||
{t("hr.directory.detail.emergencyContact")}
|
||||
</span>
|
||||
{canEditEmergency ? (
|
||||
<Button variant="secondary" size="small" onClick={openEmergencyDialog} data-ui-id="ui.hr.directory.detail.emergency.edit">
|
||||
{hasEmergencyContact ? t("hr.directory.detail.emergency.edit") : t("hr.directory.detail.emergency.add")}
|
||||
</Button>
|
||||
) : null}
|
||||
</div>
|
||||
{!hasEmergencyContact ? (
|
||||
<span className="text-body-default-regular-150 font-body-default-regular-150 text-text-neutral-secondary">
|
||||
{t("hr.directory.detail.noEmergencyContact")}
|
||||
</span>
|
||||
) : !canRevealEmergency ? (
|
||||
<span className="text-body-default-regular-150 font-body-default-regular-150 text-text-neutral-secondary">
|
||||
{t("hr.directory.detail.emergency.stored")}
|
||||
</span>
|
||||
) : revealedContact ? (
|
||||
<div className="flex w-full flex-col gap-4" data-ui-id="ui.hr.directory.detail.emergency.revealed">
|
||||
<DataRow label={t("hr.directory.detail.emergency.name")} value={revealedContact.name} />
|
||||
<DataRow label={t("hr.directory.detail.emergency.phone")} value={revealedContact.phone} />
|
||||
<DataRow label={t("hr.directory.detail.emergency.relation")} value={revealedContact.relation} />
|
||||
</div>
|
||||
) : (
|
||||
<Button
|
||||
variant="secondary"
|
||||
loading={revealing}
|
||||
onClick={() => actions.onRevealEmergency()}
|
||||
data-ui-id="ui.hr.directory.detail.emergency.reveal"
|
||||
>
|
||||
{t("hr.directory.detail.reveal")}
|
||||
</Button>
|
||||
)}
|
||||
</Card>
|
||||
) : null}
|
||||
|
||||
{/* Set / overwrite emergency contact (self or HR with hr.write). */}
|
||||
<Dialog open={emergencyOpen} onOpenChange={(next) => { if (!savingEmergency) setEmergencyOpen(next); }}>
|
||||
<Dialog.Content className="w-full max-w-[560px] p-4" data-ui-id="ui.hr.directory.detail.emergency.dialog">
|
||||
<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.directory.detail.emergency.dialogTitle")}</span>
|
||||
<div className="flex w-full flex-col gap-4">
|
||||
<TextInput label={t("hr.directory.detail.emergency.name")} showLabel fillContainer>
|
||||
<TextInput.Input value={emergencyDraft.name} onChange={(e) => setEmergencyDraft((s) => ({ ...s, name: e.target.value }))} data-ui-id="ui.hr.directory.detail.emergency.dialog.name" />
|
||||
</TextInput>
|
||||
<TextInput label={t("hr.directory.detail.emergency.phone")} showLabel fillContainer>
|
||||
<TextInput.Input value={emergencyDraft.phone} onChange={(e) => setEmergencyDraft((s) => ({ ...s, phone: e.target.value }))} data-ui-id="ui.hr.directory.detail.emergency.dialog.phone" />
|
||||
</TextInput>
|
||||
<TextInput label={t("hr.directory.detail.emergency.relation")} showLabel fillContainer>
|
||||
<TextInput.Input value={emergencyDraft.relation} onChange={(e) => setEmergencyDraft((s) => ({ ...s, relation: e.target.value }))} data-ui-id="ui.hr.directory.detail.emergency.dialog.relation" />
|
||||
</TextInput>
|
||||
</div>
|
||||
<div className="flex justify-end gap-2">
|
||||
<Button variant="neutral" disabled={savingEmergency} onClick={() => setEmergencyOpen(false)}>
|
||||
{t("hr.action.cancel")}
|
||||
</Button>
|
||||
<Button
|
||||
loading={savingEmergency}
|
||||
disabled={emergencyDraft.name.trim().length === 0 || emergencyDraft.phone.trim().length === 0}
|
||||
onClick={submitEmergency}
|
||||
data-ui-id="ui.hr.directory.detail.emergency.dialog.submit"
|
||||
>
|
||||
{t("hr.directory.detail.emergency.save")}
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
</Dialog.Content>
|
||||
</Dialog>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
+42
@@ -0,0 +1,42 @@
|
||||
import { vi, describe, it, expect } from "vitest";
|
||||
import "@testing-library/jest-dom";
|
||||
import { render } from "@testing-library/react";
|
||||
import { BrowserRouter as Router } from "react-router";
|
||||
import { buildHrDirectoryVM } from "@hivegrid/view-models";
|
||||
|
||||
import { HrDirectoryPage } from "./HrDirectoryPage";
|
||||
|
||||
vi.mock("react-i18next", () => ({
|
||||
useTranslation: () => ({ t: (str: string) => str, i18n: { language: "de" } }),
|
||||
}));
|
||||
|
||||
describe("HrDirectoryPage (interim-UI)", () => {
|
||||
it("renders directory rows (non-sensitive fields only) from the VM", () => {
|
||||
const vm = buildHrDirectoryVM({
|
||||
canManage: true,
|
||||
rows: [
|
||||
{ userId: "u1", name: "Ada Lovelace", email: "ada@acme.test", position: "Engineer", team: "Core", locationName: "Berlin", detailHref: "/acme/hr/directory/u1" },
|
||||
],
|
||||
});
|
||||
const { container, getByText } = render(
|
||||
<Router>
|
||||
<HrDirectoryPage vm={vm} />
|
||||
</Router>,
|
||||
);
|
||||
expect(container.querySelector('[data-ui-id="ui.hr.directory.table"]')).toBeInTheDocument();
|
||||
expect(container.querySelector('[data-row-id="u1"]')).toBeInTheDocument();
|
||||
expect(getByText("Ada Lovelace")).toBeInTheDocument();
|
||||
expect(getByText("Engineer")).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("shows the empty state when there are no employees", () => {
|
||||
const vm = buildHrDirectoryVM({ canManage: false, rows: [] });
|
||||
const { container } = render(
|
||||
<Router>
|
||||
<HrDirectoryPage vm={vm} />
|
||||
</Router>,
|
||||
);
|
||||
expect(container.querySelector('[data-ui-id="ui.hr.directory.empty"]')).toBeInTheDocument();
|
||||
expect(container.querySelector('[data-ui-id="ui.hr.directory.table"]')).not.toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
+105
@@ -0,0 +1,105 @@
|
||||
// AK-P17a Interim-UI (AD-28) — employee directory screen composed from ~/ui
|
||||
// (D-HR "MA-Verzeichnis", archetype A2). Pure presentational: renders the
|
||||
// server-built HrDirectoryVM passed as a prop. The directory carries ONLY
|
||||
// non-sensitive display fields (emergency contacts et al. are reveal-on-demand
|
||||
// on the detail screen, never in this list). Final Subframe optics =
|
||||
// tracked design-nachzug.
|
||||
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { FeatherMail } from "@subframe/core";
|
||||
import type { HrDirectoryVM } from "@hivegrid/view-models";
|
||||
import { Avatar } from "~/ui/components/Avatar";
|
||||
import { EmptyState } from "~/ui/components/EmptyState";
|
||||
import { IconButton } from "~/ui/components/IconButton";
|
||||
import { Table } from "~/ui/components/Table";
|
||||
|
||||
export type HrDirectoryPageProps = {
|
||||
vm: HrDirectoryVM;
|
||||
};
|
||||
|
||||
function initials(name: string): string {
|
||||
const parts = name.trim().split(/\s+/).filter(Boolean);
|
||||
if (parts.length === 0) return "?";
|
||||
if (parts.length === 1) return parts[0].slice(0, 2).toUpperCase();
|
||||
return (parts[0][0] + parts[parts.length - 1][0]).toUpperCase();
|
||||
}
|
||||
|
||||
export function HrDirectoryPage({ vm }: HrDirectoryPageProps) {
|
||||
const { t } = useTranslation();
|
||||
|
||||
if (vm.status !== "ready" || !vm.data) {
|
||||
return <div className="flex w-full flex-col gap-6 p-6" data-ui-id="ui.hr.directory" />;
|
||||
}
|
||||
|
||||
const { rows, emptyHeadlineKey, emptyBodyKey } = vm.data;
|
||||
|
||||
return (
|
||||
<div className="flex w-full flex-col gap-6 p-6" data-ui-id="ui.hr.directory">
|
||||
<div className="flex flex-col gap-0">
|
||||
<span className="text-heading-2 font-heading-2 text-text-neutral-primary">{t("hr.directory.title")}</span>
|
||||
<span className="text-body-default-regular-150 font-body-default-regular-150 text-text-neutral-secondary">
|
||||
{t("hr.directory.subtitle")}
|
||||
</span>
|
||||
</div>
|
||||
|
||||
{rows.length === 0 ? (
|
||||
<div data-ui-id="ui.hr.directory.empty">
|
||||
<EmptyState title={t(emptyHeadlineKey)} body={t(emptyBodyKey)} />
|
||||
</div>
|
||||
) : (
|
||||
<div className="w-full overflow-x-auto">
|
||||
<Table
|
||||
data-ui-id="ui.hr.directory.table"
|
||||
header={
|
||||
<Table.HeaderRow>
|
||||
<Table.HeaderCell>{t("hr.directory.column.name")}</Table.HeaderCell>
|
||||
<Table.HeaderCell>{t("hr.directory.column.position")}</Table.HeaderCell>
|
||||
<Table.HeaderCell>{t("hr.directory.column.team")}</Table.HeaderCell>
|
||||
<Table.HeaderCell>{t("hr.directory.column.location")}</Table.HeaderCell>
|
||||
<Table.HeaderCell> </Table.HeaderCell>
|
||||
</Table.HeaderRow>
|
||||
}
|
||||
>
|
||||
{rows.map((row) => (
|
||||
<Table.Row key={row.userId} data-row-id={row.userId}>
|
||||
<Table.Cell>
|
||||
<div className="flex items-center gap-3">
|
||||
<Avatar size="small">{initials(row.name)}</Avatar>
|
||||
<a
|
||||
href={row.detailHref}
|
||||
className="text-body-default-medium-0 font-body-default-medium-0 text-text-feedback-link-default"
|
||||
>
|
||||
{row.name}
|
||||
</a>
|
||||
</div>
|
||||
</Table.Cell>
|
||||
<Table.Cell>
|
||||
<span className="text-body-default-regular-0 font-body-default-regular-0 text-text-neutral-secondary">
|
||||
{row.position ?? "—"}
|
||||
</span>
|
||||
</Table.Cell>
|
||||
<Table.Cell>
|
||||
<span className="text-body-default-regular-0 font-body-default-regular-0 text-text-neutral-secondary">
|
||||
{row.team ?? "—"}
|
||||
</span>
|
||||
</Table.Cell>
|
||||
<Table.Cell>
|
||||
<span className="text-body-default-regular-0 font-body-default-regular-0 text-text-neutral-secondary">
|
||||
{row.locationName ?? "—"}
|
||||
</span>
|
||||
</Table.Cell>
|
||||
<Table.Cell>
|
||||
{row.email ? (
|
||||
<a href={`mailto:${row.email}`} className="contents no-underline" aria-label={t("hr.directory.action.mail")}>
|
||||
<IconButton size="small" icon={<FeatherMail />} />
|
||||
</a>
|
||||
) : null}
|
||||
</Table.Cell>
|
||||
</Table.Row>
|
||||
))}
|
||||
</Table>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
+74
@@ -0,0 +1,74 @@
|
||||
// AK-P17a Interim-UI (AD-28) — HR hub launchpad composed from ~/ui (D-HR
|
||||
// "HR-Hub-Start", archetype A1/A6). Pure presentational: the loader gates the
|
||||
// connector + permission and passes the resolved quick-link list in as a prop;
|
||||
// this screen only renders. The richer hub widgets (announcements, pending
|
||||
// duties, birthdays) arrive with their data in follow-up tickets; the interim
|
||||
// screen renders exactly what the loader provides. Final Subframe optics = a
|
||||
// tracked design-nachzug once David's D-HR delta ships.
|
||||
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { FeatherArrowRight, FeatherLock } from "@subframe/core";
|
||||
import { Card } from "~/ui/components/Card";
|
||||
import { EmptyState } from "~/ui/components/EmptyState";
|
||||
|
||||
export type HrHubLink = {
|
||||
/** i18n key for the link label (e.g. "hr.nav.directory"). */
|
||||
readonly labelKey: string;
|
||||
readonly href: string;
|
||||
};
|
||||
|
||||
export type HrHubPageProps = {
|
||||
/** False when the tenant has the HR module gated off (locked state). */
|
||||
moduleActive: boolean;
|
||||
links: readonly HrHubLink[];
|
||||
};
|
||||
|
||||
export function HrHubPage({ moduleActive, links }: HrHubPageProps) {
|
||||
const { t } = useTranslation();
|
||||
|
||||
if (!moduleActive) {
|
||||
return (
|
||||
<div className="flex w-full flex-col gap-6 p-6" data-ui-id="ui.hr.hub">
|
||||
<div className="flex items-center gap-2 text-text-neutral-tertiary" data-ui-id="ui.hr.hub.locked">
|
||||
<FeatherLock className="text-heading-3 font-heading-3" />
|
||||
<EmptyState title={t("hr.hub.locked.headline")} body={t("hr.hub.locked.body")} />
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="flex w-full flex-col gap-6 p-6" data-ui-id="ui.hr.hub">
|
||||
{/* Header: title + description (0px rhythm) */}
|
||||
<div className="flex flex-col gap-0">
|
||||
<span className="text-heading-2 font-heading-2 text-text-neutral-primary">{t("hr.hub.title")}</span>
|
||||
<span className="text-body-default-regular-150 font-body-default-regular-150 text-text-neutral-secondary">
|
||||
{t("hr.hub.subtitle")}
|
||||
</span>
|
||||
</div>
|
||||
|
||||
<nav
|
||||
className="grid grid-cols-1 gap-4 sm:grid-cols-2 lg:grid-cols-3"
|
||||
data-ui-id="ui.hr.hub.links"
|
||||
>
|
||||
{links.map((link) => (
|
||||
<a
|
||||
key={link.labelKey}
|
||||
href={link.href}
|
||||
className="no-underline"
|
||||
data-row-id={link.labelKey}
|
||||
>
|
||||
<Card>
|
||||
<div className="flex w-full items-center justify-between gap-4">
|
||||
<span className="text-body-default-medium-0 font-body-default-medium-0 text-text-neutral-primary">
|
||||
{t(link.labelKey)}
|
||||
</span>
|
||||
<FeatherArrowRight className="text-body-default-regular-0 font-body-default-regular-0 text-icon-neutral-tertiary" />
|
||||
</div>
|
||||
</Card>
|
||||
</a>
|
||||
))}
|
||||
</nav>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
+330
@@ -0,0 +1,330 @@
|
||||
// AK-P17b Interim-UI (AD-28) — leave/vacation screen composed from ~/ui (D-HR
|
||||
// "Urlaub", archetype A2 + A4/A5). Pure presentational: URL-driven tabs (own /
|
||||
// approvals / team); new request + reply + clarify run through injected actions
|
||||
// (route owns the fetcher). Overlap conflicts surface as an inline warning. Final
|
||||
// Subframe optics = tracked design-nachzug.
|
||||
|
||||
import { useState } from "react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { FeatherPlus } from "@subframe/core";
|
||||
import type { HrLeaveApproverVM, HrLeaveOwnVM, HrVacationRequestKind } from "@hivegrid/view-models";
|
||||
import { Alert } from "~/ui/components/Alert";
|
||||
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";
|
||||
import { DateField } from "~/components/screens/tasks/DateField";
|
||||
|
||||
export type HrLeaveTab = "own" | "approvals" | "team";
|
||||
export type HrLeaveTeamAbsence = { id: string; employeeLabel: string; source: string; kind: string; startIso: string; endIso: string };
|
||||
|
||||
export type HrLeaveActions = {
|
||||
onSubmit: (input: { requestKind: string; approverUserId: string; startDate: string; endDate: string; note: string }) => void;
|
||||
onWithdraw: (requestId: string) => void;
|
||||
onReply: (requestId: string, reply: string) => void;
|
||||
onApprove: (requestId: string) => void;
|
||||
onReject: (requestId: string) => void;
|
||||
onClarify: (requestId: string, question: string) => void;
|
||||
};
|
||||
|
||||
export type HrLeavePageProps = {
|
||||
tab: HrLeaveTab;
|
||||
canApprove: boolean;
|
||||
ownVm: HrLeaveOwnVM;
|
||||
approverVm: HrLeaveApproverVM;
|
||||
team: readonly HrLeaveTeamAbsence[];
|
||||
kinds: readonly HrVacationRequestKind[];
|
||||
tabHref: (tab: HrLeaveTab) => string;
|
||||
submitting: boolean;
|
||||
actions: HrLeaveActions;
|
||||
};
|
||||
|
||||
type DialogState =
|
||||
| { type: "new" }
|
||||
| { type: "reply"; requestId: string }
|
||||
| { type: "clarify"; requestId: string }
|
||||
| null;
|
||||
|
||||
export function HrLeavePage({ tab, canApprove, ownVm, approverVm, team, kinds, tabHref, submitting, actions }: HrLeavePageProps) {
|
||||
const { t } = useTranslation();
|
||||
const [dialog, setDialog] = useState<DialogState>(null);
|
||||
const [form, setForm] = useState({ requestKind: kinds[0] ?? "vacation", approverUserId: "", startDate: "", endDate: "", note: "" });
|
||||
const [text, setText] = useState("");
|
||||
|
||||
const tabs: HrLeaveTab[] = canApprove ? ["own", "approvals", "team"] : ["own", "team"];
|
||||
|
||||
return (
|
||||
<div className="flex w-full flex-col gap-6 p-6" data-ui-id="ui.hr.leave">
|
||||
<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.leave.title")}</span>
|
||||
<span className="text-body-default-regular-150 font-body-default-regular-150 text-text-neutral-secondary">
|
||||
{t("hr.leave.subtitle")}
|
||||
</span>
|
||||
</div>
|
||||
{tab === "own" && ownVm.data?.canCreate ? (
|
||||
<Button icon={<FeatherPlus />} onClick={() => setDialog({ type: "new" })} data-ui-id="ui.hr.leave.new">
|
||||
{t("hr.leave.action.new")}
|
||||
</Button>
|
||||
) : null}
|
||||
</div>
|
||||
|
||||
<div data-ui-id="ui.hr.leave.tabs">
|
||||
<Tabs>
|
||||
{tabs.map((entry) => (
|
||||
<a key={entry} href={tabHref(entry)} className="contents no-underline">
|
||||
<Tabs.Item active={tab === entry}>{t(`hr.leave.tab.${entry === "approvals" ? "approvals" : entry}`)}</Tabs.Item>
|
||||
</a>
|
||||
))}
|
||||
</Tabs>
|
||||
</div>
|
||||
|
||||
{tab === "own" ? (
|
||||
<OwnList vm={ownVm} submitting={submitting} onWithdraw={actions.onWithdraw} onReply={(id) => { setText(""); setDialog({ type: "reply", requestId: id }); }} />
|
||||
) : null}
|
||||
|
||||
{tab === "approvals" ? (
|
||||
<ApproverList
|
||||
vm={approverVm}
|
||||
submitting={submitting}
|
||||
onApprove={actions.onApprove}
|
||||
onReject={actions.onReject}
|
||||
onClarify={(id) => { setText(""); setDialog({ type: "clarify", requestId: id }); }}
|
||||
/>
|
||||
) : null}
|
||||
|
||||
{tab === "team" ? <TeamList team={team} /> : null}
|
||||
|
||||
{/* New request dialog */}
|
||||
<Dialog open={dialog?.type === "new"} onOpenChange={(open) => !open && setDialog(null)}>
|
||||
<Dialog.Content className="w-full max-w-[560px] p-4" data-ui-id="ui.hr.leave.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.leave.action.new")}</span>
|
||||
<div className="flex w-full flex-col gap-4">
|
||||
<Select
|
||||
label={t("hr.leave.field.kind")}
|
||||
showLabel
|
||||
value={form.requestKind}
|
||||
onValueChange={(value: string) => setForm((s) => ({ ...s, requestKind: value as HrVacationRequestKind }))}
|
||||
>
|
||||
{kinds.map((kind) => (
|
||||
<Select.Item key={kind} value={kind}>
|
||||
{t(`hr.leave.kind.${kind}`)}
|
||||
</Select.Item>
|
||||
))}
|
||||
</Select>
|
||||
<div className="flex flex-wrap gap-4">
|
||||
<DateField label={t("hr.leave.field.start")} name="startDate" />
|
||||
<DateField label={t("hr.leave.field.end")} name="endDate" />
|
||||
</div>
|
||||
<TextInput label={t("hr.leave.field.approver")} showLabel fillContainer>
|
||||
<TextInput.Input value={form.approverUserId} onChange={(e) => setForm((s) => ({ ...s, approverUserId: e.target.value }))} />
|
||||
</TextInput>
|
||||
<TextInput label={t("hr.leave.field.note")} showLabel fillContainer>
|
||||
<TextInput.Input value={form.note} onChange={(e) => setForm((s) => ({ ...s, note: e.target.value }))} />
|
||||
</TextInput>
|
||||
</div>
|
||||
<div className="flex justify-end gap-2">
|
||||
<Button variant="neutral" onClick={() => setDialog(null)}>
|
||||
{t("hr.action.cancel")}
|
||||
</Button>
|
||||
<NewRequestSubmit form={form} submitting={submitting} onSubmit={actions.onSubmit} onDone={() => setDialog(null)} />
|
||||
</div>
|
||||
</div>
|
||||
</Dialog.Content>
|
||||
</Dialog>
|
||||
|
||||
{/* Reply / clarify text dialog */}
|
||||
<Dialog open={dialog?.type === "reply" || dialog?.type === "clarify"} onOpenChange={(open) => !open && setDialog(null)}>
|
||||
<Dialog.Content className="w-full max-w-[560px] p-4" data-ui-id="ui.hr.leave.textDialog">
|
||||
<div className="flex w-full flex-col gap-6 p-2">
|
||||
<span className="text-heading-3 font-heading-3 text-text-neutral-primary">
|
||||
{dialog?.type === "reply" ? t("hr.leave.action.reply") : t("hr.leave.action.clarify")}
|
||||
</span>
|
||||
<TextArea label={dialog?.type === "reply" ? t("hr.leave.field.reply") : t("hr.leave.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={() => setDialog(null)}>
|
||||
{t("hr.action.cancel")}
|
||||
</Button>
|
||||
<Button
|
||||
loading={submitting}
|
||||
disabled={text.trim().length === 0}
|
||||
onClick={() => {
|
||||
if (dialog?.type === "reply") actions.onReply(dialog.requestId, text);
|
||||
if (dialog?.type === "clarify") actions.onClarify(dialog.requestId, text);
|
||||
setDialog(null);
|
||||
}}
|
||||
>
|
||||
{t("hr.action.confirm")}
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
</Dialog.Content>
|
||||
</Dialog>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
// The DateField uses native inputs (uncontrolled); read them from the dialog DOM on submit.
|
||||
function NewRequestSubmit({
|
||||
form,
|
||||
submitting,
|
||||
onSubmit,
|
||||
onDone,
|
||||
}: {
|
||||
form: { requestKind: string; approverUserId: string; note: string; startDate: string; endDate: string };
|
||||
submitting: boolean;
|
||||
onSubmit: HrLeaveActions["onSubmit"];
|
||||
onDone: () => void;
|
||||
}) {
|
||||
const { t } = useTranslation();
|
||||
return (
|
||||
<Button
|
||||
loading={submitting}
|
||||
onClick={(event) => {
|
||||
const dialogEl = (event.currentTarget as HTMLElement).closest("[data-ui-id='ui.hr.leave.newDialog']");
|
||||
const start = dialogEl?.querySelector<HTMLInputElement>("input[name='startDate']")?.value ?? "";
|
||||
const end = dialogEl?.querySelector<HTMLInputElement>("input[name='endDate']")?.value ?? "";
|
||||
if (!start || !end) return;
|
||||
onSubmit({ requestKind: form.requestKind, approverUserId: form.approverUserId, startDate: start, endDate: end, note: form.note });
|
||||
onDone();
|
||||
}}
|
||||
data-ui-id="ui.hr.leave.newDialog.submit"
|
||||
>
|
||||
{t("hr.leave.action.submit")}
|
||||
</Button>
|
||||
);
|
||||
}
|
||||
|
||||
function OwnList({ vm, submitting, onWithdraw, onReply }: { vm: HrLeaveOwnVM; submitting: boolean; onWithdraw: (id: string) => void; onReply: (id: string) => void }) {
|
||||
const { t } = useTranslation();
|
||||
if (vm.status !== "ready" || !vm.data) return null;
|
||||
const { rows } = vm.data;
|
||||
if (rows.length === 0) {
|
||||
return (
|
||||
<div data-ui-id="ui.hr.leave.own.empty">
|
||||
<EmptyState title={t("hr.leave.own.empty.headline")} body={t("hr.leave.own.empty.body")} />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
return (
|
||||
<div className="flex w-full flex-col gap-3" data-ui-id="ui.hr.leave.own.list">
|
||||
{rows.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">{t(row.kindLabelKey)}</span>
|
||||
<span className="text-body-small-regular-0 font-body-small-regular-0 text-text-neutral-tertiary">
|
||||
{row.startDateIso} – {row.endDateIso}
|
||||
</span>
|
||||
</div>
|
||||
<div className="flex items-center gap-2">
|
||||
<BadgeFeedback farbe="subtle-neutral" size="small">
|
||||
{t(row.statusLabelKey)}
|
||||
</BadgeFeedback>
|
||||
{row.canReply ? (
|
||||
<Button variant="tertiary" size="small" onClick={() => onReply(row.id)}>
|
||||
{t("hr.leave.action.reply")}
|
||||
</Button>
|
||||
) : null}
|
||||
{row.canWithdraw ? (
|
||||
<Button variant="tertiary" size="small" loading={submitting} onClick={() => onWithdraw(row.id)}>
|
||||
{t("hr.leave.action.withdraw")}
|
||||
</Button>
|
||||
) : null}
|
||||
</div>
|
||||
</div>
|
||||
</Card>
|
||||
))}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function ApproverList({
|
||||
vm,
|
||||
submitting,
|
||||
onApprove,
|
||||
onReject,
|
||||
onClarify,
|
||||
}: {
|
||||
vm: HrLeaveApproverVM;
|
||||
submitting: boolean;
|
||||
onApprove: (id: string) => void;
|
||||
onReject: (id: string) => void;
|
||||
onClarify: (id: string) => void;
|
||||
}) {
|
||||
const { t } = useTranslation();
|
||||
if (vm.status !== "ready" || !vm.data) return null;
|
||||
const { rows, conflictHintKey } = vm.data;
|
||||
if (rows.length === 0) {
|
||||
return (
|
||||
<div data-ui-id="ui.hr.leave.approvals.empty">
|
||||
<EmptyState title={t("hr.leave.approver.empty.headline")} body={t("hr.leave.approver.empty.body")} />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
return (
|
||||
<div className="flex w-full flex-col gap-3" data-ui-id="ui.hr.leave.approvals.list">
|
||||
{rows.map((row) => (
|
||||
<Card key={row.id} data-row-id={row.id} data-conflict={row.hasConflict}>
|
||||
<div className="flex w-full flex-col gap-3">
|
||||
<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.employeeLabel}</span>
|
||||
<span className="text-body-small-regular-0 font-body-small-regular-0 text-text-neutral-tertiary">
|
||||
{t(row.kindLabelKey)} · {row.startDateIso} – {row.endDateIso}
|
||||
</span>
|
||||
</div>
|
||||
<div className="flex items-center gap-2">
|
||||
<Button variant="tertiary" size="small" onClick={() => onClarify(row.id)}>
|
||||
{t("hr.leave.action.clarify")}
|
||||
</Button>
|
||||
<Button variant="destructive" size="small" loading={submitting} onClick={() => onReject(row.id)}>
|
||||
{t("hr.leave.action.reject")}
|
||||
</Button>
|
||||
<Button size="small" loading={submitting} onClick={() => onApprove(row.id)}>
|
||||
{t("hr.leave.action.approve")}
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
{row.hasConflict ? (
|
||||
<Alert variant="warning" title={t(conflictHintKey, { count: row.conflictCount })} data-ui-id="ui.hr.leave.conflict" />
|
||||
) : null}
|
||||
</div>
|
||||
</Card>
|
||||
))}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function TeamList({ team }: { team: readonly HrLeaveTeamAbsence[] }) {
|
||||
const { t } = useTranslation();
|
||||
if (team.length === 0) {
|
||||
return (
|
||||
<div data-ui-id="ui.hr.leave.team.empty">
|
||||
<EmptyState title={t("hr.leave.team.empty.headline")} body={t("hr.leave.team.empty.body")} />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
return (
|
||||
<div className="flex w-full flex-col gap-2" data-ui-id="ui.hr.leave.team.list">
|
||||
{team.map((entry) => (
|
||||
<Card key={`${entry.source}-${entry.id}`}>
|
||||
<div className="flex w-full items-center justify-between gap-4">
|
||||
<span className="text-body-default-medium-0 font-body-default-medium-0 text-text-neutral-primary">{entry.employeeLabel}</span>
|
||||
<span className="text-body-small-regular-0 font-body-small-regular-0 text-text-neutral-tertiary">
|
||||
{t(`hr.leave.absence.${entry.source}`)} · {entry.startIso} – {entry.endIso}
|
||||
</span>
|
||||
</div>
|
||||
</Card>
|
||||
))}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
+159
@@ -0,0 +1,159 @@
|
||||
// AK-P17a Interim-UI (AD-28) — locations screen composed from ~/ui (D-HR
|
||||
// "Standorte", archetype A2 + A5 create modal). Pure presentational: renders the
|
||||
// server-built HrLocationListVM; admin create/set-default/archive run through the
|
||||
// injected actions (route owns the fetcher). The create form uses a real Dialog
|
||||
// (DialogLayout -> Dialog -> Dialog.Content), never a Card fake. Final Subframe
|
||||
// optics = tracked design-nachzug.
|
||||
|
||||
import { useState } from "react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { FeatherPlus } from "@subframe/core";
|
||||
import type { HrLocationListVM } from "@hivegrid/view-models";
|
||||
import { BadgeFeedback } from "~/ui/components/BadgeFeedback";
|
||||
import { Button } from "~/ui/components/Button";
|
||||
import { Checkbox } from "~/ui/components/Checkbox";
|
||||
import { Dialog } from "~/ui/components/Dialog";
|
||||
import { EmptyState } from "~/ui/components/EmptyState";
|
||||
import { Table } from "~/ui/components/Table";
|
||||
import { TextInput } from "~/ui/components/TextInput";
|
||||
|
||||
export type HrLocationsActions = {
|
||||
onCreate: (input: { name: string; city: string; isDefault: boolean }) => void;
|
||||
onSetDefault: (locationId: string) => void;
|
||||
onArchive: (locationId: string) => void;
|
||||
};
|
||||
|
||||
export type HrLocationsPageProps = {
|
||||
vm: HrLocationListVM;
|
||||
submitting: boolean;
|
||||
actions: HrLocationsActions;
|
||||
};
|
||||
|
||||
export function HrLocationsPage({ vm, submitting, actions }: HrLocationsPageProps) {
|
||||
const { t } = useTranslation();
|
||||
const [createOpen, setCreateOpen] = useState(false);
|
||||
const [name, setName] = useState("");
|
||||
const [city, setCity] = useState("");
|
||||
const [isDefault, setIsDefault] = useState(false);
|
||||
|
||||
if (vm.status !== "ready" || !vm.data) {
|
||||
return <div className="flex w-full flex-col gap-6 p-6" data-ui-id="ui.hr.locations" />;
|
||||
}
|
||||
|
||||
const { rows, canManage, emptyHeadlineKey, emptyBodyKey } = vm.data;
|
||||
|
||||
function submitCreate() {
|
||||
actions.onCreate({ name, city, isDefault });
|
||||
setCreateOpen(false);
|
||||
setName("");
|
||||
setCity("");
|
||||
setIsDefault(false);
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="flex w-full flex-col gap-6 p-6" data-ui-id="ui.hr.locations">
|
||||
<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.locations.title")}</span>
|
||||
<span className="text-body-default-regular-150 font-body-default-regular-150 text-text-neutral-secondary">
|
||||
{t("hr.locations.subtitle")}
|
||||
</span>
|
||||
</div>
|
||||
{canManage ? (
|
||||
<Button icon={<FeatherPlus />} onClick={() => setCreateOpen(true)} data-ui-id="ui.hr.locations.new">
|
||||
{t("hr.locations.action.new")}
|
||||
</Button>
|
||||
) : null}
|
||||
</div>
|
||||
|
||||
{rows.length === 0 ? (
|
||||
<div data-ui-id="ui.hr.locations.empty">
|
||||
<EmptyState title={t(emptyHeadlineKey)} body={t(emptyBodyKey)} />
|
||||
</div>
|
||||
) : (
|
||||
<div className="w-full overflow-x-auto">
|
||||
<Table
|
||||
data-ui-id="ui.hr.locations.table"
|
||||
header={
|
||||
<Table.HeaderRow>
|
||||
<Table.HeaderCell>{t("hr.locations.column.name")}</Table.HeaderCell>
|
||||
<Table.HeaderCell>{t("hr.locations.column.city")}</Table.HeaderCell>
|
||||
<Table.HeaderCell>{t("hr.locations.column.employees")}</Table.HeaderCell>
|
||||
{canManage ? <Table.HeaderCell> </Table.HeaderCell> : null}
|
||||
</Table.HeaderRow>
|
||||
}
|
||||
>
|
||||
{rows.map((row) => (
|
||||
<Table.Row key={row.id} data-row-id={row.id} data-default={row.isDefault}>
|
||||
<Table.Cell>
|
||||
<div className="flex items-center gap-2">
|
||||
<a
|
||||
href={row.detailHref}
|
||||
className="text-body-default-medium-0 font-body-default-medium-0 text-text-feedback-link-default"
|
||||
>
|
||||
{row.name}
|
||||
</a>
|
||||
{row.isDefault ? (
|
||||
<BadgeFeedback farbe="subtle-neutral" size="small">
|
||||
{t("hr.locations.default")}
|
||||
</BadgeFeedback>
|
||||
) : null}
|
||||
</div>
|
||||
</Table.Cell>
|
||||
<Table.Cell>
|
||||
<span className="text-body-default-regular-0 font-body-default-regular-0 text-text-neutral-secondary">
|
||||
{row.city ?? "—"}
|
||||
</span>
|
||||
</Table.Cell>
|
||||
<Table.Cell>
|
||||
<span className="text-body-default-regular-0 font-body-default-regular-0 text-text-neutral-secondary">
|
||||
{row.employeeCount}
|
||||
</span>
|
||||
</Table.Cell>
|
||||
{canManage ? (
|
||||
<Table.Cell>
|
||||
<div className="flex items-center justify-end gap-2">
|
||||
{!row.isDefault ? (
|
||||
<Button variant="tertiary" size="small" onClick={() => actions.onSetDefault(row.id)}>
|
||||
{t("hr.locations.action.setDefault")}
|
||||
</Button>
|
||||
) : null}
|
||||
<Button variant="tertiary" size="small" onClick={() => actions.onArchive(row.id)}>
|
||||
{t("hr.locations.action.archive")}
|
||||
</Button>
|
||||
</div>
|
||||
</Table.Cell>
|
||||
) : null}
|
||||
</Table.Row>
|
||||
))}
|
||||
</Table>
|
||||
</div>
|
||||
)}
|
||||
|
||||
<Dialog open={createOpen} onOpenChange={setCreateOpen}>
|
||||
<Dialog.Content className="w-full max-w-[560px] p-4" data-ui-id="ui.hr.locations.create">
|
||||
<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.locations.create.title")}</span>
|
||||
<div className="flex w-full flex-col gap-4">
|
||||
<TextInput label={t("hr.locations.field.name")} showLabel fillContainer>
|
||||
<TextInput.Input value={name} onChange={(event) => setName(event.target.value)} data-ui-id="ui.hr.locations.create.name" />
|
||||
</TextInput>
|
||||
<TextInput label={t("hr.locations.field.city")} showLabel fillContainer>
|
||||
<TextInput.Input value={city} onChange={(event) => setCity(event.target.value)} data-ui-id="ui.hr.locations.create.city" />
|
||||
</TextInput>
|
||||
<Checkbox label={t("hr.locations.field.isDefault")} checked={isDefault} onCheckedChange={(checked: boolean) => setIsDefault(checked)} />
|
||||
</div>
|
||||
<div className="flex justify-end gap-2">
|
||||
<Button variant="neutral" onClick={() => setCreateOpen(false)}>
|
||||
{t("hr.action.cancel")}
|
||||
</Button>
|
||||
<Button loading={submitting} disabled={name.trim().length === 0} onClick={submitCreate} data-ui-id="ui.hr.locations.create.submit">
|
||||
{t("hr.locations.create.submit")}
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
</Dialog.Content>
|
||||
</Dialog>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
+51
@@ -0,0 +1,51 @@
|
||||
import { vi, describe, it, expect } from "vitest";
|
||||
import "@testing-library/jest-dom";
|
||||
import { render, fireEvent } from "@testing-library/react";
|
||||
import { buildHrDocumentListVM } from "@hivegrid/view-models";
|
||||
|
||||
import { HrMyDocumentsPage, type HrDocumentUploadState } from "./HrMyDocumentsPage";
|
||||
|
||||
vi.mock("react-i18next", () => ({
|
||||
useTranslation: () => ({ t: (str: string) => str, i18n: { language: "de" } }),
|
||||
}));
|
||||
|
||||
const IDLE: HrDocumentUploadState = { status: "idle", errorKey: null };
|
||||
|
||||
function vm(canUpload: boolean, rows: Parameters<typeof buildHrDocumentListVM>[0]["rows"] = []) {
|
||||
return buildHrDocumentListVM({ canUpload, uploadHref: "/acme/hr/my-documents", rows });
|
||||
}
|
||||
|
||||
describe("HrMyDocumentsPage (interim-UI, upload wiring)", () => {
|
||||
it("hides the upload affordance when the VM says the viewer cannot upload", () => {
|
||||
const { container } = render(<HrMyDocumentsPage vm={vm(false)} submitting={false} upload={IDLE} actions={{ onArchive: vi.fn(), onUpload: vi.fn(), onResetUpload: vi.fn() }} />);
|
||||
expect(container.querySelector('[data-ui-id="ui.hr.documents.upload"]')).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("opens the upload dialog and hands the picked file + metadata to onUpload", () => {
|
||||
const onUpload = vi.fn();
|
||||
const { container } = render(<HrMyDocumentsPage vm={vm(true)} submitting={false} upload={IDLE} actions={{ onArchive: vi.fn(), onUpload, onResetUpload: vi.fn() }} />);
|
||||
|
||||
// The trigger lives on the page; the dialog content is portalled to document.body.
|
||||
fireEvent.click(container.querySelector('[data-ui-id="ui.hr.documents.upload"]') as HTMLElement);
|
||||
const titleInput = document.querySelector('[data-ui-id="ui.hr.documents.upload.title"]') as HTMLInputElement;
|
||||
fireEvent.change(titleInput, { target: { value: "Arbeitsvertrag" } });
|
||||
const fileInput = document.querySelector('[data-ui-id="ui.hr.documents.upload.file"]') as HTMLInputElement;
|
||||
const file = new File(["hello"], "vertrag.pdf", { type: "application/pdf" });
|
||||
fireEvent.change(fileInput, { target: { files: [file] } });
|
||||
|
||||
fireEvent.click(document.querySelector('[data-ui-id="ui.hr.documents.upload.submit"]') as HTMLElement);
|
||||
expect(onUpload).toHaveBeenCalledTimes(1);
|
||||
const arg = onUpload.mock.calls[0][0];
|
||||
expect(arg.title).toBe("Arbeitsvertrag");
|
||||
expect(arg.file).toBe(file);
|
||||
expect(arg.documentKind).toBe("other");
|
||||
});
|
||||
|
||||
it("surfaces an upload error via the Alert", () => {
|
||||
const { container } = render(
|
||||
<HrMyDocumentsPage vm={vm(true)} submitting={false} upload={{ status: "error", errorKey: "hr.documents.upload.error.generic" }} actions={{ onArchive: vi.fn(), onUpload: vi.fn(), onResetUpload: vi.fn() }} />,
|
||||
);
|
||||
fireEvent.click(container.querySelector('[data-ui-id="ui.hr.documents.upload"]') as HTMLElement);
|
||||
expect(document.querySelector('[data-ui-id="ui.hr.documents.upload.progress"][data-status="error"]')).toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
+265
@@ -0,0 +1,265 @@
|
||||
// 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 { FeatherUpload } from "@subframe/core";
|
||||
import type { HrDocumentKind, HrDocumentListVM } from "@hivegrid/view-models";
|
||||
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";
|
||||
|
||||
/** 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<HrDocumentKind | null>(null);
|
||||
const [uploadOpen, setUploadOpen] = useState(false);
|
||||
const [form, setForm] = useState<{ title: string; documentKind: HrDocumentKind; validUntil: string }>({ title: "", documentKind: "other", validUntil: "" });
|
||||
const [file, setFile] = useState<File | null>(null);
|
||||
const fileInputRef = useRef<HTMLInputElement>(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 <div className="flex w-full flex-col gap-6 p-6" data-ui-id="ui.hr.documents" />;
|
||||
}
|
||||
|
||||
const { rows, canUpload, emptyHeadlineKey, emptyBodyKey } = vm.data;
|
||||
const dateFormatter = new Intl.DateTimeFormat(i18n.language, { 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 (
|
||||
<div className="flex w-full flex-col gap-6 p-6" data-ui-id="ui.hr.documents">
|
||||
<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.documents.title")}</span>
|
||||
<span className="text-body-default-regular-150 font-body-default-regular-150 text-text-neutral-secondary">
|
||||
{t("hr.documents.subtitle")}
|
||||
</span>
|
||||
</div>
|
||||
{canUpload ? (
|
||||
<Button
|
||||
icon={<FeatherUpload />}
|
||||
onClick={() => {
|
||||
actions.onResetUpload();
|
||||
setUploadOpen(true);
|
||||
}}
|
||||
data-ui-id="ui.hr.documents.upload"
|
||||
>
|
||||
{t("hr.documents.upload.button")}
|
||||
</Button>
|
||||
) : null}
|
||||
</div>
|
||||
|
||||
{rows.length > 0 ? (
|
||||
<div className="flex flex-wrap items-end gap-4" data-ui-id="ui.hr.documents.filter">
|
||||
<Select
|
||||
className="max-w-[240px]"
|
||||
label={t("hr.documents.filter.kind")}
|
||||
showLabel
|
||||
value={kind ?? FILTER_ALL}
|
||||
onValueChange={(value: string) => setKind(value === FILTER_ALL ? null : (value as HrDocumentKind))}
|
||||
>
|
||||
<Select.Item value={FILTER_ALL}>{t("hr.documents.filter.all")}</Select.Item>
|
||||
{KINDS.map((entry) => (
|
||||
<Select.Item key={entry} value={entry}>
|
||||
{t(`hr.document.kind.${entry}`)}
|
||||
</Select.Item>
|
||||
))}
|
||||
</Select>
|
||||
</div>
|
||||
) : null}
|
||||
|
||||
{rows.length === 0 ? (
|
||||
<div data-ui-id="ui.hr.documents.empty">
|
||||
<EmptyState title={t(emptyHeadlineKey)} body={t(emptyBodyKey)} />
|
||||
</div>
|
||||
) : visible.length === 0 ? (
|
||||
<EmptyState variant="no-results" title={t("hr.documents.noMatches")} body={t(emptyBodyKey)} />
|
||||
) : (
|
||||
<div className="w-full overflow-x-auto">
|
||||
<Table
|
||||
data-ui-id="ui.hr.documents.table"
|
||||
header={
|
||||
<Table.HeaderRow>
|
||||
<Table.HeaderCell>{t("hr.documents.column.title")}</Table.HeaderCell>
|
||||
<Table.HeaderCell>{t("hr.documents.column.kind")}</Table.HeaderCell>
|
||||
<Table.HeaderCell>{t("hr.documents.column.date")}</Table.HeaderCell>
|
||||
<Table.HeaderCell>{t("hr.documents.column.validity")}</Table.HeaderCell>
|
||||
<Table.HeaderCell> </Table.HeaderCell>
|
||||
</Table.HeaderRow>
|
||||
}
|
||||
>
|
||||
{visible.map((row) => (
|
||||
<Table.Row key={row.id} data-row-id={row.id} data-readonly={row.readOnly}>
|
||||
<Table.Cell>
|
||||
<div className="flex items-center gap-2">
|
||||
<a href={row.fileHref} className="text-body-default-medium-0 font-body-default-medium-0 text-text-feedback-link-default">
|
||||
{row.title}
|
||||
</a>
|
||||
{row.readOnly ? (
|
||||
<BadgeFeedback farbe="subtle-neutral" size="small">
|
||||
{t("hr.documents.status.readOnly")}
|
||||
</BadgeFeedback>
|
||||
) : null}
|
||||
</div>
|
||||
</Table.Cell>
|
||||
<Table.Cell>
|
||||
<span className="text-body-default-regular-0 font-body-default-regular-0 text-text-neutral-secondary">{t(row.kindKey)}</span>
|
||||
</Table.Cell>
|
||||
<Table.Cell>
|
||||
<span className="text-body-default-regular-0 font-body-default-regular-0 text-text-neutral-secondary">
|
||||
{dateFormatter.format(new Date(row.createdAtIso))}
|
||||
</span>
|
||||
</Table.Cell>
|
||||
<Table.Cell>
|
||||
{row.validUntilIso ? (
|
||||
row.isExpired ? (
|
||||
<BadgeFeedback farbe="subtle-negative" size="small">
|
||||
{t("hr.documents.status.expired")}
|
||||
</BadgeFeedback>
|
||||
) : (
|
||||
<span className="text-body-default-regular-0 font-body-default-regular-0 text-text-neutral-secondary">
|
||||
{dateFormatter.format(new Date(row.validUntilIso))}
|
||||
</span>
|
||||
)
|
||||
) : (
|
||||
<span className="text-body-default-regular-0 font-body-default-regular-0 text-text-neutral-tertiary">—</span>
|
||||
)}
|
||||
</Table.Cell>
|
||||
<Table.Cell>
|
||||
{!row.readOnly ? (
|
||||
<div className="flex justify-end">
|
||||
<Button variant="tertiary" size="small" loading={submitting} onClick={() => actions.onArchive(row.id)}>
|
||||
{t("hr.documents.action.archive")}
|
||||
</Button>
|
||||
</div>
|
||||
) : null}
|
||||
</Table.Cell>
|
||||
</Table.Row>
|
||||
))}
|
||||
</Table>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* Upload dialog (self-service). The route drives the chunked upload + link. */}
|
||||
<Dialog open={uploadOpen} onOpenChange={(next) => { if (!busy) setUploadOpen(next); }}>
|
||||
<Dialog.Content className="w-full max-w-[560px] p-4" data-ui-id="ui.hr.documents.uploadDialog">
|
||||
<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.documents.upload.dialog.title")}</span>
|
||||
<div className="flex w-full flex-col gap-4">
|
||||
<TextInput label={t("hr.documents.upload.field.title")} showLabel fillContainer>
|
||||
<TextInput.Input value={form.title} onChange={(e) => setForm((s) => ({ ...s, title: e.target.value }))} data-ui-id="ui.hr.documents.upload.title" />
|
||||
</TextInput>
|
||||
<Select
|
||||
label={t("hr.documents.upload.field.kind")}
|
||||
showLabel
|
||||
value={form.documentKind}
|
||||
onValueChange={(value: string) => setForm((s) => ({ ...s, documentKind: value as HrDocumentKind }))}
|
||||
>
|
||||
{KINDS.map((entry) => (
|
||||
<Select.Item key={entry} value={entry}>
|
||||
{t(`hr.document.kind.${entry}`)}
|
||||
</Select.Item>
|
||||
))}
|
||||
</Select>
|
||||
<label className="flex flex-col gap-1">
|
||||
<span className="text-body-small-medium-0 font-body-small-medium-0 text-text-neutral-tertiary">{t("hr.documents.upload.field.validUntil")}</span>
|
||||
<input
|
||||
type="date"
|
||||
value={form.validUntil}
|
||||
onChange={(e) => setForm((s) => ({ ...s, validUntil: e.target.value }))}
|
||||
className="h-9 rounded-[4px] border border-solid border-border-default bg-transparent px-3 text-body-default-regular-0 font-body-default-regular-0 text-text-neutral-primary outline-none"
|
||||
/>
|
||||
</label>
|
||||
<label className="flex flex-col gap-1">
|
||||
<span className="text-body-small-medium-0 font-body-small-medium-0 text-text-neutral-tertiary">{t("hr.documents.upload.field.file")}</span>
|
||||
<input
|
||||
ref={fileInputRef}
|
||||
type="file"
|
||||
onChange={(e) => setFile(e.target.files?.[0] ?? null)}
|
||||
className="text-body-default-regular-0 font-body-default-regular-0 text-text-neutral-secondary file:mr-3 file:rounded-[4px] file:border file:border-solid file:border-border-default file:bg-transparent file:px-3 file:py-1.5 file:text-text-neutral-primary"
|
||||
data-ui-id="ui.hr.documents.upload.file"
|
||||
/>
|
||||
</label>
|
||||
|
||||
{upload.status !== "idle" ? (
|
||||
<div className="flex flex-col gap-2" data-ui-id="ui.hr.documents.upload.progress" data-status={upload.status}>
|
||||
{upload.status === "error" ? (
|
||||
<Alert variant="error" textSize="small" description={t(upload.errorKey ?? "hr.documents.upload.error.generic")} notDismissible />
|
||||
) : upload.status === "uploading" ? (
|
||||
<span className="text-body-small-regular-150 font-body-small-regular-150 text-text-neutral-secondary">{t("hr.documents.upload.status.uploading")}</span>
|
||||
) : null}
|
||||
</div>
|
||||
) : null}
|
||||
</div>
|
||||
<div className="flex justify-end gap-2">
|
||||
<Button variant="neutral" disabled={busy} onClick={() => setUploadOpen(false)}>
|
||||
{t("hr.action.cancel")}
|
||||
</Button>
|
||||
<Button loading={busy} disabled={!file || form.title.trim().length === 0} onClick={submitUpload} data-ui-id="ui.hr.documents.upload.submit">
|
||||
{t("hr.documents.upload.submit")}
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
</Dialog.Content>
|
||||
</Dialog>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
+110
@@ -0,0 +1,110 @@
|
||||
// AK-P17a Interim-UI (AD-28) — password-safe vault list composed from ~/ui (D-HR
|
||||
// "Passwort-Safe", archetype A2 + A5 create modal). Pure presentational: shows
|
||||
// ONLY the vaults the caller holds access to (no secret values here); creating a
|
||||
// vault runs through the injected action (route owns the fetcher). Final Subframe
|
||||
// optics = tracked design-nachzug.
|
||||
|
||||
import { useState } from "react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { FeatherPlus } from "@subframe/core";
|
||||
import type { VaultListVM } from "@hivegrid/view-models";
|
||||
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 { TextInput } from "~/ui/components/TextInput";
|
||||
|
||||
export type HrPasswordSafeListActions = {
|
||||
onCreateVault: (input: { name: string; description: string }) => void;
|
||||
};
|
||||
|
||||
export type HrPasswordSafeListPageProps = {
|
||||
vm: VaultListVM;
|
||||
submitting: boolean;
|
||||
actions: HrPasswordSafeListActions;
|
||||
};
|
||||
|
||||
export function HrPasswordSafeListPage({ vm, submitting, actions }: HrPasswordSafeListPageProps) {
|
||||
const { t } = useTranslation();
|
||||
const [createOpen, setCreateOpen] = useState(false);
|
||||
const [name, setName] = useState("");
|
||||
const [description, setDescription] = useState("");
|
||||
|
||||
if (vm.status !== "ready" || !vm.data) {
|
||||
return <div className="flex w-full flex-col gap-6 p-6" data-ui-id="ui.hr.passwordSafe" />;
|
||||
}
|
||||
|
||||
const { rows, canCreate, emptyHeadlineKey, emptyBodyKey } = vm.data;
|
||||
|
||||
function submitCreate() {
|
||||
actions.onCreateVault({ name, description });
|
||||
setCreateOpen(false);
|
||||
setName("");
|
||||
setDescription("");
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="flex w-full flex-col gap-6 p-6" data-ui-id="ui.hr.passwordSafe">
|
||||
<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.passwordSafe.title")}</span>
|
||||
<span className="text-body-default-regular-150 font-body-default-regular-150 text-text-neutral-secondary">
|
||||
{t("hr.passwordSafe.subtitle")}
|
||||
</span>
|
||||
</div>
|
||||
{canCreate ? (
|
||||
<Button icon={<FeatherPlus />} onClick={() => setCreateOpen(true)} data-ui-id="ui.hr.passwordSafe.new">
|
||||
{t("hr.passwordSafe.action.newVault")}
|
||||
</Button>
|
||||
) : null}
|
||||
</div>
|
||||
|
||||
{rows.length === 0 ? (
|
||||
<div data-ui-id="ui.hr.passwordSafe.empty">
|
||||
<EmptyState title={t(emptyHeadlineKey)} body={t(emptyBodyKey)} />
|
||||
</div>
|
||||
) : (
|
||||
<div className="grid grid-cols-1 gap-4 sm:grid-cols-2 lg:grid-cols-3" data-ui-id="ui.hr.passwordSafe.list">
|
||||
{rows.map((row) => (
|
||||
<a key={row.id} href={row.detailHref} className="no-underline" data-row-id={row.id}>
|
||||
<Card>
|
||||
<div className="flex w-full flex-col gap-1">
|
||||
<span className="text-body-default-medium-0 font-body-default-medium-0 text-text-neutral-primary">{row.name}</span>
|
||||
{row.description ? (
|
||||
<span className="text-body-default-regular-150 font-body-default-regular-150 text-text-neutral-secondary">
|
||||
{row.description}
|
||||
</span>
|
||||
) : null}
|
||||
</div>
|
||||
</Card>
|
||||
</a>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
|
||||
<Dialog open={createOpen} onOpenChange={setCreateOpen}>
|
||||
<Dialog.Content className="w-full max-w-[560px] p-4" data-ui-id="ui.hr.passwordSafe.create">
|
||||
<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.passwordSafe.create.title")}</span>
|
||||
<div className="flex w-full flex-col gap-4">
|
||||
<TextInput label={t("hr.passwordSafe.field.vaultName")} showLabel fillContainer>
|
||||
<TextInput.Input value={name} onChange={(event) => setName(event.target.value)} data-ui-id="ui.hr.passwordSafe.create.name" />
|
||||
</TextInput>
|
||||
<TextInput label={t("hr.passwordSafe.field.description")} showLabel fillContainer>
|
||||
<TextInput.Input value={description} onChange={(event) => setDescription(event.target.value)} />
|
||||
</TextInput>
|
||||
</div>
|
||||
<div className="flex justify-end gap-2">
|
||||
<Button variant="neutral" onClick={() => setCreateOpen(false)}>
|
||||
{t("hr.action.cancel")}
|
||||
</Button>
|
||||
<Button loading={submitting} disabled={name.trim().length === 0} onClick={submitCreate} data-ui-id="ui.hr.passwordSafe.create.submit">
|
||||
{t("hr.passwordSafe.create.submit")}
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
</Dialog.Content>
|
||||
</Dialog>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
+79
@@ -0,0 +1,79 @@
|
||||
// AK-P17b Interim-UI (AD-28) — employee payslips composed from ~/ui (D-HR
|
||||
// "Lohnabrechnungen", archetype A2). Pure presentational: own list; opening a
|
||||
// payslip is audited server-side and returns the File id (route opens it). Final
|
||||
// Subframe optics = tracked design-nachzug.
|
||||
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { FeatherExternalLink } from "@subframe/core";
|
||||
import type { HrPayslipOwnVM } from "@hivegrid/view-models";
|
||||
import { BadgeFeedback } from "~/ui/components/BadgeFeedback";
|
||||
import { Button } from "~/ui/components/Button";
|
||||
import { EmptyState } from "~/ui/components/EmptyState";
|
||||
import { Table } from "~/ui/components/Table";
|
||||
|
||||
export type HrPayslipsActions = { onOpen: (payslipId: string) => void };
|
||||
|
||||
export type HrPayslipsPageProps = {
|
||||
vm: HrPayslipOwnVM;
|
||||
submitting: boolean;
|
||||
actions: HrPayslipsActions;
|
||||
};
|
||||
|
||||
export function HrPayslipsPage({ vm, submitting, actions }: HrPayslipsPageProps) {
|
||||
const { t } = useTranslation();
|
||||
const rows = vm.data?.rows ?? [];
|
||||
|
||||
if (vm.status !== "ready" || !vm.data) {
|
||||
return <div className="flex w-full flex-col gap-6 p-6" data-ui-id="ui.hr.payslips" />;
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="flex w-full flex-col gap-6 p-6" data-ui-id="ui.hr.payslips">
|
||||
<div className="flex flex-col gap-0">
|
||||
<span className="text-heading-2 font-heading-2 text-text-neutral-primary">{t("hr.payslips.title")}</span>
|
||||
<span className="text-body-default-regular-150 font-body-default-regular-150 text-text-neutral-secondary">{t("hr.payslips.subtitle")}</span>
|
||||
</div>
|
||||
|
||||
{rows.length === 0 ? (
|
||||
<div data-ui-id="ui.hr.payslips.empty">
|
||||
<EmptyState title={t("hr.payslips.own.empty.headline")} body={t("hr.payslips.own.empty.body")} />
|
||||
</div>
|
||||
) : (
|
||||
<div className="w-full overflow-x-auto">
|
||||
<Table
|
||||
data-ui-id="ui.hr.payslips.list"
|
||||
header={
|
||||
<Table.HeaderRow>
|
||||
<Table.HeaderCell>{t("hr.payslips.column.period")}</Table.HeaderCell>
|
||||
<Table.HeaderCell> </Table.HeaderCell>
|
||||
<Table.HeaderCell> </Table.HeaderCell>
|
||||
</Table.HeaderRow>
|
||||
}
|
||||
>
|
||||
{rows.map((row) => (
|
||||
<Table.Row key={row.id} data-row-id={row.id} data-read={row.isRead}>
|
||||
<Table.Cell>
|
||||
<span className="text-body-default-medium-0 font-body-default-medium-0 text-text-neutral-primary">{row.periodLabel}</span>
|
||||
</Table.Cell>
|
||||
<Table.Cell>
|
||||
{!row.isRead ? (
|
||||
<BadgeFeedback farbe="subtle-warning" size="small">
|
||||
{t("hr.payslips.unread")}
|
||||
</BadgeFeedback>
|
||||
) : null}
|
||||
</Table.Cell>
|
||||
<Table.Cell>
|
||||
<div className="flex justify-end">
|
||||
<Button variant="tertiary" size="small" icon={<FeatherExternalLink />} loading={submitting} onClick={() => actions.onOpen(row.id)}>
|
||||
{t("hr.payslips.action.open")}
|
||||
</Button>
|
||||
</div>
|
||||
</Table.Cell>
|
||||
</Table.Row>
|
||||
))}
|
||||
</Table>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
+223
@@ -0,0 +1,223 @@
|
||||
// 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>
|
||||
);
|
||||
}
|
||||
+283
@@ -0,0 +1,283 @@
|
||||
// AK-P17b Interim-UI (AD-28) — sick-leave screen composed from ~/ui (D-HR "Krank",
|
||||
// archetype A2 + A4). Pure presentational: URL-driven tabs (own / office). The AU
|
||||
// certificate is sensitive — never rendered; a reveal action decrypts + opens it
|
||||
// on demand (route owns the fetch/open). Report / attach / close run through
|
||||
// injected actions. Final Subframe optics = tracked design-nachzug.
|
||||
|
||||
import { useState } from "react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { FeatherPlus } from "@subframe/core";
|
||||
import type { HrSickLeaveOfficeVM, HrSickLeaveOwnVM, HrSickLeaveRow } 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 { Tabs } from "~/ui/components/Tabs";
|
||||
import { TextInput } from "~/ui/components/TextInput";
|
||||
import { DateField } from "~/components/screens/tasks/DateField";
|
||||
|
||||
export type HrSickTab = "own" | "office";
|
||||
|
||||
export type HrSickActions = {
|
||||
onReport: (input: { startDate: string; expectedReturnDate: string }) => void;
|
||||
onReportFor: (input: { employeeUserId: string; startDate: string }) => void;
|
||||
onAttach: (reportId: string, certificateFileId: string) => void;
|
||||
onRevealCertificate: (reportId: string) => void;
|
||||
onClose: (reportId: string, returnDate: string) => void;
|
||||
};
|
||||
|
||||
export type HrSickPageProps = {
|
||||
tab: HrSickTab;
|
||||
canManage: boolean;
|
||||
ownVm: HrSickLeaveOwnVM;
|
||||
officeVm: HrSickLeaveOfficeVM;
|
||||
tabHref: (tab: HrSickTab) => string;
|
||||
submitting: boolean;
|
||||
actions: HrSickActions;
|
||||
};
|
||||
|
||||
type DialogState =
|
||||
| { type: "report" }
|
||||
| { type: "reportFor" }
|
||||
| { type: "attach"; reportId: string }
|
||||
| { type: "close"; reportId: string }
|
||||
| null;
|
||||
|
||||
function readDate(el: HTMLElement | null, name: string): string {
|
||||
return el?.querySelector<HTMLInputElement>(`input[name='${name}']`)?.value ?? "";
|
||||
}
|
||||
|
||||
export function HrSickPage({ tab, canManage, ownVm, officeVm, tabHref, submitting, actions }: HrSickPageProps) {
|
||||
const { t } = useTranslation();
|
||||
const [dialog, setDialog] = useState<DialogState>(null);
|
||||
const [text, setText] = useState("");
|
||||
|
||||
const tabs: HrSickTab[] = canManage ? ["own", "office"] : ["own"];
|
||||
const ownRows = ownVm.data?.rows ?? [];
|
||||
const officeRows = officeVm.data?.rows ?? [];
|
||||
|
||||
return (
|
||||
<div className="flex w-full flex-col gap-6 p-6" data-ui-id="ui.hr.sick">
|
||||
<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.sick.title")}</span>
|
||||
<span className="text-body-default-regular-150 font-body-default-regular-150 text-text-neutral-secondary">{t("hr.sick.subtitle")}</span>
|
||||
</div>
|
||||
{tab === "own" ? (
|
||||
<Button icon={<FeatherPlus />} onClick={() => setDialog({ type: "report" })} data-ui-id="ui.hr.sick.report">
|
||||
{t("hr.sick.action.report")}
|
||||
</Button>
|
||||
) : (
|
||||
<Button icon={<FeatherPlus />} onClick={() => setDialog({ type: "reportFor" })} data-ui-id="ui.hr.sick.reportFor">
|
||||
{t("hr.sick.action.reportFor")}
|
||||
</Button>
|
||||
)}
|
||||
</div>
|
||||
|
||||
<div data-ui-id="ui.hr.sick.tabs">
|
||||
<Tabs>
|
||||
{tabs.map((entry) => (
|
||||
<a key={entry} href={tabHref(entry)} className="contents no-underline">
|
||||
<Tabs.Item active={tab === entry}>{t(`hr.sick.tab.${entry}`)}</Tabs.Item>
|
||||
</a>
|
||||
))}
|
||||
</Tabs>
|
||||
</div>
|
||||
|
||||
{tab === "own" ? (
|
||||
ownRows.length === 0 ? (
|
||||
<div data-ui-id="ui.hr.sick.own.empty">
|
||||
<EmptyState title={t("hr.sick.own.empty.headline")} body={t("hr.sick.own.empty.body")} />
|
||||
</div>
|
||||
) : (
|
||||
<div className="flex w-full flex-col gap-3" data-ui-id="ui.hr.sick.own.list">
|
||||
{ownRows.map((row) => (
|
||||
<SickCard
|
||||
key={row.id}
|
||||
row={row}
|
||||
submitting={submitting}
|
||||
onReveal={() => actions.onRevealCertificate(row.id)}
|
||||
onAttach={() => { setText(""); setDialog({ type: "attach", reportId: row.id }); }}
|
||||
onClose={() => setDialog({ type: "close", reportId: row.id })}
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
)
|
||||
) : null}
|
||||
|
||||
{tab === "office" ? (
|
||||
officeRows.length === 0 ? (
|
||||
<div data-ui-id="ui.hr.sick.office.empty">
|
||||
<EmptyState title={t("hr.sick.office.empty.headline")} body={t("hr.sick.office.empty.body")} />
|
||||
</div>
|
||||
) : (
|
||||
<div className="flex w-full flex-col gap-2" data-ui-id="ui.hr.sick.office.list">
|
||||
{officeRows.map((row) => (
|
||||
<Card key={row.id} data-row-id={row.id}>
|
||||
<div className="flex w-full items-center justify-between gap-4">
|
||||
<span className="text-body-default-medium-0 font-body-default-medium-0 text-text-neutral-primary">{row.employeeLabel}</span>
|
||||
<div className="flex items-center gap-2">
|
||||
<span className="text-body-small-regular-0 font-body-small-regular-0 text-text-neutral-tertiary">{row.startDateIso}</span>
|
||||
<BadgeFeedback farbe="subtle-neutral" size="small">
|
||||
{t(row.statusLabelKey)}
|
||||
</BadgeFeedback>
|
||||
</div>
|
||||
</div>
|
||||
</Card>
|
||||
))}
|
||||
</div>
|
||||
)
|
||||
) : null}
|
||||
|
||||
{/* Report dialog (own or office) */}
|
||||
<Dialog open={dialog?.type === "report" || dialog?.type === "reportFor"} onOpenChange={(open) => !open && setDialog(null)}>
|
||||
<Dialog.Content className="w-full max-w-[560px] p-4" data-ui-id="ui.hr.sick.reportDialog">
|
||||
<div className="flex w-full flex-col gap-6 p-2">
|
||||
<span className="text-heading-3 font-heading-3 text-text-neutral-primary">
|
||||
{dialog?.type === "reportFor" ? t("hr.sick.action.reportFor") : t("hr.sick.action.report")}
|
||||
</span>
|
||||
<div className="flex w-full flex-col gap-4">
|
||||
{dialog?.type === "reportFor" ? (
|
||||
<TextInput label={t("hr.sick.field.employee")} showLabel fillContainer>
|
||||
<TextInput.Input value={text} onChange={(e) => setText(e.target.value)} />
|
||||
</TextInput>
|
||||
) : null}
|
||||
<div className="flex flex-wrap gap-4">
|
||||
<DateField label={t("hr.sick.field.start")} name="startDate" />
|
||||
{dialog?.type === "report" ? <DateField label={t("hr.sick.field.expectedReturn")} name="expectedReturnDate" /> : null}
|
||||
</div>
|
||||
</div>
|
||||
<div className="flex justify-end gap-2">
|
||||
<Button variant="neutral" onClick={() => setDialog(null)}>
|
||||
{t("hr.action.cancel")}
|
||||
</Button>
|
||||
<Button
|
||||
loading={submitting}
|
||||
onClick={(event) => {
|
||||
const el = (event.currentTarget as HTMLElement).closest("[data-ui-id='ui.hr.sick.reportDialog']");
|
||||
const start = readDate(el as HTMLElement, "startDate");
|
||||
if (!start) return;
|
||||
if (dialog?.type === "reportFor") {
|
||||
if (!text.trim()) return;
|
||||
actions.onReportFor({ employeeUserId: text, startDate: start });
|
||||
} else {
|
||||
actions.onReport({ startDate: start, expectedReturnDate: readDate(el as HTMLElement, "expectedReturnDate") });
|
||||
}
|
||||
setDialog(null);
|
||||
}}
|
||||
data-ui-id="ui.hr.sick.reportDialog.submit"
|
||||
>
|
||||
{t("hr.action.confirm")}
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
</Dialog.Content>
|
||||
</Dialog>
|
||||
|
||||
{/* Attach certificate dialog */}
|
||||
<Dialog open={dialog?.type === "attach"} onOpenChange={(open) => !open && setDialog(null)}>
|
||||
<Dialog.Content className="w-full max-w-[560px] p-4" data-ui-id="ui.hr.sick.attachDialog">
|
||||
<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.sick.action.attachCertificate")}</span>
|
||||
<TextInput label={t("hr.sick.field.certificateFileId")} showLabel fillContainer>
|
||||
<TextInput.Input value={text} onChange={(e) => setText(e.target.value)} />
|
||||
</TextInput>
|
||||
<div className="flex justify-end gap-2">
|
||||
<Button variant="neutral" onClick={() => setDialog(null)}>
|
||||
{t("hr.action.cancel")}
|
||||
</Button>
|
||||
<Button
|
||||
loading={submitting}
|
||||
disabled={text.trim().length === 0}
|
||||
onClick={() => {
|
||||
if (dialog?.type === "attach") actions.onAttach(dialog.reportId, text);
|
||||
setDialog(null);
|
||||
}}
|
||||
>
|
||||
{t("hr.action.confirm")}
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
</Dialog.Content>
|
||||
</Dialog>
|
||||
|
||||
{/* Close dialog */}
|
||||
<Dialog open={dialog?.type === "close"} onOpenChange={(open) => !open && setDialog(null)}>
|
||||
<Dialog.Content className="w-full max-w-[560px] p-4" data-ui-id="ui.hr.sick.closeDialog">
|
||||
<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.sick.action.close")}</span>
|
||||
<DateField label={t("hr.sick.field.returnDate")} name="returnDate" />
|
||||
<div className="flex justify-end gap-2">
|
||||
<Button variant="neutral" onClick={() => setDialog(null)}>
|
||||
{t("hr.action.cancel")}
|
||||
</Button>
|
||||
<Button
|
||||
loading={submitting}
|
||||
onClick={(event) => {
|
||||
const el = (event.currentTarget as HTMLElement).closest("[data-ui-id='ui.hr.sick.closeDialog']");
|
||||
const ret = readDate(el as HTMLElement, "returnDate");
|
||||
if (!ret || dialog?.type !== "close") return;
|
||||
actions.onClose(dialog.reportId, ret);
|
||||
setDialog(null);
|
||||
}}
|
||||
>
|
||||
{t("hr.action.confirm")}
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
</Dialog.Content>
|
||||
</Dialog>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function SickCard({
|
||||
row,
|
||||
submitting,
|
||||
onReveal,
|
||||
onAttach,
|
||||
onClose,
|
||||
}: {
|
||||
row: HrSickLeaveRow;
|
||||
submitting: boolean;
|
||||
onReveal: () => void;
|
||||
onAttach: () => void;
|
||||
onClose: () => void;
|
||||
}) {
|
||||
const { t } = useTranslation();
|
||||
return (
|
||||
<Card 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.startDateIso}
|
||||
{row.returnDateIso ? ` – ${row.returnDateIso}` : ""}
|
||||
</span>
|
||||
<span className="text-body-small-regular-0 font-body-small-regular-0 text-text-neutral-tertiary">
|
||||
{row.hasCertificate ? t("hr.sick.certificate.present") : t("hr.sick.certificate.missing")}
|
||||
</span>
|
||||
</div>
|
||||
<div className="flex items-center gap-2">
|
||||
<BadgeFeedback farbe="subtle-neutral" size="small">
|
||||
{t(row.statusLabelKey)}
|
||||
</BadgeFeedback>
|
||||
{row.hasCertificate ? (
|
||||
<Button variant="tertiary" size="small" loading={submitting} onClick={onReveal} data-ui-id="ui.hr.sick.reveal">
|
||||
{t("hr.sick.action.revealCertificate")}
|
||||
</Button>
|
||||
) : (
|
||||
<Button variant="tertiary" size="small" onClick={onAttach}>
|
||||
{t("hr.sick.action.attachCertificate")}
|
||||
</Button>
|
||||
)}
|
||||
{row.canClose ? (
|
||||
<Button variant="tertiary" size="small" onClick={onClose}>
|
||||
{t("hr.sick.action.close")}
|
||||
</Button>
|
||||
) : null}
|
||||
</div>
|
||||
</div>
|
||||
</Card>
|
||||
);
|
||||
}
|
||||
+188
@@ -0,0 +1,188 @@
|
||||
// AK-P17b Interim-UI (AD-28) — survey participation + item editor composed from
|
||||
// ~/ui (D-HR "Umfrage Teilnahme", archetype A3/A4). Pure presentational: answers
|
||||
// held in local state and submitted via the injected action (route maps them to
|
||||
// item:<id> form fields); managers add/remove items. Final Subframe optics =
|
||||
// tracked design-nachzug.
|
||||
|
||||
import { useState } from "react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { FeatherPlus } from "@subframe/core";
|
||||
import type { HrSurveyItem, HrSurveyItemType, HrSurveyParticipationVM } from "@hivegrid/view-models";
|
||||
import { Alert } from "~/ui/components/Alert";
|
||||
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 { Select } from "~/ui/components/Select";
|
||||
import { TextInput } from "~/ui/components/TextInput";
|
||||
|
||||
const ITEM_TYPES: readonly HrSurveyItemType[] = ["text", "rating_5", "nps", "choice", "boolean", "date"];
|
||||
|
||||
export type HrSurveyParticipationActions = {
|
||||
onSubmit: (answers: Record<string, string>) => void;
|
||||
onAddItem: (input: { itemType: string; prompt: string; options: string; required: boolean }) => void;
|
||||
onRemoveItem: (itemId: string) => void;
|
||||
};
|
||||
|
||||
export type HrSurveyParticipationPageProps = {
|
||||
vm: HrSurveyParticipationVM;
|
||||
canManage: boolean;
|
||||
status: string;
|
||||
submitting: boolean;
|
||||
actions: HrSurveyParticipationActions;
|
||||
};
|
||||
|
||||
// Controlled answer field per item type. Date uses a native input styled with the
|
||||
// ~/ui design tokens (same sanctioned exception as the tasks DateField).
|
||||
function AnswerField({ item, value, onChange }: { item: HrSurveyItem; value: string; onChange: (v: string) => void }) {
|
||||
if (item.itemType === "boolean") {
|
||||
return <Checkbox label="" checked={value === "true"} onCheckedChange={(c: boolean) => onChange(c ? "true" : "")} />;
|
||||
}
|
||||
if (item.itemType === "choice") {
|
||||
return (
|
||||
<Select value={value} onValueChange={onChange}>
|
||||
{item.options.map((o) => (
|
||||
<Select.Item key={o} value={o}>
|
||||
{o}
|
||||
</Select.Item>
|
||||
))}
|
||||
</Select>
|
||||
);
|
||||
}
|
||||
if (item.itemType === "date") {
|
||||
return (
|
||||
<input
|
||||
type="date"
|
||||
value={value}
|
||||
onChange={(e) => onChange(e.target.value)}
|
||||
className="h-9 rounded-[4px] border border-solid border-border-default bg-transparent px-3 text-body-default-regular-0 font-body-default-regular-0 text-text-neutral-primary outline-none"
|
||||
/>
|
||||
);
|
||||
}
|
||||
const numeric = item.itemType === "rating_5" || item.itemType === "nps";
|
||||
return (
|
||||
<TextInput fillContainer>
|
||||
<TextInput.Input type={numeric ? "number" : "text"} value={value} onChange={(e) => onChange(e.target.value)} />
|
||||
</TextInput>
|
||||
);
|
||||
}
|
||||
|
||||
export function HrSurveyParticipationPage({ vm, canManage, status, submitting, actions }: HrSurveyParticipationPageProps) {
|
||||
const { t } = useTranslation();
|
||||
const data = vm.data;
|
||||
const [answers, setAnswers] = useState<Record<string, string>>({});
|
||||
const [addOpen, setAddOpen] = useState(false);
|
||||
const [item, setItem] = useState({ itemType: "text", prompt: "", options: "", required: false });
|
||||
|
||||
if (vm.status !== "ready" || !data) {
|
||||
return <div className="flex w-full flex-col gap-6 p-6" data-ui-id="ui.hr.survey.participate" />;
|
||||
}
|
||||
|
||||
function addItem() {
|
||||
if (!item.prompt.trim()) return;
|
||||
actions.onAddItem(item);
|
||||
setAddOpen(false);
|
||||
setItem({ itemType: "text", prompt: "", options: "", required: false });
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="flex w-full flex-col gap-6 p-6" data-ui-id="ui.hr.survey.participate" data-row-id={data.surveyId}>
|
||||
<div className="flex flex-col gap-0">
|
||||
<span className="text-heading-2 font-heading-2 text-text-neutral-primary">{data.title}</span>
|
||||
{data.description ? (
|
||||
<span className="text-body-default-regular-150 font-body-default-regular-150 text-text-neutral-secondary">{data.description}</span>
|
||||
) : null}
|
||||
</div>
|
||||
|
||||
{data.isAnonymous ? <Alert variant="information" title={t(data.anonymousHintKey)} /> : null}
|
||||
|
||||
{data.alreadySubmitted ? (
|
||||
<div data-ui-id="ui.hr.survey.submitted">
|
||||
<Alert variant="success" title={t(data.submittedHintKey)} />
|
||||
</div>
|
||||
) : status === "open" ? (
|
||||
<Card>
|
||||
<div className="flex w-full flex-col gap-4" data-ui-id="ui.hr.survey.form">
|
||||
{data.items.map((surveyItem) => (
|
||||
<div key={surveyItem.id} className="flex flex-col gap-1" data-row-id={surveyItem.id}>
|
||||
<span className="text-body-default-medium-0 font-body-default-medium-0 text-text-neutral-primary">
|
||||
{surveyItem.prompt}
|
||||
{surveyItem.required ? " *" : ""}
|
||||
</span>
|
||||
<AnswerField
|
||||
item={surveyItem}
|
||||
value={answers[surveyItem.id] ?? ""}
|
||||
onChange={(v) => setAnswers((s) => ({ ...s, [surveyItem.id]: v }))}
|
||||
/>
|
||||
</div>
|
||||
))}
|
||||
<div className="flex justify-end">
|
||||
<Button loading={submitting} onClick={() => actions.onSubmit(answers)} data-ui-id="ui.hr.survey.submit">
|
||||
{t("hr.surveys.action.submit")}
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
</Card>
|
||||
) : (
|
||||
<div data-ui-id="ui.hr.survey.closed">
|
||||
<Alert variant="neutral" title={t("hr.surveys.notOpen")} />
|
||||
</div>
|
||||
)}
|
||||
|
||||
{canManage ? (
|
||||
<div className="flex w-full flex-col gap-3" data-ui-id="ui.hr.survey.editor">
|
||||
<div className="flex items-center justify-between">
|
||||
<span className="text-body-default-medium-0 font-body-default-medium-0 text-text-neutral-primary">{t("hr.surveys.editor.title")}</span>
|
||||
<Button variant="secondary" size="small" icon={<FeatherPlus />} onClick={() => setAddOpen(true)}>
|
||||
{t("hr.surveys.editor.add")}
|
||||
</Button>
|
||||
</div>
|
||||
{data.items.map((surveyItem) => (
|
||||
<Card key={`edit-${surveyItem.id}`}>
|
||||
<div className="flex w-full items-center justify-between gap-4">
|
||||
<span className="text-body-default-regular-0 font-body-default-regular-0 text-text-neutral-secondary">
|
||||
{t(surveyItem.typeLabelKey)} · {surveyItem.prompt}
|
||||
</span>
|
||||
<Button variant="tertiary" size="small" loading={submitting} onClick={() => actions.onRemoveItem(surveyItem.id)}>
|
||||
{t("hr.surveys.editor.remove")}
|
||||
</Button>
|
||||
</div>
|
||||
</Card>
|
||||
))}
|
||||
</div>
|
||||
) : null}
|
||||
|
||||
<Dialog open={addOpen} onOpenChange={setAddOpen}>
|
||||
<Dialog.Content className="w-full max-w-[560px] p-4" data-ui-id="ui.hr.survey.addItem">
|
||||
<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.surveys.editor.add")}</span>
|
||||
<div className="flex w-full flex-col gap-4">
|
||||
<Select label={t("hr.surveys.editor.itemType")} showLabel value={item.itemType} onValueChange={(v: string) => setItem((s) => ({ ...s, itemType: v }))}>
|
||||
{ITEM_TYPES.map((type) => (
|
||||
<Select.Item key={type} value={type}>
|
||||
{t(`hr.surveys.itemType.${type}`)}
|
||||
</Select.Item>
|
||||
))}
|
||||
</Select>
|
||||
<TextInput label={t("hr.surveys.editor.prompt")} showLabel fillContainer>
|
||||
<TextInput.Input value={item.prompt} onChange={(e) => setItem((s) => ({ ...s, prompt: e.target.value }))} />
|
||||
</TextInput>
|
||||
<TextInput label={t("hr.surveys.editor.options")} showLabel fillContainer>
|
||||
<TextInput.Input value={item.options} onChange={(e) => setItem((s) => ({ ...s, options: e.target.value }))} />
|
||||
</TextInput>
|
||||
<Checkbox label={t("hr.surveys.editor.required")} checked={item.required} onCheckedChange={(c: boolean) => setItem((s) => ({ ...s, required: c }))} />
|
||||
</div>
|
||||
<div className="flex justify-end gap-2">
|
||||
<Button variant="neutral" onClick={() => setAddOpen(false)}>
|
||||
{t("hr.action.cancel")}
|
||||
</Button>
|
||||
<Button loading={submitting} disabled={!item.prompt.trim()} onClick={addItem} data-ui-id="ui.hr.survey.addItem.submit">
|
||||
{t("hr.surveys.editor.add")}
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
</Dialog.Content>
|
||||
</Dialog>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
+87
@@ -0,0 +1,87 @@
|
||||
// AK-P17b Interim-UI (AD-28) — survey results composed from ~/ui (D-HR "Umfrage
|
||||
// Ergebnisse", archetype A3). Pure presentational: per-item distribution (bar) +
|
||||
// average + free-text responses. Final Subframe optics (richer charts) = tracked
|
||||
// design-nachzug.
|
||||
|
||||
import { useTranslation } from "react-i18next";
|
||||
import type { HrSurveyResultsVM } from "@hivegrid/view-models";
|
||||
import { BadgeFeedback } from "~/ui/components/BadgeFeedback";
|
||||
import { Card } from "~/ui/components/Card";
|
||||
import { EmptyState } from "~/ui/components/EmptyState";
|
||||
import { Progress } from "~/ui/components/Progress";
|
||||
|
||||
export type HrSurveyResultsPageProps = { vm: HrSurveyResultsVM };
|
||||
|
||||
export function HrSurveyResultsPage({ vm }: HrSurveyResultsPageProps) {
|
||||
const { t } = useTranslation();
|
||||
const data = vm.data;
|
||||
if (vm.status !== "ready" || !data) {
|
||||
return <div className="flex w-full flex-col gap-6 p-6" data-ui-id="ui.hr.survey.results" />;
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="flex w-full flex-col gap-6 p-6" data-ui-id="ui.hr.survey.results" data-row-id={data.surveyId}>
|
||||
<div className="flex flex-col gap-0">
|
||||
<span className="text-heading-2 font-heading-2 text-text-neutral-primary">{data.title}</span>
|
||||
<div className="flex items-center gap-2">
|
||||
<span className="text-body-default-regular-150 font-body-default-regular-150 text-text-neutral-secondary">
|
||||
{t("hr.surveys.results.count", { count: data.submissionCount })}
|
||||
</span>
|
||||
{data.isAnonymous ? (
|
||||
<BadgeFeedback farbe="subtle-neutral" size="small">
|
||||
{t("hr.surveys.anonymous")}
|
||||
</BadgeFeedback>
|
||||
) : null}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{data.submissionCount === 0 ? (
|
||||
<div data-ui-id="ui.hr.survey.results.empty">
|
||||
<EmptyState title={t("hr.surveys.results.empty.headline")} body={t("hr.surveys.results.empty.body")} />
|
||||
</div>
|
||||
) : (
|
||||
<div className="flex w-full flex-col gap-4" data-ui-id="ui.hr.survey.results.items">
|
||||
{data.items.map((item) => {
|
||||
const entries = Object.entries(item.distribution);
|
||||
const max = entries.reduce((m, [, count]) => Math.max(m, count), 0) || 1;
|
||||
return (
|
||||
<Card key={item.itemId} data-row-id={item.itemId}>
|
||||
<div className="flex w-full flex-col gap-2">
|
||||
<div className="flex items-center justify-between gap-3">
|
||||
<span className="text-body-default-medium-0 font-body-default-medium-0 text-text-neutral-primary">{item.prompt}</span>
|
||||
<span className="text-body-small-regular-0 font-body-small-regular-0 text-text-neutral-tertiary">
|
||||
{t("hr.surveys.results.responses", { count: item.responseCount })}
|
||||
{item.average != null ? ` · ⌀ ${item.average.toFixed(2)}` : ""}
|
||||
</span>
|
||||
</div>
|
||||
{entries.length > 0 ? (
|
||||
<div className="flex w-full flex-col gap-2">
|
||||
{entries.map(([key, count]) => (
|
||||
<div key={key} className="flex items-center gap-3">
|
||||
<span className="w-24 shrink-0 text-body-small-regular-0 font-body-small-regular-0 text-text-neutral-secondary">{key}</span>
|
||||
<div className="flex-1">
|
||||
<Progress value={(count / max) * 100} />
|
||||
</div>
|
||||
<span className="w-8 shrink-0 text-right text-body-small-regular-0 font-body-small-regular-0 text-text-neutral-tertiary">{count}</span>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
) : null}
|
||||
{item.textResponses.length > 0 ? (
|
||||
<div className="flex w-full flex-col gap-1">
|
||||
{item.textResponses.map((text, index) => (
|
||||
<span key={index} className="text-body-default-regular-150 font-body-default-regular-150 text-text-neutral-secondary">
|
||||
{`“${text}”`}
|
||||
</span>
|
||||
))}
|
||||
</div>
|
||||
) : null}
|
||||
</div>
|
||||
</Card>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
+149
@@ -0,0 +1,149 @@
|
||||
// AK-P17b Interim-UI (AD-28) — surveys list composed from ~/ui (D-HR "Umfragen",
|
||||
// archetype A2 + A5). Pure presentational: participate / results links; managers
|
||||
// create (Dialog) and open/close/archive via injected actions. Final Subframe
|
||||
// optics = tracked design-nachzug.
|
||||
|
||||
import { useState } from "react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { FeatherPlus } from "@subframe/core";
|
||||
import type { HrSurveyListVM } 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 { LinkButton } from "~/ui/components/LinkButton";
|
||||
import { Select } from "~/ui/components/Select";
|
||||
import { TextInput } from "~/ui/components/TextInput";
|
||||
|
||||
const VISIBILITIES = ["admins", "participants", "everyone"] as const;
|
||||
|
||||
export type HrSurveysListActions = {
|
||||
onCreate: (input: { title: string; description: string; isAnonymous: boolean; resultVisibility: string }) => void;
|
||||
onSetStatus: (surveyId: string, status: "open" | "close") => void;
|
||||
onArchive: (surveyId: string) => void;
|
||||
};
|
||||
|
||||
export type HrSurveysListPageProps = {
|
||||
vm: HrSurveyListVM;
|
||||
canManage: boolean;
|
||||
submitting: boolean;
|
||||
actions: HrSurveysListActions;
|
||||
};
|
||||
|
||||
export function HrSurveysListPage({ vm, canManage, submitting, actions }: HrSurveysListPageProps) {
|
||||
const { t } = useTranslation();
|
||||
const [open, setOpen] = useState(false);
|
||||
const [form, setForm] = useState({ title: "", description: "", isAnonymous: false, resultVisibility: "admins" });
|
||||
const rows = vm.data?.rows ?? [];
|
||||
|
||||
function submit() {
|
||||
if (!form.title.trim()) return;
|
||||
actions.onCreate(form);
|
||||
setOpen(false);
|
||||
setForm({ title: "", description: "", isAnonymous: false, resultVisibility: "admins" });
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="flex w-full flex-col gap-6 p-6" data-ui-id="ui.hr.surveys">
|
||||
<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.surveys.title")}</span>
|
||||
<span className="text-body-default-regular-150 font-body-default-regular-150 text-text-neutral-secondary">{t("hr.surveys.subtitle")}</span>
|
||||
</div>
|
||||
{canManage ? (
|
||||
<Button icon={<FeatherPlus />} onClick={() => setOpen(true)} data-ui-id="ui.hr.surveys.newBtn">
|
||||
{t("hr.surveys.action.create")}
|
||||
</Button>
|
||||
) : null}
|
||||
</div>
|
||||
|
||||
{rows.length === 0 ? (
|
||||
<div data-ui-id="ui.hr.surveys.empty">
|
||||
<EmptyState title={t("hr.surveys.empty.headline")} body={t("hr.surveys.empty.body")} />
|
||||
</div>
|
||||
) : (
|
||||
<div className="flex w-full flex-col gap-2" data-ui-id="ui.hr.surveys.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 items-center gap-2">
|
||||
<span className="text-body-default-medium-0 font-body-default-medium-0 text-text-neutral-primary">{row.title}</span>
|
||||
<BadgeFeedback farbe={row.status === "open" ? "subtle-positive" : "subtle-neutral"} size="small">
|
||||
{t(row.statusLabelKey)}
|
||||
</BadgeFeedback>
|
||||
{row.isAnonymous ? (
|
||||
<BadgeFeedback farbe="subtle-neutral" size="small">
|
||||
{t("hr.surveys.anonymous")}
|
||||
</BadgeFeedback>
|
||||
) : null}
|
||||
</div>
|
||||
<div className="flex items-center gap-2">
|
||||
{row.status === "open" && !row.hasSubmitted ? (
|
||||
<a href={row.participateHref} className="contents no-underline">
|
||||
<LinkButton variant="subtle">{t("hr.surveys.action.participate")}</LinkButton>
|
||||
</a>
|
||||
) : null}
|
||||
{row.canViewResults ? (
|
||||
<a href={row.resultsHref} className="contents no-underline">
|
||||
<LinkButton variant="subtle">{t("hr.surveys.action.results")}</LinkButton>
|
||||
</a>
|
||||
) : null}
|
||||
{canManage ? (
|
||||
<>
|
||||
{row.status !== "open" ? (
|
||||
<Button variant="tertiary" size="small" loading={submitting} onClick={() => actions.onSetStatus(row.id, "open")}>
|
||||
{t("hr.surveys.action.open")}
|
||||
</Button>
|
||||
) : (
|
||||
<Button variant="tertiary" size="small" loading={submitting} onClick={() => actions.onSetStatus(row.id, "close")}>
|
||||
{t("hr.surveys.action.close")}
|
||||
</Button>
|
||||
)}
|
||||
<a href={row.participateHref} className="contents no-underline">
|
||||
<LinkButton variant="subtle">{t("hr.surveys.action.edit")}</LinkButton>
|
||||
</a>
|
||||
</>
|
||||
) : null}
|
||||
</div>
|
||||
</div>
|
||||
</Card>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
|
||||
<Dialog open={open} onOpenChange={setOpen}>
|
||||
<Dialog.Content className="w-full max-w-[560px] p-4" data-ui-id="ui.hr.surveys.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.surveys.action.create")}</span>
|
||||
<div className="flex w-full flex-col gap-4">
|
||||
<TextInput label={t("hr.surveys.field.title")} showLabel fillContainer>
|
||||
<TextInput.Input value={form.title} onChange={(e) => setForm((s) => ({ ...s, title: e.target.value }))} />
|
||||
</TextInput>
|
||||
<TextInput label={t("hr.surveys.field.description")} showLabel fillContainer>
|
||||
<TextInput.Input value={form.description} onChange={(e) => setForm((s) => ({ ...s, description: e.target.value }))} />
|
||||
</TextInput>
|
||||
<Select label={t("hr.surveys.field.resultVisibility")} showLabel value={form.resultVisibility} onValueChange={(v: string) => setForm((s) => ({ ...s, resultVisibility: v }))}>
|
||||
{VISIBILITIES.map((v) => (
|
||||
<Select.Item key={v} value={v}>
|
||||
{t(`hr.surveys.visibility.${v}`)}
|
||||
</Select.Item>
|
||||
))}
|
||||
</Select>
|
||||
<Checkbox label={t("hr.surveys.field.anonymous")} checked={form.isAnonymous} onCheckedChange={(c: boolean) => setForm((s) => ({ ...s, isAnonymous: c }))} />
|
||||
</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.surveys.new.submit">
|
||||
{t("hr.surveys.action.create")}
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
</Dialog.Content>
|
||||
</Dialog>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
+64
@@ -0,0 +1,64 @@
|
||||
import { vi, describe, it, expect } from "vitest";
|
||||
import "@testing-library/jest-dom";
|
||||
import { render, fireEvent, waitFor } from "@testing-library/react";
|
||||
import { BrowserRouter as Router } from "react-router";
|
||||
import { buildVaultDetailVM } from "@hivegrid/view-models";
|
||||
|
||||
import { HrVaultDetailPage } from "./HrVaultDetailPage";
|
||||
|
||||
vi.mock("react-i18next", () => ({
|
||||
useTranslation: () => ({ t: (str: string) => str, i18n: { language: "de" } }),
|
||||
}));
|
||||
|
||||
function vault(overrides: Record<string, unknown> = {}) {
|
||||
return buildVaultDetailVM({
|
||||
vaultId: "v1",
|
||||
vaultName: "Team Vault",
|
||||
accessLevel: "admin",
|
||||
exportHref: "/acme/hr/password-safe/v1/export",
|
||||
rows: [
|
||||
{ id: "e1", title: "GitHub", tags: ["dev"], url: "https://github.com", hasUsername: true, hasPassword: true, hasNotes: false, revealHref: "/acme/hr/password-safe/v1/reveal" },
|
||||
],
|
||||
...overrides,
|
||||
});
|
||||
}
|
||||
|
||||
const noopActions = {
|
||||
onReveal: vi.fn(async () => null),
|
||||
onCreateEntry: vi.fn(),
|
||||
onArchiveEntry: vi.fn(),
|
||||
onGrantAccess: vi.fn(),
|
||||
};
|
||||
|
||||
describe("HrVaultDetailPage (interim-UI, security-critical)", () => {
|
||||
it("never renders secret values in the entry list — only reveal controls", () => {
|
||||
const { container, queryByText } = render(
|
||||
<Router>
|
||||
<HrVaultDetailPage vm={vault()} backHref=".." submitting={false} actions={noopActions} />
|
||||
</Router>,
|
||||
);
|
||||
// The entry surface renders...
|
||||
expect(container.querySelector('[data-row-id="e1"]')).toBeInTheDocument();
|
||||
// ...with reveal controls, but no plaintext secret anywhere before an explicit reveal.
|
||||
expect(container.querySelectorAll('[data-ui-id="ui.hr.vault.reveal"]').length).toBeGreaterThan(0);
|
||||
expect(queryByText("s3cret")).not.toBeInTheDocument();
|
||||
expect(container.querySelector('[data-ui-id="ui.hr.vault.revealed"]')).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("reveals a single field on demand via the injected onReveal action and then offers copy", async () => {
|
||||
const onReveal = vi.fn(async () => "s3cret");
|
||||
const { container, findByText } = render(
|
||||
<Router>
|
||||
<HrVaultDetailPage vm={vault()} backHref=".." submitting={false} actions={{ ...noopActions, onReveal }} />
|
||||
</Router>,
|
||||
);
|
||||
const revealBtn = container.querySelector('[data-ui-id="ui.hr.vault.reveal"]') as HTMLElement;
|
||||
fireEvent.click(revealBtn);
|
||||
await waitFor(() => expect(onReveal).toHaveBeenCalledWith("e1", "username"));
|
||||
// The plaintext now appears next to a copy control; the 30s clipboard wipe is
|
||||
// driven by that CopyToClipboardButton's onCopy (exercised end-to-end in the
|
||||
// browser — the Subframe copy primitive is not reliably triggerable in jsdom).
|
||||
expect(await findByText("s3cret")).toBeInTheDocument();
|
||||
expect(container.querySelector('[data-ui-id="ui.hr.vault.revealed"]')).toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
+318
@@ -0,0 +1,318 @@
|
||||
// AK-P17a Interim-UI (AD-28) — vault detail composed from ~/ui (D-HR
|
||||
// "Passwort-Safe Detail", archetype A3 + reveal). SECURITY-CRITICAL: secret
|
||||
// values are NEVER in the list — each entry shows only "hasX" flags. A value is
|
||||
// fetched ONLY on an explicit, audited reveal (route action) and, once copied, the
|
||||
// clipboard is wiped after copyAutoClearMs (30s, DoD #3). Create-entry / grant-
|
||||
// access run through injected actions. Final Subframe optics = design-nachzug.
|
||||
|
||||
import { useEffect, useRef, useState } from "react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { FeatherPlus } from "@subframe/core";
|
||||
import type { EntryRow, VaultDetailVM } from "@hivegrid/view-models";
|
||||
import { Breadcrumbs } from "~/ui/components/Breadcrumbs";
|
||||
import { Button } from "~/ui/components/Button";
|
||||
import { Card } from "~/ui/components/Card";
|
||||
import { CopyToClipboardButton } from "~/ui/components/CopyToClipboardButton";
|
||||
import { Dialog } from "~/ui/components/Dialog";
|
||||
import { EmptyState } from "~/ui/components/EmptyState";
|
||||
import { LinkButton } from "~/ui/components/LinkButton";
|
||||
import { Select } from "~/ui/components/Select";
|
||||
import { Tag_Label } from "~/ui/components/Tag_Label";
|
||||
import { TextInput } from "~/ui/components/TextInput";
|
||||
|
||||
export type VaultSecretField = "username" | "password" | "notes";
|
||||
export type VaultAccessLevel = "read" | "write" | "admin";
|
||||
|
||||
export type HrVaultDetailActions = {
|
||||
/** Reveal ONE field of ONE entry (audited server-side); resolves the plaintext. */
|
||||
onReveal: (entryId: string, field: VaultSecretField) => Promise<string | null>;
|
||||
onCreateEntry: (input: { title: string; url: string; username: string; password: string; notes: string }) => void;
|
||||
onArchiveEntry: (entryId: string) => void;
|
||||
onGrantAccess: (input: { targetUserId: string; permissionLevel: VaultAccessLevel }) => void;
|
||||
};
|
||||
|
||||
export type HrVaultDetailPageProps = {
|
||||
vm: VaultDetailVM;
|
||||
backHref: string;
|
||||
submitting: boolean;
|
||||
actions: HrVaultDetailActions;
|
||||
};
|
||||
|
||||
/** One revealable secret field: reveal on demand, copy, wipe clipboard after the
|
||||
* VM-supplied window (30s). The value is held only in local component state. */
|
||||
function SecretField({
|
||||
entryId,
|
||||
field,
|
||||
labelKey,
|
||||
autoClearMs,
|
||||
onReveal,
|
||||
}: {
|
||||
entryId: string;
|
||||
field: VaultSecretField;
|
||||
labelKey: string;
|
||||
autoClearMs: number;
|
||||
onReveal: HrVaultDetailActions["onReveal"];
|
||||
}) {
|
||||
const { t } = useTranslation();
|
||||
const [value, setValue] = useState<string | null>(null);
|
||||
const [loading, setLoading] = useState(false);
|
||||
const [copied, setCopied] = useState(false);
|
||||
const clearTimer = useRef<ReturnType<typeof setTimeout> | null>(null);
|
||||
|
||||
useEffect(() => () => {
|
||||
if (clearTimer.current) clearTimeout(clearTimer.current);
|
||||
}, []);
|
||||
|
||||
async function reveal() {
|
||||
setLoading(true);
|
||||
try {
|
||||
setValue(await onReveal(entryId, field));
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
}
|
||||
|
||||
function scheduleClipboardWipe() {
|
||||
setCopied(true);
|
||||
if (clearTimer.current) clearTimeout(clearTimer.current);
|
||||
clearTimer.current = setTimeout(() => {
|
||||
// Wipe the clipboard so a copied secret does not linger (DoD #3).
|
||||
void navigator.clipboard?.writeText("").catch(() => {});
|
||||
setCopied(false);
|
||||
}, autoClearMs);
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="flex items-center justify-between gap-3" data-ui-id={`ui.hr.vault.field.${field}`}>
|
||||
<span className="text-body-small-regular-0 font-body-small-regular-0 text-text-neutral-tertiary">{t(labelKey)}</span>
|
||||
{value === null ? (
|
||||
<Button variant="tertiary" size="small" loading={loading} onClick={reveal} data-ui-id="ui.hr.vault.reveal">
|
||||
{t("hr.passwordSafe.detail.reveal")}
|
||||
</Button>
|
||||
) : (
|
||||
<div className="flex items-center gap-2">
|
||||
<span className="font-mono text-body-default-regular-0 text-text-neutral-primary" data-ui-id="ui.hr.vault.revealed">
|
||||
{value}
|
||||
</span>
|
||||
<CopyToClipboardButton
|
||||
clipboardText={value}
|
||||
tooltipText={t("hr.passwordSafe.detail.copy")}
|
||||
onCopy={scheduleClipboardWipe}
|
||||
/>
|
||||
<Button variant="tertiary" size="small" onClick={() => setValue(null)}>
|
||||
{t("hr.passwordSafe.detail.hide")}
|
||||
</Button>
|
||||
</div>
|
||||
)}
|
||||
{copied ? (
|
||||
<span className="text-body-small-regular-0 font-body-small-regular-0 text-text-feedback-warning" data-ui-id="ui.hr.vault.copyHint">
|
||||
{t("hr.passwordSafe.detail.copyCleared")}
|
||||
</span>
|
||||
) : null}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function EntryCard({
|
||||
entry,
|
||||
autoClearMs,
|
||||
canWrite,
|
||||
submitting,
|
||||
onReveal,
|
||||
onArchive,
|
||||
}: {
|
||||
entry: EntryRow;
|
||||
autoClearMs: number;
|
||||
canWrite: boolean;
|
||||
submitting: boolean;
|
||||
onReveal: HrVaultDetailActions["onReveal"];
|
||||
onArchive: (entryId: string) => void;
|
||||
}) {
|
||||
const { t } = useTranslation();
|
||||
return (
|
||||
<Card data-row-id={entry.id}>
|
||||
<div className="flex w-full items-start 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">{entry.title}</span>
|
||||
{entry.url ? (
|
||||
<a href={entry.url} target="_blank" rel="noreferrer" className="text-body-small-regular-0 font-body-small-regular-0 text-text-feedback-link-default">
|
||||
{entry.url}
|
||||
</a>
|
||||
) : null}
|
||||
{entry.tags.length > 0 ? (
|
||||
<div className="flex flex-wrap items-center gap-1">
|
||||
{entry.tags.map((tag) => (
|
||||
<Tag_Label key={tag} tone="neutral-subtle" size="small" noAction>
|
||||
{tag}
|
||||
</Tag_Label>
|
||||
))}
|
||||
</div>
|
||||
) : null}
|
||||
</div>
|
||||
{canWrite ? (
|
||||
<Button variant="tertiary" size="small" loading={submitting} onClick={() => onArchive(entry.id)} data-ui-id="ui.hr.vault.archiveEntry">
|
||||
{t("hr.passwordSafe.detail.archiveEntry")}
|
||||
</Button>
|
||||
) : null}
|
||||
</div>
|
||||
<div className="flex w-full flex-col gap-2">
|
||||
{entry.hasUsername ? (
|
||||
<SecretField entryId={entry.id} field="username" labelKey="hr.passwordSafe.field.username" autoClearMs={autoClearMs} onReveal={onReveal} />
|
||||
) : null}
|
||||
{entry.hasPassword ? (
|
||||
<SecretField entryId={entry.id} field="password" labelKey="hr.passwordSafe.field.password" autoClearMs={autoClearMs} onReveal={onReveal} />
|
||||
) : null}
|
||||
{entry.hasNotes ? (
|
||||
<SecretField entryId={entry.id} field="notes" labelKey="hr.passwordSafe.field.notes" autoClearMs={autoClearMs} onReveal={onReveal} />
|
||||
) : null}
|
||||
</div>
|
||||
</Card>
|
||||
);
|
||||
}
|
||||
|
||||
export function HrVaultDetailPage({ vm, backHref, submitting, actions }: HrVaultDetailPageProps) {
|
||||
const { t } = useTranslation();
|
||||
const [entryOpen, setEntryOpen] = useState(false);
|
||||
const [accessOpen, setAccessOpen] = useState(false);
|
||||
const [entry, setEntry] = useState({ title: "", url: "", username: "", password: "", notes: "" });
|
||||
const [access, setAccess] = useState<{ targetUserId: string; permissionLevel: VaultAccessLevel }>({ targetUserId: "", permissionLevel: "read" });
|
||||
|
||||
if (vm.status !== "ready" || !vm.data) {
|
||||
return <div className="flex w-full flex-col gap-6 p-6" data-ui-id="ui.hr.vault" />;
|
||||
}
|
||||
|
||||
const { vaultName, rows, canWrite, canManageAccess, copyAutoClearMs, exportHref, emptyHeadlineKey, emptyBodyKey } = vm.data;
|
||||
|
||||
function submitEntry() {
|
||||
actions.onCreateEntry(entry);
|
||||
setEntryOpen(false);
|
||||
setEntry({ title: "", url: "", username: "", password: "", notes: "" });
|
||||
}
|
||||
function submitAccess() {
|
||||
actions.onGrantAccess(access);
|
||||
setAccessOpen(false);
|
||||
setAccess({ targetUserId: "", permissionLevel: "read" });
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="flex w-full flex-col gap-6 p-6" data-ui-id="ui.hr.vault">
|
||||
<Breadcrumbs>
|
||||
<a href={backHref} className="contents no-underline" data-ui-id="ui.hr.vault.back">
|
||||
<Breadcrumbs.Item>{t("hr.passwordSafe.detail.back")}</Breadcrumbs.Item>
|
||||
</a>
|
||||
<Breadcrumbs.Divider />
|
||||
<Breadcrumbs.Item active>{vaultName}</Breadcrumbs.Item>
|
||||
</Breadcrumbs>
|
||||
|
||||
<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">{vaultName}</span>
|
||||
<span className="text-body-default-regular-150 font-body-default-regular-150 text-text-neutral-secondary">
|
||||
{t("hr.passwordSafe.detail.subtitle")}
|
||||
</span>
|
||||
</div>
|
||||
<div className="flex items-center gap-2">
|
||||
<a href={exportHref} className="contents no-underline" data-ui-id="ui.hr.vault.export">
|
||||
<LinkButton variant="subtle">{t("hr.passwordSafe.detail.export")}</LinkButton>
|
||||
</a>
|
||||
{canManageAccess ? (
|
||||
<Button variant="secondary" onClick={() => setAccessOpen(true)} data-ui-id="ui.hr.vault.manageAccess">
|
||||
{t("hr.passwordSafe.detail.manageAccess")}
|
||||
</Button>
|
||||
) : null}
|
||||
{canWrite ? (
|
||||
<Button icon={<FeatherPlus />} onClick={() => setEntryOpen(true)} data-ui-id="ui.hr.vault.newEntry">
|
||||
{t("hr.passwordSafe.detail.newEntry")}
|
||||
</Button>
|
||||
) : null}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{rows.length === 0 ? (
|
||||
<div data-ui-id="ui.hr.vault.empty">
|
||||
<EmptyState title={t(emptyHeadlineKey)} body={t(emptyBodyKey)} />
|
||||
</div>
|
||||
) : (
|
||||
<div className="flex w-full flex-col gap-4" data-ui-id="ui.hr.vault.entries">
|
||||
{rows.map((row) => (
|
||||
<EntryCard
|
||||
key={row.id}
|
||||
entry={row}
|
||||
autoClearMs={copyAutoClearMs}
|
||||
canWrite={canWrite}
|
||||
submitting={submitting}
|
||||
onReveal={actions.onReveal}
|
||||
onArchive={actions.onArchiveEntry}
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* New entry dialog (canWrite) */}
|
||||
<Dialog open={entryOpen} onOpenChange={setEntryOpen}>
|
||||
<Dialog.Content className="w-full max-w-[560px] p-4" data-ui-id="ui.hr.vault.createEntry">
|
||||
<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.passwordSafe.detail.newEntry")}</span>
|
||||
<div className="flex w-full flex-col gap-4">
|
||||
<TextInput label={t("hr.passwordSafe.field.entryTitle")} showLabel fillContainer>
|
||||
<TextInput.Input value={entry.title} onChange={(e) => setEntry((s) => ({ ...s, title: e.target.value }))} data-ui-id="ui.hr.vault.createEntry.title" />
|
||||
</TextInput>
|
||||
<TextInput label={t("hr.passwordSafe.field.url")} showLabel fillContainer>
|
||||
<TextInput.Input value={entry.url} onChange={(e) => setEntry((s) => ({ ...s, url: e.target.value }))} />
|
||||
</TextInput>
|
||||
<TextInput label={t("hr.passwordSafe.field.username")} showLabel fillContainer>
|
||||
<TextInput.Input value={entry.username} onChange={(e) => setEntry((s) => ({ ...s, username: e.target.value }))} />
|
||||
</TextInput>
|
||||
<TextInput label={t("hr.passwordSafe.field.password")} showLabel fillContainer type="password">
|
||||
<TextInput.Input type="password" value={entry.password} onChange={(e) => setEntry((s) => ({ ...s, password: e.target.value }))} />
|
||||
</TextInput>
|
||||
<TextInput label={t("hr.passwordSafe.field.notes")} showLabel fillContainer>
|
||||
<TextInput.Input value={entry.notes} onChange={(e) => setEntry((s) => ({ ...s, notes: e.target.value }))} />
|
||||
</TextInput>
|
||||
</div>
|
||||
<div className="flex justify-end gap-2">
|
||||
<Button variant="neutral" onClick={() => setEntryOpen(false)}>
|
||||
{t("hr.action.cancel")}
|
||||
</Button>
|
||||
<Button loading={submitting} disabled={entry.title.trim().length === 0} onClick={submitEntry} data-ui-id="ui.hr.vault.createEntry.submit">
|
||||
{t("hr.passwordSafe.detail.createEntry.submit")}
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
</Dialog.Content>
|
||||
</Dialog>
|
||||
|
||||
{/* Grant access dialog (canManageAccess) */}
|
||||
<Dialog open={accessOpen} onOpenChange={setAccessOpen}>
|
||||
<Dialog.Content className="w-full max-w-[560px] p-4" data-ui-id="ui.hr.vault.grantAccess">
|
||||
<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.passwordSafe.detail.manageAccess")}</span>
|
||||
<div className="flex w-full flex-col gap-4">
|
||||
<TextInput label={t("hr.passwordSafe.field.targetUser")} showLabel fillContainer>
|
||||
<TextInput.Input value={access.targetUserId} onChange={(e) => setAccess((s) => ({ ...s, targetUserId: e.target.value }))} data-ui-id="ui.hr.vault.grantAccess.user" />
|
||||
</TextInput>
|
||||
<Select
|
||||
label={t("hr.passwordSafe.field.permissionLevel")}
|
||||
showLabel
|
||||
value={access.permissionLevel}
|
||||
onValueChange={(value: string) => setAccess((s) => ({ ...s, permissionLevel: value as VaultAccessLevel }))}
|
||||
>
|
||||
<Select.Item value="read">{t("hr.passwordSafe.access.read")}</Select.Item>
|
||||
<Select.Item value="write">{t("hr.passwordSafe.access.write")}</Select.Item>
|
||||
<Select.Item value="admin">{t("hr.passwordSafe.access.admin")}</Select.Item>
|
||||
</Select>
|
||||
</div>
|
||||
<div className="flex justify-end gap-2">
|
||||
<Button variant="neutral" onClick={() => setAccessOpen(false)}>
|
||||
{t("hr.action.cancel")}
|
||||
</Button>
|
||||
<Button loading={submitting} disabled={access.targetUserId.trim().length === 0} onClick={submitAccess} data-ui-id="ui.hr.vault.grantAccess.submit">
|
||||
{t("hr.passwordSafe.detail.grantAccess.submit")}
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
</Dialog.Content>
|
||||
</Dialog>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
+201
@@ -0,0 +1,201 @@
|
||||
// R-P5 Interim-UI (AD-28) — connect/reconnect wizard as a REAL ~/ui Dialog
|
||||
// (D-P5 "Connection-Setup-Wizard", archetype A5+A6, size M 720) with a
|
||||
// StepperHorizontal: prerequisites → auto-generated credential form (from the
|
||||
// app's connectionSchema, secret fields with reveal toggle) → review & connect.
|
||||
// Submit posts the existing connect/reconnect route action (adapter validation +
|
||||
// health check server-side). OAuth2 apps without credential fields show an
|
||||
// interim hint (the guided OAuth redirect ships with the module phases P14/P16).
|
||||
// Final Subframe optics land as a tracked design-nachzug once David's D-P5 ships.
|
||||
|
||||
import { useEffect, useState } from "react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { FeatherEye, FeatherEyeOff } from "@subframe/core";
|
||||
import type { AppCredentialField } from "@hivegrid/integrations";
|
||||
import { Alert } from "~/ui/components/Alert";
|
||||
import { Button } from "~/ui/components/Button";
|
||||
import { Dialog } from "~/ui/components/Dialog";
|
||||
import { IconButton } from "~/ui/components/IconButton";
|
||||
import { StepperHorizontal } from "~/ui/components/StepperHorizontal";
|
||||
import { TextInput } from "~/ui/components/TextInput";
|
||||
|
||||
export type ConnectWizardMode = { type: "connect" } | { type: "reconnect"; connectionId: string; label: string };
|
||||
|
||||
export type ConnectWizardSubmit = { label: string; credentials: Record<string, string> };
|
||||
|
||||
export type ConnectWizardDialogProps = {
|
||||
open: boolean;
|
||||
mode: ConnectWizardMode;
|
||||
appTitleKey: string;
|
||||
connectionType: string;
|
||||
credentialFields: readonly AppCredentialField[];
|
||||
submitting: boolean;
|
||||
errorMessage: string | null;
|
||||
onSubmit: (input: ConnectWizardSubmit) => void;
|
||||
onClose: () => void;
|
||||
};
|
||||
|
||||
const STEPS = ["prerequisites", "credentials", "confirm"] as const;
|
||||
|
||||
export function ConnectWizardDialog({ open, mode, appTitleKey, connectionType, credentialFields, submitting, errorMessage, onSubmit, onClose }: ConnectWizardDialogProps) {
|
||||
const { t } = useTranslation();
|
||||
const [step, setStep] = useState(0);
|
||||
const [label, setLabel] = useState(mode.type === "reconnect" ? mode.label : "");
|
||||
const [values, setValues] = useState<Record<string, string>>({});
|
||||
const [revealed, setRevealed] = useState<ReadonlySet<string>>(new Set());
|
||||
|
||||
// Reset the wizard whenever it (re)opens or the target changes (the parent
|
||||
// passes a fresh `mode` object per open, so state identity stays stable
|
||||
// across mere re-renders like submitting toggles).
|
||||
useEffect(() => {
|
||||
if (open) {
|
||||
setStep(0);
|
||||
setLabel(mode.type === "reconnect" ? mode.label : "");
|
||||
setValues({});
|
||||
setRevealed(new Set());
|
||||
}
|
||||
}, [open, mode]);
|
||||
|
||||
const isOauthWithoutForm = connectionType === "oauth2" && credentialFields.length === 0;
|
||||
const labelMissing = mode.type === "connect" && label.trim().length === 0;
|
||||
const requiredMissing = credentialFields.some((field) => field.required && !(values[field.name] ?? "").trim());
|
||||
const credentialsIncomplete = labelMissing || requiredMissing;
|
||||
|
||||
function toggleReveal(name: string) {
|
||||
setRevealed((prev) => {
|
||||
const next = new Set(prev);
|
||||
if (next.has(name)) next.delete(name);
|
||||
else next.add(name);
|
||||
return next;
|
||||
});
|
||||
}
|
||||
|
||||
function submit() {
|
||||
onSubmit({ label: label.trim(), credentials: values });
|
||||
}
|
||||
|
||||
return (
|
||||
<Dialog open={open} onOpenChange={(nextOpen: boolean) => (nextOpen ? undefined : onClose())}>
|
||||
<Dialog.Content className="w-[720px] max-w-[90vw] p-6">
|
||||
<div className="flex w-full flex-col gap-6" data-ui-id="ui.integrations.app.wizard">
|
||||
<div className="flex flex-col gap-2">
|
||||
<span className="text-heading-3 font-heading-3 text-text-neutral-primary">
|
||||
{mode.type === "reconnect" ? t("integrations.wizard.reconnectTitle", { app: t(appTitleKey) }) : t("integrations.wizard.title", { app: t(appTitleKey) })}
|
||||
</span>
|
||||
{errorMessage ? <Alert variant="error" title={t(errorMessage)} /> : null}
|
||||
</div>
|
||||
|
||||
<StepperHorizontal>
|
||||
{STEPS.map((key, index) => (
|
||||
<StepperHorizontal.Step
|
||||
key={key}
|
||||
firstStep={index === 0}
|
||||
lastStep={index === STEPS.length - 1}
|
||||
stepNumber={String(index + 1)}
|
||||
label={t(`integrations.wizard.step.${key}`)}
|
||||
variant={index === step ? "active" : index < step ? "completed" : "default"}
|
||||
/>
|
||||
))}
|
||||
</StepperHorizontal>
|
||||
|
||||
{step === 0 ? (
|
||||
<div className="flex w-full flex-col gap-2" data-wizard-step="prerequisites">
|
||||
<span className="text-body-default-regular-150 font-body-default-regular-150 text-text-neutral-secondary">
|
||||
{t("integrations.wizard.prerequisites.body", { app: t(appTitleKey) })}
|
||||
</span>
|
||||
{isOauthWithoutForm ? (
|
||||
<Alert variant="information" title={t("integrations.wizard.oauthHint")} />
|
||||
) : null}
|
||||
</div>
|
||||
) : null}
|
||||
|
||||
{step === 1 ? (
|
||||
<div className="flex w-full flex-col gap-4" data-wizard-step="credentials">
|
||||
{mode.type === "connect" ? (
|
||||
<TextInput className="w-full" label={t("integrations.wizard.label")} showLabel helpText={t("integrations.wizard.labelHelp")}>
|
||||
<TextInput.Input value={label} onChange={(event) => setLabel(event.target.value)} required data-ui-id="ui.integrations.app.wizard.label" />
|
||||
</TextInput>
|
||||
) : (
|
||||
<span className="text-body-default-regular-150 font-body-default-regular-150 text-text-neutral-secondary">
|
||||
{t("integrations.wizard.reconnectHint", { label: mode.label })}
|
||||
</span>
|
||||
)}
|
||||
{credentialFields.map((field) => {
|
||||
const isSecret = field.type === "secret";
|
||||
const shown = revealed.has(field.name);
|
||||
return (
|
||||
<TextInput
|
||||
key={field.name}
|
||||
className="w-full"
|
||||
label={t(field.labelKey)}
|
||||
showLabel
|
||||
type={isSecret && !shown ? "password" : "text"}
|
||||
iconRight={
|
||||
isSecret ? (
|
||||
<IconButton
|
||||
size="small"
|
||||
icon={shown ? <FeatherEyeOff /> : <FeatherEye />}
|
||||
onClick={() => toggleReveal(field.name)}
|
||||
aria-label={t(shown ? "integrations.wizard.hideSecret" : "integrations.wizard.revealSecret")}
|
||||
/>
|
||||
) : undefined
|
||||
}
|
||||
>
|
||||
<TextInput.Input
|
||||
type={isSecret && !shown ? "password" : "text"}
|
||||
value={values[field.name] ?? ""}
|
||||
onChange={(event) => setValues((prev) => ({ ...prev, [field.name]: event.target.value }))}
|
||||
required={field.required}
|
||||
data-wizard-field={field.name}
|
||||
/>
|
||||
</TextInput>
|
||||
);
|
||||
})}
|
||||
{credentialFields.length === 0 && !isOauthWithoutForm ? (
|
||||
<span className="text-body-default-regular-150 font-body-default-regular-150 text-text-neutral-secondary">
|
||||
{t("integrations.wizard.noFields")}
|
||||
</span>
|
||||
) : null}
|
||||
{isOauthWithoutForm ? <Alert variant="information" title={t("integrations.wizard.oauthHint")} /> : null}
|
||||
</div>
|
||||
) : null}
|
||||
|
||||
{step === 2 ? (
|
||||
<div className="flex w-full flex-col gap-2" data-wizard-step="confirm">
|
||||
<span className="text-body-default-regular-150 font-body-default-regular-150 text-text-neutral-secondary">
|
||||
{t("integrations.wizard.confirm.body")}
|
||||
</span>
|
||||
<span className="text-body-default-regular-0 font-body-default-regular-0 text-text-neutral-primary">
|
||||
{t("integrations.wizard.label")}: {mode.type === "reconnect" ? mode.label : label || "—"}
|
||||
</span>
|
||||
{credentialFields.map((field) => (
|
||||
<span key={field.name} className="text-body-default-regular-0 font-body-default-regular-0 text-text-neutral-secondary">
|
||||
{t(field.labelKey)}: {(values[field.name] ?? "").trim() ? (field.type === "secret" ? "••••••" : values[field.name]) : "—"}
|
||||
</span>
|
||||
))}
|
||||
</div>
|
||||
) : null}
|
||||
|
||||
<div className="flex w-full items-center justify-end gap-2">
|
||||
<Button variant="tertiary" onClick={onClose}>
|
||||
{t("shared.cancel")}
|
||||
</Button>
|
||||
{step > 0 ? (
|
||||
<Button variant="secondary" onClick={() => setStep(step - 1)}>
|
||||
{t("shared.back")}
|
||||
</Button>
|
||||
) : null}
|
||||
{step < STEPS.length - 1 ? (
|
||||
<Button disabled={step === 1 && credentialsIncomplete} onClick={() => setStep(step + 1)} data-ui-id="ui.integrations.app.wizard.next">
|
||||
{t("shared.next")}
|
||||
</Button>
|
||||
) : (
|
||||
<Button loading={submitting} disabled={credentialsIncomplete} onClick={submit} data-ui-id="ui.integrations.app.wizard.submit">
|
||||
{t("integrations.wizard.connect")}
|
||||
</Button>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</Dialog.Content>
|
||||
</Dialog>
|
||||
);
|
||||
}
|
||||
+72
@@ -0,0 +1,72 @@
|
||||
// R-P5 Interim-UI (AD-28) — reusable Connection-Card (D-P5: app card with status
|
||||
// traffic light, Klartext health hint, last sync time and the lifecycle buttons
|
||||
// Verbinden/Re-Sync/Reconnect/Trennen). All later app connections (P14/P15/P16/
|
||||
// P20) render through this card. Pure presentational; callbacks injected.
|
||||
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { Link } from "react-router";
|
||||
import type { ConnectionRow } from "@hivegrid/view-models";
|
||||
import { BadgeFeedback } from "~/ui/components/BadgeFeedback";
|
||||
import { Button } from "~/ui/components/Button";
|
||||
import { Card } from "~/ui/components/Card";
|
||||
import { LinkButton } from "~/ui/components/LinkButton";
|
||||
import { connectionStatusBadge } from "./integrationsBadges";
|
||||
|
||||
export type ConnectionCardProps = {
|
||||
row: ConnectionRow;
|
||||
canDisconnect: boolean;
|
||||
canManualSync: boolean;
|
||||
canReconnect: boolean;
|
||||
submitting: boolean;
|
||||
onManualSync: (connectionId: string) => void;
|
||||
onReconnect: (row: ConnectionRow) => void;
|
||||
onDisconnect: (row: ConnectionRow) => void;
|
||||
};
|
||||
|
||||
export function ConnectionCard({ row, canDisconnect, canManualSync, canReconnect, submitting, onManualSync, onReconnect, onDisconnect }: ConnectionCardProps) {
|
||||
const { t, i18n } = useTranslation();
|
||||
const dateFormatter = new Intl.DateTimeFormat(i18n.language, { dateStyle: "medium", timeStyle: "short" });
|
||||
const unhealthy = row.status === "degraded" || row.status === "broken";
|
||||
const revoked = row.status === "revoked";
|
||||
|
||||
return (
|
||||
<Card data-row-id={row.id} data-status={row.status} data-ui-id="ui.integrations.app.connectionCard">
|
||||
<div className="flex w-full flex-wrap items-start justify-between gap-2">
|
||||
<div className="flex flex-col gap-0">
|
||||
<span className="text-body-default-medium-0 font-body-default-medium-0 text-text-neutral-primary">{row.label}</span>
|
||||
{row.healthMessageKey ? (
|
||||
<span className="text-body-small-regular-150 font-body-small-regular-150 text-text-neutral-tertiary">{t(row.healthMessageKey)}</span>
|
||||
) : null}
|
||||
</div>
|
||||
<BadgeFeedback farbe={connectionStatusBadge(row.status)} size="small">
|
||||
{t(row.statusKey)}
|
||||
</BadgeFeedback>
|
||||
</div>
|
||||
<span className="text-body-small-regular-150 font-body-small-regular-150 text-text-neutral-tertiary">
|
||||
{t("integrations.connections.column.lastCheck")}: {row.lastHealthCheckIso ? dateFormatter.format(new Date(row.lastHealthCheckIso)) : "—"}
|
||||
</span>
|
||||
<div className="flex w-full flex-wrap items-center justify-between gap-2">
|
||||
<Link to={row.syncsHref} className="contents no-underline">
|
||||
<LinkButton variant="subtle">{t("integrations.connections.actions.history")}</LinkButton>
|
||||
</Link>
|
||||
<div className="flex flex-wrap items-center gap-2">
|
||||
{canManualSync && !revoked ? (
|
||||
<Button variant="secondary" size="small" loading={submitting} onClick={() => onManualSync(row.id)} data-ui-id="ui.integrations.app.resync">
|
||||
{t("integrations.connections.actions.resync")}
|
||||
</Button>
|
||||
) : null}
|
||||
{canReconnect && (unhealthy || revoked) ? (
|
||||
<Button variant="secondary" size="small" onClick={() => onReconnect(row)} data-ui-id="ui.integrations.app.reconnect">
|
||||
{t("integrations.connections.actions.reconnect")}
|
||||
</Button>
|
||||
) : null}
|
||||
{canDisconnect && !revoked ? (
|
||||
<Button variant="destructive" size="small" onClick={() => onDisconnect(row)} data-ui-id="ui.integrations.app.disconnect">
|
||||
{t("integrations.connections.actions.disconnect")}
|
||||
</Button>
|
||||
) : null}
|
||||
</div>
|
||||
</div>
|
||||
</Card>
|
||||
);
|
||||
}
|
||||
+177
@@ -0,0 +1,177 @@
|
||||
// R-P5 Interim-UI (AD-28) — per-app connection management screen composed from
|
||||
// ~/ui (D-P5 "App-Detail / Connection-Verwaltung", archetype A6+A2). Pure
|
||||
// presentational: renders the server-built ConnectionDetailVM and reports the
|
||||
// lifecycle mutations (connect / reconnect / disconnect / manual re-sync)
|
||||
// through injected actions — the route owns the fetcher. Degraded/broken
|
||||
// connections raise a screen banner with a reconnect solution button (D-P5
|
||||
// Klartext requirement). Final Subframe optics = tracked design-nachzug.
|
||||
|
||||
import { useEffect, useState } from "react";
|
||||
import { Link } from "react-router";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { FeatherPlus } from "@subframe/core";
|
||||
import type { AppCredentialField } from "@hivegrid/integrations";
|
||||
import type { ConnectionDetailVM, ConnectionRow } from "@hivegrid/view-models";
|
||||
import { Alert } from "~/ui/components/Alert";
|
||||
import { Button } from "~/ui/components/Button";
|
||||
import { Dialog } from "~/ui/components/Dialog";
|
||||
import { EmptyState } from "~/ui/components/EmptyState";
|
||||
import { LinkButton } from "~/ui/components/LinkButton";
|
||||
import { ConnectionCard } from "./ConnectionCard";
|
||||
import { ConnectWizardDialog, type ConnectWizardMode, type ConnectWizardSubmit } from "./ConnectWizardDialog";
|
||||
|
||||
export type ConnectionDetailActions = {
|
||||
/** POSTs intent=connect to the app route action. */
|
||||
onConnect: (input: ConnectWizardSubmit) => void;
|
||||
/** POSTs intent=reconnect (same connection id, no history loss). */
|
||||
onReconnect: (connectionId: string, input: ConnectWizardSubmit) => void;
|
||||
/** POSTs intent=disconnect (status revoked, no hard delete). */
|
||||
onDisconnect: (connectionId: string) => void;
|
||||
/** POSTs intent=manual-sync. */
|
||||
onManualSync: (connectionId: string) => void;
|
||||
};
|
||||
|
||||
export type ConnectionDetailPageProps = {
|
||||
vm: ConnectionDetailVM;
|
||||
connectionType: string;
|
||||
credentialFields: readonly AppCredentialField[];
|
||||
backHref: string;
|
||||
actions: ConnectionDetailActions;
|
||||
submitting: boolean;
|
||||
errorMessage: string | null;
|
||||
/** Increments after a successful mutation — closes any open dialog. */
|
||||
closeSignal: number;
|
||||
};
|
||||
|
||||
type WizardState = ConnectWizardMode | null;
|
||||
|
||||
export function ConnectionDetailPage({ vm, connectionType, credentialFields, backHref, actions, submitting, errorMessage, closeSignal }: ConnectionDetailPageProps) {
|
||||
const { t } = useTranslation();
|
||||
const [wizard, setWizard] = useState<WizardState>(null);
|
||||
const [disconnectRow, setDisconnectRow] = useState<ConnectionRow | null>(null);
|
||||
|
||||
useEffect(() => {
|
||||
if (closeSignal > 0) {
|
||||
setWizard(null);
|
||||
setDisconnectRow(null);
|
||||
}
|
||||
}, [closeSignal]);
|
||||
|
||||
if (vm.status !== "ready" || !vm.data) {
|
||||
return <div className="flex w-full flex-col gap-6 p-6" data-ui-id="ui.integrations.app" />;
|
||||
}
|
||||
|
||||
const { appTitleKey, rows, canConnect, canDisconnect, canManualSync, emptyHeadlineKey, emptyBodyKey } = vm.data;
|
||||
const unhealthy = rows.filter((row) => row.status === "degraded" || row.status === "broken");
|
||||
|
||||
return (
|
||||
<div className="flex w-full flex-col gap-6 p-6" data-ui-id="ui.integrations.app">
|
||||
{/* Breadcrumb back to the catalog (DoD B9) + header with connect CTA */}
|
||||
<Link to={backHref} className="contents no-underline" data-ui-id="ui.integrations.app.back">
|
||||
<LinkButton variant="subtle">{t("integrations.connections.back")}</LinkButton>
|
||||
</Link>
|
||||
<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(appTitleKey)}</span>
|
||||
<span className="text-body-default-regular-150 font-body-default-regular-150 text-text-neutral-secondary">
|
||||
{t("integrations.connections.subtitle")}
|
||||
</span>
|
||||
</div>
|
||||
{canConnect ? (
|
||||
<Button icon={<FeatherPlus />} onClick={() => setWizard({ type: "connect" })} data-ui-id="ui.integrations.app.connect">
|
||||
{t("integrations.connections.add")}
|
||||
</Button>
|
||||
) : null}
|
||||
</div>
|
||||
|
||||
{/* Screen banner (hierarchy §8): at least one degraded/broken connection. */}
|
||||
{unhealthy.length > 0 ? (
|
||||
<Alert
|
||||
variant={unhealthy.some((row) => row.status === "broken") ? "error" : "warning"}
|
||||
title={t("integrations.connections.banner.title", { count: unhealthy.length })}
|
||||
description={unhealthy[0].healthMessageKey ? t(unhealthy[0].healthMessageKey) : undefined}
|
||||
actions={
|
||||
canConnect ? (
|
||||
<Button variant="secondary" size="small" onClick={() => setWizard({ type: "reconnect", connectionId: unhealthy[0].id, label: unhealthy[0].label })}>
|
||||
{t("integrations.connections.actions.reconnect")}
|
||||
</Button>
|
||||
) : undefined
|
||||
}
|
||||
data-ui-id="ui.integrations.app.banner"
|
||||
/>
|
||||
) : null}
|
||||
|
||||
{rows.length === 0 ? (
|
||||
<div className="flex w-full flex-col items-center gap-4" data-ui-id="ui.integrations.app.empty">
|
||||
<EmptyState title={t(emptyHeadlineKey)} body={t(emptyBodyKey)} />
|
||||
{canConnect ? (
|
||||
<Button icon={<FeatherPlus />} onClick={() => setWizard({ type: "connect" })}>
|
||||
{t("integrations.connections.add")}
|
||||
</Button>
|
||||
) : null}
|
||||
</div>
|
||||
) : (
|
||||
<div className="grid w-full grid-cols-1 gap-4 lg:grid-cols-2" data-ui-id="ui.integrations.app.list">
|
||||
{rows.map((row) => (
|
||||
<ConnectionCard
|
||||
key={row.id}
|
||||
row={row}
|
||||
canDisconnect={canDisconnect}
|
||||
canManualSync={canManualSync}
|
||||
canReconnect={canConnect}
|
||||
submitting={submitting}
|
||||
onManualSync={actions.onManualSync}
|
||||
onReconnect={(target) => setWizard({ type: "reconnect", connectionId: target.id, label: target.label })}
|
||||
onDisconnect={setDisconnectRow}
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* Connect/Reconnect wizard (A5, M 720) */}
|
||||
{wizard ? (
|
||||
<ConnectWizardDialog
|
||||
open
|
||||
mode={wizard}
|
||||
appTitleKey={appTitleKey}
|
||||
connectionType={connectionType}
|
||||
credentialFields={credentialFields}
|
||||
submitting={submitting}
|
||||
errorMessage={errorMessage}
|
||||
onSubmit={(input) => {
|
||||
if (wizard.type === "reconnect") actions.onReconnect(wizard.connectionId, input);
|
||||
else actions.onConnect(input);
|
||||
}}
|
||||
onClose={() => setWizard(null)}
|
||||
/>
|
||||
) : null}
|
||||
|
||||
{/* Disconnect confirm (XS 420, Klartext: sync jobs stop, history preserved) */}
|
||||
<Dialog open={disconnectRow !== null} onOpenChange={(open: boolean) => (open ? undefined : setDisconnectRow(null))}>
|
||||
<Dialog.Content className="w-[420px] max-w-[90vw] p-4">
|
||||
{disconnectRow ? (
|
||||
<div className="flex w-full flex-col gap-6" data-ui-id="ui.integrations.app.disconnectConfirm">
|
||||
<div className="flex flex-col gap-2">
|
||||
<span className="text-heading-3 font-heading-3 text-text-neutral-primary">{t("integrations.disconnect.title", { label: disconnectRow.label })}</span>
|
||||
<span className="text-body-default-regular-150 font-body-default-regular-150 text-text-neutral-secondary">
|
||||
{t("integrations.disconnect.description")}
|
||||
</span>
|
||||
{errorMessage ? <Alert variant="error" title={t(errorMessage)} /> : null}
|
||||
</div>
|
||||
<div className="flex w-full items-center justify-end gap-2">
|
||||
<Button variant="tertiary" onClick={() => setDisconnectRow(null)}>
|
||||
{t("shared.cancel")}
|
||||
</Button>
|
||||
<Button variant="destructive" loading={submitting} onClick={() => actions.onDisconnect(disconnectRow.id)} data-ui-id="ui.integrations.app.disconnectSubmit">
|
||||
{t("integrations.connections.actions.disconnect")}
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
) : (
|
||||
<div />
|
||||
)}
|
||||
</Dialog.Content>
|
||||
</Dialog>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
+93
@@ -0,0 +1,93 @@
|
||||
// R-P5 Interim-UI (AD-28) — integrations catalog preview screen composed from
|
||||
// ~/ui (D-P5 "Integrations-Katalog", archetype A6). Pure presentational: renders
|
||||
// the server-built IntegrationCatalogVM passed as a prop; navigation only, no
|
||||
// mutations. App cards grouped by category with a status light (connection
|
||||
// count) and a client-side search filter. Final Subframe optics land as a
|
||||
// tracked design-nachzug once David's D-P5 ships.
|
||||
|
||||
import { useState } from "react";
|
||||
import { Link } from "react-router";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import type { CatalogAppRow, IntegrationCatalogVM } from "@hivegrid/view-models";
|
||||
import { BadgeFeedback } from "~/ui/components/BadgeFeedback";
|
||||
import { Card } from "~/ui/components/Card";
|
||||
import { EmptyState } from "~/ui/components/EmptyState";
|
||||
import { SearchInput } from "~/ui/components/SearchInput";
|
||||
|
||||
export type IntegrationsCatalogPageProps = {
|
||||
vm: IntegrationCatalogVM;
|
||||
};
|
||||
|
||||
export function IntegrationsCatalogPage({ vm }: IntegrationsCatalogPageProps) {
|
||||
const { t } = useTranslation();
|
||||
const [query, setQuery] = useState("");
|
||||
|
||||
if (vm.status !== "ready" || !vm.data) {
|
||||
return <div className="flex w-full flex-col gap-6 p-6" data-ui-id="ui.integrations.catalog" />;
|
||||
}
|
||||
|
||||
const { rows, emptyHeadlineKey, emptyBodyKey } = vm.data;
|
||||
const needle = query.trim().toLowerCase();
|
||||
const visible = needle ? rows.filter((row) => t(row.titleKey).toLowerCase().includes(needle) || t(row.categoryKey).toLowerCase().includes(needle)) : rows;
|
||||
|
||||
// Group by category (stable order: first appearance in the catalog).
|
||||
const groups: { categoryKey: string; rows: CatalogAppRow[] }[] = [];
|
||||
for (const row of visible) {
|
||||
const group = groups.find((entry) => entry.categoryKey === row.categoryKey);
|
||||
if (group) group.rows.push(row);
|
||||
else groups.push({ categoryKey: row.categoryKey, rows: [row] });
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="flex w-full flex-col gap-6 p-6" data-ui-id="ui.integrations.catalog">
|
||||
{/* Header: title + subtitle (0px rhythm) */}
|
||||
<div className="flex flex-col gap-0">
|
||||
<span className="text-heading-2 font-heading-2 text-text-neutral-primary">{t("integrations.catalog.title")}</span>
|
||||
<span className="text-body-default-regular-150 font-body-default-regular-150 text-text-neutral-secondary">
|
||||
{t("integrations.catalog.subtitle")}
|
||||
</span>
|
||||
</div>
|
||||
|
||||
<SearchInput
|
||||
className="max-w-[320px]"
|
||||
placeholder={t("integrations.catalog.searchPlaceholder")}
|
||||
hideShortcut
|
||||
value={query}
|
||||
onChange={(event) => setQuery(event.target.value)}
|
||||
/>
|
||||
|
||||
{rows.length === 0 ? (
|
||||
<div data-ui-id="ui.integrations.catalog.empty">
|
||||
<EmptyState title={t(emptyHeadlineKey)} body={t(emptyBodyKey)} />
|
||||
</div>
|
||||
) : visible.length === 0 ? (
|
||||
<EmptyState variant="no-results" title={t("integrations.catalog.noMatches")} body={t(emptyBodyKey)} />
|
||||
) : (
|
||||
<div className="flex w-full flex-col gap-6" data-ui-id="ui.integrations.catalog.list">
|
||||
{groups.map((group) => (
|
||||
<div key={group.categoryKey} className="flex w-full flex-col gap-3" data-catalog-category={group.categoryKey}>
|
||||
<span className="text-body-default-medium-0 font-body-default-medium-0 text-text-neutral-primary">{t(group.categoryKey)}</span>
|
||||
<div className="grid w-full grid-cols-1 gap-4 sm:grid-cols-2 lg:grid-cols-3">
|
||||
{group.rows.map((row) => (
|
||||
<Link key={row.key} to={row.detailHref} className="contents no-underline" data-row-id={row.key}>
|
||||
<Card>
|
||||
<div className="flex w-full items-start justify-between gap-2">
|
||||
<span className="text-body-default-medium-0 font-body-default-medium-0 text-text-neutral-primary">{t(row.titleKey)}</span>
|
||||
<BadgeFeedback farbe={row.connectionCount > 0 ? "subtle-positive" : "subtle-neutral"} size="small">
|
||||
{t("integrations.catalog.connectionCount", { count: row.connectionCount })}
|
||||
</BadgeFeedback>
|
||||
</div>
|
||||
<span className="text-body-small-regular-150 font-body-small-regular-150 text-text-neutral-tertiary">
|
||||
{t(row.categoryKey)} · {t(`integrations.catalog.connectionType.${row.connectionType}`)}
|
||||
</span>
|
||||
</Card>
|
||||
</Link>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
+163
@@ -0,0 +1,163 @@
|
||||
// R-P5 Interim-UI (AD-28) — sync history screen composed from ~/ui (D-P5
|
||||
// "Sync-History", archetype A2): AppSyncRun table with Klartext summary,
|
||||
// client-side status/kind filters, manual re-sync trigger and a link into the
|
||||
// run detail. Pure presentational; the route owns the fetcher. Final Subframe
|
||||
// optics = tracked design-nachzug.
|
||||
|
||||
import { useState } from "react";
|
||||
import { Link } from "react-router";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import type { SyncHistoryVM, SyncKind, SyncStatus } from "@hivegrid/view-models";
|
||||
import { BadgeFeedback } from "~/ui/components/BadgeFeedback";
|
||||
import { Button } from "~/ui/components/Button";
|
||||
import { EmptyState } from "~/ui/components/EmptyState";
|
||||
import { LinkButton } from "~/ui/components/LinkButton";
|
||||
import { Select } from "~/ui/components/Select";
|
||||
import { Table } from "~/ui/components/Table";
|
||||
import { syncStatusBadge } from "./integrationsBadges";
|
||||
|
||||
const FILTER_ALL = "__all__";
|
||||
const STATUSES: readonly SyncStatus[] = ["pending", "running", "completed", "partial", "failed", "cancelled"];
|
||||
const KINDS: readonly SyncKind[] = ["manual", "scheduled", "webhook"];
|
||||
|
||||
export type SyncHistoryActions = {
|
||||
/** POSTs intent=manual-sync for this connection (app route action). */
|
||||
onManualSync: (connectionId: string) => void;
|
||||
};
|
||||
|
||||
export type SyncHistoryPageProps = {
|
||||
vm: SyncHistoryVM;
|
||||
backHref: string;
|
||||
/** Base path of this connection's syncs route; run detail = `${base}/${runId}`. */
|
||||
runHrefBase: string;
|
||||
actions: SyncHistoryActions;
|
||||
submitting: boolean;
|
||||
};
|
||||
|
||||
export function SyncHistoryPage({ vm, backHref, runHrefBase, actions, submitting }: SyncHistoryPageProps) {
|
||||
const { t, i18n } = useTranslation();
|
||||
const [status, setStatus] = useState<SyncStatus | null>(null);
|
||||
const [kind, setKind] = useState<SyncKind | null>(null);
|
||||
|
||||
if (vm.status !== "ready" || !vm.data) {
|
||||
return <div className="flex w-full flex-col gap-6 p-6" data-ui-id="ui.integrations.syncs" />;
|
||||
}
|
||||
|
||||
const { connectionId, rows, canManualSync, emptyHeadlineKey, emptyBodyKey } = vm.data;
|
||||
const dateFormatter = new Intl.DateTimeFormat(i18n.language, { dateStyle: "medium", timeStyle: "short" });
|
||||
const visible = rows.filter((row) => (status ? row.status === status : true) && (kind ? row.kind === kind : true));
|
||||
|
||||
return (
|
||||
<div className="flex w-full flex-col gap-6 p-6" data-ui-id="ui.integrations.syncs">
|
||||
{/* Breadcrumb back to the connection management (DoD B9) + header */}
|
||||
<Link to={backHref} className="contents no-underline" data-ui-id="ui.integrations.syncs.back">
|
||||
<LinkButton variant="subtle">{t("integrations.syncs.back")}</LinkButton>
|
||||
</Link>
|
||||
<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("integrations.syncs.title")}</span>
|
||||
<span className="text-body-default-regular-150 font-body-default-regular-150 text-text-neutral-secondary">
|
||||
{t("integrations.syncs.subtitle")}
|
||||
</span>
|
||||
</div>
|
||||
{canManualSync ? (
|
||||
<Button loading={submitting} onClick={() => actions.onManualSync(connectionId)} data-ui-id="ui.integrations.syncs.resync">
|
||||
{t("integrations.connections.actions.resync")}
|
||||
</Button>
|
||||
) : null}
|
||||
</div>
|
||||
|
||||
{/* Filters: status / kind (client-side, A2) */}
|
||||
<div className="flex flex-wrap items-end gap-4" data-ui-id="ui.integrations.syncs.filter">
|
||||
<Select
|
||||
className="max-w-[200px]"
|
||||
label={t("integrations.syncs.column.status")}
|
||||
showLabel
|
||||
value={status ?? FILTER_ALL}
|
||||
onValueChange={(value: string) => setStatus(value === FILTER_ALL ? null : (value as SyncStatus))}
|
||||
>
|
||||
<Select.Item value={FILTER_ALL}>{t("integrations.syncs.filter.all")}</Select.Item>
|
||||
{STATUSES.map((entry) => (
|
||||
<Select.Item key={entry} value={entry}>
|
||||
{t(`integrations.syncStatus.${entry}`)}
|
||||
</Select.Item>
|
||||
))}
|
||||
</Select>
|
||||
<Select
|
||||
className="max-w-[200px]"
|
||||
label={t("integrations.syncs.column.kind")}
|
||||
showLabel
|
||||
value={kind ?? FILTER_ALL}
|
||||
onValueChange={(value: string) => setKind(value === FILTER_ALL ? null : (value as SyncKind))}
|
||||
>
|
||||
<Select.Item value={FILTER_ALL}>{t("integrations.syncs.filter.all")}</Select.Item>
|
||||
{KINDS.map((entry) => (
|
||||
<Select.Item key={entry} value={entry}>
|
||||
{t(`integrations.syncKind.${entry}`)}
|
||||
</Select.Item>
|
||||
))}
|
||||
</Select>
|
||||
</div>
|
||||
|
||||
{rows.length === 0 ? (
|
||||
<div data-ui-id="ui.integrations.syncs.empty">
|
||||
<EmptyState title={t(emptyHeadlineKey)} body={t(emptyBodyKey)} />
|
||||
</div>
|
||||
) : visible.length === 0 ? (
|
||||
<EmptyState variant="no-results" title={t("integrations.syncs.noMatches")} body={t(emptyBodyKey)} />
|
||||
) : (
|
||||
<div className="w-full overflow-x-auto">
|
||||
<Table
|
||||
data-ui-id="ui.integrations.syncs.table"
|
||||
header={
|
||||
<Table.HeaderRow>
|
||||
<Table.HeaderCell>{t("integrations.syncs.column.started")}</Table.HeaderCell>
|
||||
<Table.HeaderCell>{t("integrations.syncs.column.kind")}</Table.HeaderCell>
|
||||
<Table.HeaderCell>{t("integrations.syncs.column.status")}</Table.HeaderCell>
|
||||
<Table.HeaderCell>{t("integrations.syncs.column.items")}</Table.HeaderCell>
|
||||
<Table.HeaderCell>{t("integrations.syncs.column.summary")}</Table.HeaderCell>
|
||||
<Table.HeaderCell> </Table.HeaderCell>
|
||||
</Table.HeaderRow>
|
||||
}
|
||||
>
|
||||
{visible.map((row) => (
|
||||
<Table.Row key={row.id} data-row-id={row.id} data-status={row.status}>
|
||||
<Table.Cell>
|
||||
<span className="whitespace-nowrap text-body-default-regular-0 font-body-default-regular-0 text-text-neutral-secondary">
|
||||
{row.startedIso ? dateFormatter.format(new Date(row.startedIso)) : "—"}
|
||||
</span>
|
||||
</Table.Cell>
|
||||
<Table.Cell>
|
||||
<span className="whitespace-nowrap text-body-default-regular-0 font-body-default-regular-0 text-text-neutral-secondary">
|
||||
{t(row.kindKey)}
|
||||
</span>
|
||||
</Table.Cell>
|
||||
<Table.Cell>
|
||||
<BadgeFeedback farbe={syncStatusBadge(row.status)} size="small">
|
||||
{t(row.statusKey)}
|
||||
</BadgeFeedback>
|
||||
</Table.Cell>
|
||||
<Table.Cell>
|
||||
<span className="whitespace-nowrap text-body-default-regular-0 font-body-default-regular-0 text-text-neutral-secondary">
|
||||
{row.itemsSucceeded}/{row.itemsTotal}
|
||||
{row.itemsFailed > 0 ? ` (${row.itemsFailed} ✗)` : ""}
|
||||
</span>
|
||||
</Table.Cell>
|
||||
<Table.Cell>
|
||||
<span className="text-body-default-regular-150 font-body-default-regular-150 text-text-neutral-tertiary">
|
||||
{row.summaryKey ? t(row.summaryKey) : "—"}
|
||||
</span>
|
||||
</Table.Cell>
|
||||
<Table.Cell>
|
||||
<Link to={`${runHrefBase}/${row.id}`} className="contents no-underline" data-ui-id="ui.integrations.syncs.detail">
|
||||
<LinkButton variant="subtle">{t("integrations.syncs.detail")}</LinkButton>
|
||||
</Link>
|
||||
</Table.Cell>
|
||||
</Table.Row>
|
||||
))}
|
||||
</Table>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
+145
@@ -0,0 +1,145 @@
|
||||
// R-P5 Interim-UI (AD-28) — sync-run detail screen composed from ~/ui (D-P5
|
||||
// "Sync-Run-Detail", archetype A3): run header with item counters + Klartext
|
||||
// summary, AppSyncItem table (entity ↔ external id, operation, status, Klartext
|
||||
// error) and the AppSyncRunLog lines with severity badges. Pure presentational.
|
||||
// Final Subframe optics = tracked design-nachzug.
|
||||
|
||||
import { Link } from "react-router";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import type { SyncRunDetailVM } from "@hivegrid/view-models";
|
||||
import { Alert } from "~/ui/components/Alert";
|
||||
import { BadgeFeedback } from "~/ui/components/BadgeFeedback";
|
||||
import { Card } from "~/ui/components/Card";
|
||||
import { EmptyState } from "~/ui/components/EmptyState";
|
||||
import { LinkButton } from "~/ui/components/LinkButton";
|
||||
import { Table } from "~/ui/components/Table";
|
||||
import { syncItemStatusBadge, syncLogSeverityBadge, syncStatusBadge } from "./integrationsBadges";
|
||||
|
||||
export type SyncRunDetailPageProps = {
|
||||
vm: SyncRunDetailVM;
|
||||
backHref: string;
|
||||
};
|
||||
|
||||
export function SyncRunDetailPage({ vm, backHref }: SyncRunDetailPageProps) {
|
||||
const { t, i18n } = useTranslation();
|
||||
|
||||
if (vm.status !== "ready" || !vm.data) {
|
||||
return <div className="flex w-full flex-col gap-6 p-6" data-ui-id="ui.integrations.runDetail" />;
|
||||
}
|
||||
|
||||
const data = vm.data;
|
||||
const dateFormatter = new Intl.DateTimeFormat(i18n.language, { dateStyle: "medium", timeStyle: "short" });
|
||||
|
||||
return (
|
||||
<div className="flex w-full flex-col gap-6 p-6" data-ui-id="ui.integrations.runDetail">
|
||||
{/* Breadcrumb back to the sync history (DoD B9) + run header */}
|
||||
<Link to={backHref} className="contents no-underline" data-ui-id="ui.integrations.runDetail.back">
|
||||
<LinkButton variant="subtle">{t("integrations.runDetail.back")}</LinkButton>
|
||||
</Link>
|
||||
<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("integrations.runDetail.title")}</span>
|
||||
<span className="text-body-default-regular-150 font-body-default-regular-150 text-text-neutral-secondary">
|
||||
{t(data.kindKey)} · {data.startedIso ? dateFormatter.format(new Date(data.startedIso)) : "—"}
|
||||
</span>
|
||||
</div>
|
||||
<BadgeFeedback farbe={syncStatusBadge(data.status)}>{t(data.statusKey)}</BadgeFeedback>
|
||||
</div>
|
||||
|
||||
{/* Counters + Klartext summary */}
|
||||
<Card>
|
||||
<div className="flex w-full flex-wrap items-center gap-6">
|
||||
<div className="flex flex-col gap-0">
|
||||
<span className="text-body-small-regular-150 font-body-small-regular-150 text-text-neutral-tertiary">{t("integrations.runDetail.stats.total")}</span>
|
||||
<span className="text-body-default-medium-0 font-body-default-medium-0 text-text-neutral-primary">{data.itemsTotal}</span>
|
||||
</div>
|
||||
<div className="flex flex-col gap-0">
|
||||
<span className="text-body-small-regular-150 font-body-small-regular-150 text-text-neutral-tertiary">{t("integrations.runDetail.stats.succeeded")}</span>
|
||||
<span className="text-body-default-medium-0 font-body-default-medium-0 text-text-neutral-primary">{data.itemsSucceeded}</span>
|
||||
</div>
|
||||
<div className="flex flex-col gap-0">
|
||||
<span className="text-body-small-regular-150 font-body-small-regular-150 text-text-neutral-tertiary">{t("integrations.runDetail.stats.failed")}</span>
|
||||
<span className="text-body-default-medium-0 font-body-default-medium-0 text-text-neutral-primary">{data.itemsFailed}</span>
|
||||
</div>
|
||||
</div>
|
||||
{data.summaryKey ? (
|
||||
<span className="text-body-default-regular-150 font-body-default-regular-150 text-text-neutral-secondary">{t(data.summaryKey)}</span>
|
||||
) : null}
|
||||
</Card>
|
||||
|
||||
{data.status === "failed" ? <Alert variant="error" title={data.summaryKey ? t(data.summaryKey) : t("integrations.syncStatus.failed")} /> : null}
|
||||
|
||||
{/* AppSyncItem table (A3) */}
|
||||
<div className="flex w-full flex-col gap-3">
|
||||
<span className="text-body-default-medium-0 font-body-default-medium-0 text-text-neutral-primary">{t("integrations.runDetail.itemsHeadline")}</span>
|
||||
{data.items.length === 0 ? (
|
||||
<div data-ui-id="ui.integrations.runDetail.emptyItems">
|
||||
<EmptyState title={t(data.emptyItemsHeadlineKey)} body={t(data.emptyItemsBodyKey)} />
|
||||
</div>
|
||||
) : (
|
||||
<div className="w-full overflow-x-auto">
|
||||
<Table
|
||||
data-ui-id="ui.integrations.runDetail.items"
|
||||
header={
|
||||
<Table.HeaderRow>
|
||||
<Table.HeaderCell>{t("integrations.runDetail.column.entity")}</Table.HeaderCell>
|
||||
<Table.HeaderCell>{t("integrations.runDetail.column.externalId")}</Table.HeaderCell>
|
||||
<Table.HeaderCell>{t("integrations.runDetail.column.operation")}</Table.HeaderCell>
|
||||
<Table.HeaderCell>{t("integrations.runDetail.column.status")}</Table.HeaderCell>
|
||||
<Table.HeaderCell>{t("integrations.runDetail.column.error")}</Table.HeaderCell>
|
||||
</Table.HeaderRow>
|
||||
}
|
||||
>
|
||||
{data.items.map((item) => (
|
||||
<Table.Row key={item.id} data-row-id={item.id} data-status={item.status}>
|
||||
<Table.Cell>
|
||||
<span className="whitespace-nowrap text-body-default-regular-0 font-body-default-regular-0 text-text-neutral-primary">
|
||||
{item.entityType}
|
||||
{item.entityId ? ` · ${item.entityId}` : ""}
|
||||
</span>
|
||||
</Table.Cell>
|
||||
<Table.Cell>
|
||||
<span className="whitespace-nowrap text-body-default-regular-0 font-body-default-regular-0 text-text-neutral-secondary">{item.externalId}</span>
|
||||
</Table.Cell>
|
||||
<Table.Cell>
|
||||
<span className="whitespace-nowrap text-body-default-regular-0 font-body-default-regular-0 text-text-neutral-secondary">
|
||||
{t(item.operationKey)}
|
||||
</span>
|
||||
</Table.Cell>
|
||||
<Table.Cell>
|
||||
<BadgeFeedback farbe={syncItemStatusBadge(item.status)} size="small">
|
||||
{t(item.statusKey)}
|
||||
</BadgeFeedback>
|
||||
</Table.Cell>
|
||||
<Table.Cell>
|
||||
<span className="text-body-default-regular-150 font-body-default-regular-150 text-text-neutral-tertiary">
|
||||
{item.errorText ? t(item.errorText) : "—"}
|
||||
</span>
|
||||
</Table.Cell>
|
||||
</Table.Row>
|
||||
))}
|
||||
</Table>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{/* AppSyncRunLog lines with severity */}
|
||||
<div className="flex w-full flex-col gap-3" data-ui-id="ui.integrations.runDetail.logs">
|
||||
<span className="text-body-default-medium-0 font-body-default-medium-0 text-text-neutral-primary">{t("integrations.runDetail.logsHeadline")}</span>
|
||||
<div className="flex w-full flex-col gap-2">
|
||||
{data.logs.map((log) => (
|
||||
<div key={log.id} className="flex w-full items-center gap-2" data-log-id={log.id} data-severity={log.severity}>
|
||||
<BadgeFeedback farbe={syncLogSeverityBadge(log.severity)} size="small">
|
||||
{t(log.severityKey)}
|
||||
</BadgeFeedback>
|
||||
<span className="text-body-default-regular-150 font-body-default-regular-150 text-text-neutral-secondary">{t(log.messageKey)}</span>
|
||||
<span className="whitespace-nowrap text-body-small-regular-150 font-body-small-regular-150 text-text-neutral-tertiary">
|
||||
{dateFormatter.format(new Date(log.createdIso))}
|
||||
</span>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
+69
@@ -0,0 +1,69 @@
|
||||
// R-P5 Interim-UI (AD-28) — shared BadgeFeedback color mappings for the
|
||||
// integrations screens (status traffic light per D-P5: green active / yellow
|
||||
// degraded / red broken / gray revoked|pending). Pure, client-safe.
|
||||
|
||||
import type { ConnectionStatus, SyncItemStatus, SyncLogSeverity, SyncStatus } from "@hivegrid/view-models";
|
||||
|
||||
type BadgeColor =
|
||||
| "subtle-neutral"
|
||||
| "subtle-positive"
|
||||
| "subtle-negative"
|
||||
| "subtle-warning"
|
||||
| "subtle-information";
|
||||
|
||||
export function connectionStatusBadge(status: ConnectionStatus): BadgeColor {
|
||||
switch (status) {
|
||||
case "active":
|
||||
return "subtle-positive";
|
||||
case "degraded":
|
||||
return "subtle-warning";
|
||||
case "broken":
|
||||
return "subtle-negative";
|
||||
case "pending":
|
||||
return "subtle-information";
|
||||
case "revoked":
|
||||
return "subtle-neutral";
|
||||
}
|
||||
}
|
||||
|
||||
export function syncStatusBadge(status: SyncStatus): BadgeColor {
|
||||
switch (status) {
|
||||
case "completed":
|
||||
return "subtle-positive";
|
||||
case "partial":
|
||||
return "subtle-warning";
|
||||
case "failed":
|
||||
return "subtle-negative";
|
||||
case "running":
|
||||
return "subtle-information";
|
||||
case "pending":
|
||||
case "cancelled":
|
||||
return "subtle-neutral";
|
||||
}
|
||||
}
|
||||
|
||||
export function syncItemStatusBadge(status: SyncItemStatus): BadgeColor {
|
||||
switch (status) {
|
||||
case "synced":
|
||||
return "subtle-positive";
|
||||
case "failed":
|
||||
return "subtle-negative";
|
||||
case "pending":
|
||||
return "subtle-information";
|
||||
case "skipped":
|
||||
return "subtle-neutral";
|
||||
}
|
||||
}
|
||||
|
||||
export function syncLogSeverityBadge(severity: SyncLogSeverity): BadgeColor {
|
||||
switch (severity) {
|
||||
case "success":
|
||||
return "subtle-positive";
|
||||
case "error":
|
||||
return "subtle-negative";
|
||||
case "warning":
|
||||
return "subtle-warning";
|
||||
case "info":
|
||||
return "subtle-information";
|
||||
}
|
||||
}
|
||||
+174
@@ -0,0 +1,174 @@
|
||||
// AK-P3 Interim-UI (AD-28) — Notification-Center preview screen composed from
|
||||
// ~/ui. Pure presentational component: renders the (live-merged) VM passed as a
|
||||
// prop; mark-read/bulk-clear run through injected action callbacks (M014), the
|
||||
// SSE subscription lives in the hosting route (useNotificationsStream). Final
|
||||
// Subframe optics land as a tracked design-nachzug once David's D-P3 ships.
|
||||
|
||||
import { useState } from "react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import type { NotificationCenterItemVM, NotificationCenterVM } from "@hivegrid/view-models";
|
||||
import { Alert } from "~/ui/components/Alert";
|
||||
import { BadgeFeedback } from "~/ui/components/BadgeFeedback";
|
||||
import { Button } from "~/ui/components/Button";
|
||||
import { EmptyState } from "~/ui/components/EmptyState";
|
||||
import { Tabs } from "~/ui/components/Tabs";
|
||||
|
||||
export type NotificationCenterActions = {
|
||||
onMarkRead: (deliveryId: string) => void;
|
||||
onMarkAllRead: () => void;
|
||||
};
|
||||
|
||||
export type NotificationCenterPageProps = {
|
||||
vm: NotificationCenterVM;
|
||||
/** i18n key describing the SSE connection state (sr-only live region). */
|
||||
connectionStatusKey: string;
|
||||
actions: NotificationCenterActions;
|
||||
};
|
||||
|
||||
type BadgeFarbe = "subtle-positive" | "subtle-warning" | "subtle-negative" | "subtle-neutral";
|
||||
|
||||
function statusFarbe(status: string): BadgeFarbe {
|
||||
switch (status) {
|
||||
case "READ":
|
||||
return "subtle-positive";
|
||||
case "FAILED":
|
||||
return "subtle-negative";
|
||||
case "PENDING":
|
||||
return "subtle-warning";
|
||||
default:
|
||||
return "subtle-neutral";
|
||||
}
|
||||
}
|
||||
|
||||
export function NotificationCenterPage({ vm, connectionStatusKey, actions }: NotificationCenterPageProps) {
|
||||
const { t, i18n } = useTranslation();
|
||||
const [activeTab, setActiveTab] = useState<"all" | "unread">("all");
|
||||
|
||||
// Loading / not-ready: keep the marker so the shell + e2e see a stable surface.
|
||||
if (vm.status !== "ready" || !vm.data) {
|
||||
return <div className="flex w-full flex-col gap-6 p-6" data-ui-id="ui.notifications.center" />;
|
||||
}
|
||||
|
||||
const { items, totalCount, unreadCount, emptyHeadlineKey, emptyBodyKey, unreadEmptyKey } = vm.data;
|
||||
const visibleItems = activeTab === "unread" ? items.filter((item) => !item.isRead) : items;
|
||||
const numberFormatter = new Intl.NumberFormat(i18n.language);
|
||||
|
||||
return (
|
||||
<div className="flex w-full flex-col gap-6 p-6" data-ui-id="ui.notifications.center">
|
||||
{/* Header: title + subtitle (0px rhythm) */}
|
||||
<div className="flex flex-col gap-0">
|
||||
<span className="text-heading-2 font-heading-2 text-text-neutral-primary">{t("notifications.center.title")}</span>
|
||||
<span className="text-body-default-regular-150 font-body-default-regular-150 text-text-neutral-secondary">
|
||||
{t("notifications.center.diagnostics")}
|
||||
</span>
|
||||
<span className="sr-only" role="status">
|
||||
{t(connectionStatusKey)}
|
||||
</span>
|
||||
</div>
|
||||
|
||||
{totalCount === 0 ? (
|
||||
<div data-ui-id="ui.notifications.center.empty">
|
||||
<EmptyState title={t(emptyHeadlineKey)} body={t(emptyBodyKey)} />
|
||||
</div>
|
||||
) : (
|
||||
<>
|
||||
<div className="flex flex-wrap items-center justify-between gap-4">
|
||||
<div className="max-w-[360px] flex-1" data-ui-id="ui.notifications.center.tabs">
|
||||
<Tabs>
|
||||
<Tabs.Item active={activeTab === "all"} onClick={() => setActiveTab("all")} role="tab" aria-selected={activeTab === "all"}>
|
||||
{`${t("notifications.center.tabs.all")} (${numberFormatter.format(totalCount)})`}
|
||||
</Tabs.Item>
|
||||
<Tabs.Item
|
||||
active={activeTab === "unread"}
|
||||
onClick={() => setActiveTab("unread")}
|
||||
role="tab"
|
||||
aria-selected={activeTab === "unread"}
|
||||
>
|
||||
{`${t("notifications.center.tabs.unread")} (${numberFormatter.format(unreadCount)})`}
|
||||
</Tabs.Item>
|
||||
</Tabs>
|
||||
</div>
|
||||
{unreadCount > 0 ? (
|
||||
<Button variant="secondary" onClick={() => actions.onMarkAllRead()} data-ui-id="ui.notifications.center.bulkClear">
|
||||
{t("notifications.center.bulkClear")}
|
||||
</Button>
|
||||
) : null}
|
||||
</div>
|
||||
|
||||
{visibleItems.length === 0 ? (
|
||||
<div data-ui-id="ui.notifications.center.unreadEmpty">
|
||||
<EmptyState title={t(unreadEmptyKey)} body={t(emptyBodyKey)} />
|
||||
</div>
|
||||
) : (
|
||||
<ul className="flex list-none flex-col gap-4 p-0" aria-label={String(t("notifications.center.listLabel"))}>
|
||||
{visibleItems.map((item) => (
|
||||
<NotificationCard key={item.id} item={item} onMarkRead={actions.onMarkRead} />
|
||||
))}
|
||||
</ul>
|
||||
)}
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function NotificationCard({ item, onMarkRead }: { item: NotificationCenterItemVM; onMarkRead: (deliveryId: string) => void }) {
|
||||
const { t, i18n } = useTranslation();
|
||||
const dateTimeFormatter = new Intl.DateTimeFormat(i18n.language, { dateStyle: "medium", timeStyle: "short" });
|
||||
|
||||
const messageLabel = i18n.exists(item.messageKey) ? String(t(item.messageKey)) : String(t("notifications.center.unknownMessage"));
|
||||
const enumLabel = (key: string, fallbackKey: string) => (i18n.exists(key) ? String(t(key)) : String(t(fallbackKey)));
|
||||
const formatTimestamp = (iso: string | null) =>
|
||||
iso ? dateTimeFormatter.format(new Date(iso)) : String(t("notifications.center.timestamps.notRecorded"));
|
||||
|
||||
return (
|
||||
<li
|
||||
className="flex flex-col gap-4 rounded-md border border-solid border-border-default bg-surface-neutral-primary p-4"
|
||||
data-row-id={item.id}
|
||||
data-read={item.isRead}
|
||||
>
|
||||
<div className="flex flex-wrap items-start justify-between gap-4">
|
||||
<div className="flex flex-col gap-0">
|
||||
{item.deeplinkHref ? (
|
||||
<a
|
||||
href={item.deeplinkHref}
|
||||
className="text-body-default-medium-0 font-body-default-medium-0 text-text-feedback-link-default no-underline"
|
||||
data-ui-id="ui.notifications.center.deeplink"
|
||||
>
|
||||
{messageLabel}
|
||||
</a>
|
||||
) : (
|
||||
<span className="text-body-default-medium-0 font-body-default-medium-0 text-text-neutral-primary">{messageLabel}</span>
|
||||
)}
|
||||
<span className="text-body-small-regular-150 font-body-small-regular-150 text-text-neutral-secondary">
|
||||
{enumLabel(item.categoryKey, "notifications.center.categories.unknown")} ·{" "}
|
||||
{enumLabel(item.channelKey, "notifications.center.channels.unknown")} · {formatTimestamp(item.sentAtIso ?? item.createdAtIso)}
|
||||
</span>
|
||||
</div>
|
||||
<BadgeFeedback farbe={statusFarbe(item.status)} size="small">
|
||||
{enumLabel(item.statusKey, "notifications.center.statuses.unknown")}
|
||||
</BadgeFeedback>
|
||||
</div>
|
||||
|
||||
{item.bounceKey ? (
|
||||
<div data-ui-id="ui.notifications.center.bounce">
|
||||
<Alert variant="error" title={t(item.bounceKey)} description={item.lastErrorRedacted ?? undefined} />
|
||||
</div>
|
||||
) : null}
|
||||
|
||||
{!item.isRead ? (
|
||||
<div className="flex">
|
||||
<Button
|
||||
size="small"
|
||||
variant="secondary"
|
||||
onClick={() => onMarkRead(item.id)}
|
||||
aria-label={String(t("notifications.center.markReadLabel", { message: messageLabel }))}
|
||||
data-ui-id="ui.notifications.center.markRead"
|
||||
>
|
||||
{t("notifications.center.markRead")}
|
||||
</Button>
|
||||
</div>
|
||||
) : null}
|
||||
</li>
|
||||
);
|
||||
}
|
||||
+146
@@ -0,0 +1,146 @@
|
||||
// AK-P3 Interim-UI (AD-28) — Notification-Settings preview screen composed from
|
||||
// ~/ui (A6 settings archetype). Pure presentational component: renders the
|
||||
// server-built NotificationSettingsVM passed as a prop; toggles run through
|
||||
// injected action callbacks (M014) implemented fetcher-side by the hosting
|
||||
// route. Final Subframe optics land as a tracked design-nachzug once David's
|
||||
// D-P3 ships.
|
||||
|
||||
import { useTranslation } from "react-i18next";
|
||||
import type { NotificationSettingChannel, NotificationSettingsVM } from "@hivegrid/view-models";
|
||||
import { Alert } from "~/ui/components/Alert";
|
||||
import { Switch } from "~/ui/components/Switch";
|
||||
|
||||
export type NotificationSettingsActions = {
|
||||
onTogglePreference: (input: { category: string; channel: NotificationSettingChannel; enabled: boolean }) => void;
|
||||
/** Master switch: true = turn ALL emails off (writes every category). */
|
||||
onSetEmailMaster: (disableAllEmails: boolean) => void;
|
||||
};
|
||||
|
||||
export type NotificationSettingsPageProps = {
|
||||
vm: NotificationSettingsVM;
|
||||
/** Plain-text result of the last save action (null = nothing saved yet). */
|
||||
saveState: { ok: boolean; errorText?: string } | null;
|
||||
actions: NotificationSettingsActions;
|
||||
};
|
||||
|
||||
export function NotificationSettingsPage({ vm, saveState, actions }: NotificationSettingsPageProps) {
|
||||
const { t } = useTranslation();
|
||||
|
||||
// Loading / not-ready: keep the marker so the shell + e2e see a stable surface.
|
||||
if (vm.status !== "ready" || !vm.data) {
|
||||
return <div className="flex w-full flex-col gap-6 p-6" data-ui-id="ui.settings.notifications.page" />;
|
||||
}
|
||||
|
||||
const { groups, allEmailsDisabled } = vm.data;
|
||||
|
||||
return (
|
||||
<div className="mx-auto flex w-full max-w-3xl flex-col gap-6 p-6" data-ui-id="ui.settings.notifications.page">
|
||||
{/* Header: title + subtitle (0px rhythm) */}
|
||||
<div className="flex flex-col gap-0">
|
||||
<span className="text-heading-2 font-heading-2 text-text-neutral-primary">{t("settings.notifications.heading")}</span>
|
||||
<span className="text-body-default-regular-150 font-body-default-regular-150 text-text-neutral-secondary">
|
||||
{t("settings.notifications.description")}
|
||||
</span>
|
||||
</div>
|
||||
|
||||
{saveState ? (
|
||||
<div data-ui-id="ui.settings.notifications.saveState">
|
||||
{saveState.ok ? (
|
||||
<Alert variant="success" title={t("settings.notifications.saved")} />
|
||||
) : (
|
||||
<Alert variant="error" title={saveState.errorText ?? t("settings.notifications.errors.invalidPreferenceAction")} />
|
||||
)}
|
||||
</div>
|
||||
) : null}
|
||||
|
||||
{/* Master switch: all emails off (card surface, 16px padding) */}
|
||||
<div
|
||||
className="flex flex-wrap items-center justify-between gap-4 rounded-md border border-solid border-border-default bg-surface-neutral-primary p-4"
|
||||
data-ui-id="ui.settings.notifications.master.email"
|
||||
>
|
||||
<div className="flex flex-col gap-0">
|
||||
<span className="text-body-default-medium-0 font-body-default-medium-0 text-text-neutral-primary">
|
||||
{t("settings.notifications.master.heading")}
|
||||
</span>
|
||||
<span className="text-body-small-regular-150 font-body-small-regular-150 text-text-neutral-secondary">
|
||||
{t("settings.notifications.master.description")}
|
||||
</span>
|
||||
</div>
|
||||
<label className="flex items-center gap-2">
|
||||
<span className="text-body-default-regular-0 font-body-default-regular-0 text-text-neutral-primary">
|
||||
{t("settings.notifications.master.disableAllEmails")}
|
||||
</span>
|
||||
<Switch
|
||||
checked={allEmailsDisabled}
|
||||
onCheckedChange={(checked: boolean) => actions.onSetEmailMaster(checked)}
|
||||
data-ui-id="ui.settings.notifications.master.switch"
|
||||
/>
|
||||
</label>
|
||||
</div>
|
||||
|
||||
{/* Event types grouped per module (A6) */}
|
||||
<div className="flex flex-col gap-4">
|
||||
{groups.map((group) => (
|
||||
<div
|
||||
key={group.module}
|
||||
className="flex flex-col rounded-md border border-solid border-border-default bg-surface-neutral-primary"
|
||||
data-ui-id={`ui.settings.notifications.module.${group.module}`}
|
||||
>
|
||||
<span className="border-b border-solid border-border-default px-4 py-2 text-body-small-medium-0 font-body-small-medium-0 uppercase text-text-neutral-tertiary">
|
||||
{t(group.moduleLabelKey)}
|
||||
</span>
|
||||
{group.categories.map((category) => (
|
||||
<div
|
||||
key={category.category}
|
||||
className="flex flex-wrap items-center justify-between gap-4 p-4"
|
||||
data-ui-id={`ui.settings.notifications.category.${category.category}`}
|
||||
>
|
||||
<div className="flex flex-col gap-0">
|
||||
<span className="text-body-default-medium-0 font-body-default-medium-0 text-text-neutral-primary">
|
||||
{t(category.labelKey)}
|
||||
</span>
|
||||
<span className="text-body-small-regular-150 font-body-small-regular-150 text-text-neutral-secondary">
|
||||
{t("settings.notifications.categoryDescription", { category: String(t(category.labelKey)).toLowerCase() })}
|
||||
</span>
|
||||
</div>
|
||||
<div className="flex flex-wrap items-center gap-4">
|
||||
<ChannelToggle
|
||||
label={t("settings.notifications.channels.inApp")}
|
||||
checked={category.channels.IN_APP}
|
||||
uiId={`ui.settings.notifications.preference.${category.category}.in_app`}
|
||||
onChange={(enabled) => actions.onTogglePreference({ category: category.category, channel: "IN_APP", enabled })}
|
||||
/>
|
||||
<ChannelToggle
|
||||
label={t("settings.notifications.channels.email")}
|
||||
checked={category.channels.EMAIL}
|
||||
uiId={`ui.settings.notifications.preference.${category.category}.email`}
|
||||
onChange={(enabled) => actions.onTogglePreference({ category: category.category, channel: "EMAIL", enabled })}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function ChannelToggle({
|
||||
label,
|
||||
checked,
|
||||
uiId,
|
||||
onChange,
|
||||
}: {
|
||||
label: string;
|
||||
checked: boolean;
|
||||
uiId: string;
|
||||
onChange: (enabled: boolean) => void;
|
||||
}) {
|
||||
return (
|
||||
<label className="flex items-center gap-2" data-ui-id={uiId}>
|
||||
<span className="text-body-default-regular-0 font-body-default-regular-0 text-text-neutral-primary">{label}</span>
|
||||
<Switch checked={checked} onCheckedChange={onChange} />
|
||||
</label>
|
||||
);
|
||||
}
|
||||
+59
@@ -0,0 +1,59 @@
|
||||
import { vi, describe, it, expect } from "vitest";
|
||||
import "@testing-library/jest-dom";
|
||||
import { fireEvent, render } from "@testing-library/react";
|
||||
import { toNotificationCenterItemVM, type NotificationCenterItemVM } from "@hivegrid/view-models";
|
||||
|
||||
import { NotificationsDrawer } from "./NotificationsDrawer";
|
||||
|
||||
vi.mock("react-i18next", () => ({
|
||||
useTranslation: () => ({
|
||||
t: (str: string) => str,
|
||||
i18n: { language: "de", exists: (key: string) => key === "team.invite.created" },
|
||||
}),
|
||||
}));
|
||||
|
||||
function item(overrides: Partial<Parameters<typeof toNotificationCenterItemVM>[0]> = {}): NotificationCenterItemVM {
|
||||
return toNotificationCenterItemVM({
|
||||
id: "delivery_1",
|
||||
messageKey: "team.invite.created",
|
||||
category: "team",
|
||||
channel: "IN_APP",
|
||||
status: "SENT",
|
||||
attemptsMade: 1,
|
||||
createdAtIso: "2026-07-01T10:00:00.000Z",
|
||||
sentAtIso: "2026-07-01T10:01:00.000Z",
|
||||
...overrides,
|
||||
});
|
||||
}
|
||||
|
||||
describe("NotificationsDrawer (interim-UI)", () => {
|
||||
it("renders items with unread badge and deeplink when open", () => {
|
||||
render(
|
||||
<NotificationsDrawer
|
||||
open
|
||||
items={[item({ payloadMetadata: { deeplink: "/acme/settings/members" } }), item({ id: "d2", status: "READ" })]}
|
||||
allHref="/acme/notifications"
|
||||
onClose={vi.fn()}
|
||||
/>,
|
||||
);
|
||||
|
||||
expect(document.querySelector('[data-ui-id="ui.notifications.drawer"]')).toBeInTheDocument();
|
||||
expect(document.querySelector('[data-row-id="delivery_1"]')).toHaveAttribute("data-read", "false");
|
||||
expect(document.querySelector('[data-ui-id="ui.notifications.drawer.deeplink"]')).toHaveAttribute("href", "/acme/settings/members");
|
||||
expect(document.querySelector('[data-ui-id="ui.notifications.drawer.showAll"]')).toHaveAttribute("href", "/acme/notifications");
|
||||
});
|
||||
|
||||
it("shows the empty state and closes via the close button", () => {
|
||||
const onClose = vi.fn();
|
||||
render(<NotificationsDrawer open items={[]} allHref="/acme/notifications" onClose={onClose} />);
|
||||
|
||||
expect(document.querySelector('[data-ui-id="ui.notifications.drawer.empty"]')).toBeInTheDocument();
|
||||
fireEvent.click(document.querySelector('[data-ui-id="ui.notifications.drawer.close"]')!);
|
||||
expect(onClose).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
it("renders nothing visible when closed", () => {
|
||||
render(<NotificationsDrawer open={false} items={[item()]} allHref="/acme/notifications" onClose={vi.fn()} />);
|
||||
expect(document.querySelector('[data-ui-id="ui.notifications.drawer"]')).not.toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
+105
@@ -0,0 +1,105 @@
|
||||
// AK-P3 Interim-UI (AD-28) — topbar notifications drawer composed from ~/ui
|
||||
// (real Drawer, not a card fake — D07). Pure presentational: the host (NavBar)
|
||||
// owns the SSE subscription and open state; items arrive as VM props, clicks
|
||||
// follow validated deeplinks. Final Subframe optics land as a tracked
|
||||
// design-nachzug once David's D-P3 ships.
|
||||
|
||||
import { useTranslation } from "react-i18next";
|
||||
import type { NotificationCenterItemVM } from "@hivegrid/view-models";
|
||||
import { BadgeFeedback } from "~/ui/components/BadgeFeedback";
|
||||
import { Button } from "~/ui/components/Button";
|
||||
import { Drawer } from "~/ui/components/Drawer";
|
||||
import { EmptyState } from "~/ui/components/EmptyState";
|
||||
|
||||
const DRAWER_MAX_ITEMS = 10;
|
||||
|
||||
export type NotificationsDrawerProps = {
|
||||
open: boolean;
|
||||
items: readonly NotificationCenterItemVM[];
|
||||
/** Href of the full notification center route ("show all"). */
|
||||
allHref: string;
|
||||
onClose: () => void;
|
||||
};
|
||||
|
||||
export function NotificationsDrawer({ open, items, allHref, onClose }: NotificationsDrawerProps) {
|
||||
const { t, i18n } = useTranslation();
|
||||
const visibleItems = items.slice(0, DRAWER_MAX_ITEMS);
|
||||
const dateTimeFormatter = new Intl.DateTimeFormat(i18n.language, { dateStyle: "short", timeStyle: "short" });
|
||||
|
||||
return (
|
||||
<Drawer open={open} onOpenChange={(nextOpen: boolean) => (nextOpen ? undefined : onClose())}>
|
||||
<Drawer.Content>
|
||||
<div className="flex w-96 max-w-full flex-col gap-6 p-6" data-ui-id="ui.notifications.drawer">
|
||||
<div className="flex items-start justify-between gap-4">
|
||||
<span className="text-heading-3 font-heading-3 text-text-neutral-primary">{t("notifications.center.drawer.title")}</span>
|
||||
<Button variant="tertiary" size="small" onClick={onClose} data-ui-id="ui.notifications.drawer.close">
|
||||
{t("notifications.center.drawer.close")}
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
{visibleItems.length === 0 ? (
|
||||
<div data-ui-id="ui.notifications.drawer.empty">
|
||||
<EmptyState title={t("notifications.center.drawer.empty")} body={t("notifications.center.emptyHelper")} />
|
||||
</div>
|
||||
) : (
|
||||
<ul className="flex list-none flex-col gap-3 p-0" aria-label={String(t("notifications.center.listLabel"))}>
|
||||
{visibleItems.map((item) => (
|
||||
<DrawerItem key={item.id} item={item} formatter={dateTimeFormatter} />
|
||||
))}
|
||||
</ul>
|
||||
)}
|
||||
|
||||
<div className="flex justify-end">
|
||||
<a href={allHref} className="no-underline" data-ui-id="ui.notifications.drawer.showAll">
|
||||
<Button variant="secondary">{t("notifications.center.drawer.showAll")}</Button>
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
</Drawer.Content>
|
||||
</Drawer>
|
||||
);
|
||||
}
|
||||
|
||||
function DrawerItem({ item, formatter }: { item: NotificationCenterItemVM; formatter: Intl.DateTimeFormat }) {
|
||||
const { t, i18n } = useTranslation();
|
||||
const messageLabel = i18n.exists(item.messageKey) ? String(t(item.messageKey)) : String(t("notifications.center.unknownMessage"));
|
||||
const timestampIso = item.sentAtIso ?? item.createdAtIso;
|
||||
|
||||
const body = (
|
||||
<div className="flex flex-col gap-0">
|
||||
<span
|
||||
className={
|
||||
item.isRead
|
||||
? "text-body-default-regular-0 font-body-default-regular-0 text-text-neutral-secondary"
|
||||
: "text-body-default-medium-0 font-body-default-medium-0 text-text-neutral-primary"
|
||||
}
|
||||
>
|
||||
{messageLabel}
|
||||
</span>
|
||||
<span className="text-body-small-regular-150 font-body-small-regular-150 text-text-neutral-tertiary">
|
||||
{timestampIso ? formatter.format(new Date(timestampIso)) : String(t("notifications.center.timestamps.notRecorded"))}
|
||||
</span>
|
||||
</div>
|
||||
);
|
||||
|
||||
return (
|
||||
<li
|
||||
className="flex items-start justify-between gap-3 rounded-md border border-solid border-border-default p-3"
|
||||
data-row-id={item.id}
|
||||
data-read={item.isRead}
|
||||
>
|
||||
{item.deeplinkHref ? (
|
||||
<a href={item.deeplinkHref} className="no-underline" data-ui-id="ui.notifications.drawer.deeplink">
|
||||
{body}
|
||||
</a>
|
||||
) : (
|
||||
body
|
||||
)}
|
||||
{!item.isRead ? (
|
||||
<BadgeFeedback farbe="subtle-warning" size="small">
|
||||
{t("notifications.center.statuses.unread")}
|
||||
</BadgeFeedback>
|
||||
) : null}
|
||||
</li>
|
||||
);
|
||||
}
|
||||
+25
@@ -0,0 +1,25 @@
|
||||
// Interim-UI helper (AD-28): a labeled native <input type="date"> for server forms.
|
||||
// Deliberate exception to "compose from ~/ui" — the ~/ui TextInput.Input type prop
|
||||
// excludes "date" and the ~/ui DatePicker is a controlled component that does not
|
||||
// submit a form field. Styled with the same design tokens as ~/ui inputs (control
|
||||
// height Medium 36 = h-9, radius small 4, neutral border/text) so it reads David-near.
|
||||
|
||||
export type DateFieldProps = {
|
||||
label: string;
|
||||
name: string;
|
||||
defaultValue?: string;
|
||||
};
|
||||
|
||||
export function DateField({ label, name, defaultValue }: DateFieldProps) {
|
||||
return (
|
||||
<label className="flex flex-col gap-1">
|
||||
<span className="text-body-small-medium-0 font-body-small-medium-0 text-text-neutral-tertiary">{label}</span>
|
||||
<input
|
||||
type="date"
|
||||
name={name}
|
||||
defaultValue={defaultValue}
|
||||
className="h-9 rounded-[4px] border border-solid border-border-default bg-transparent px-3 text-body-default-regular-0 font-body-default-regular-0 text-text-neutral-primary outline-none"
|
||||
/>
|
||||
</label>
|
||||
);
|
||||
}
|
||||
+91
@@ -0,0 +1,91 @@
|
||||
import { vi, describe, it, expect } from "vitest";
|
||||
import "@testing-library/jest-dom";
|
||||
import { render } from "@testing-library/react";
|
||||
import { BrowserRouter as Router } from "react-router";
|
||||
import { buildTaskDetailVM, type BuildTaskDetailVMInput, type TaskDetailData, type TaskDetailSource } from "@hivegrid/view-models";
|
||||
|
||||
import { TaskDetailPage } from "./TaskDetailPage";
|
||||
|
||||
vi.mock("react-i18next", () => ({
|
||||
useTranslation: () => ({ t: (str: string) => str, i18n: { language: "de" } }),
|
||||
}));
|
||||
|
||||
function source(overrides: Partial<TaskDetailSource> = {}): TaskDetailSource {
|
||||
return {
|
||||
id: "t1",
|
||||
title: "Angebot nachfassen",
|
||||
description: "Kunde bis Freitag anrufen",
|
||||
status: "open",
|
||||
priority: "high",
|
||||
deadlineIso: "2026-02-01T10:00:00.000Z",
|
||||
isOverdue: false,
|
||||
assignee: { kind: "user", label: "Alex Meier" },
|
||||
linkedEntity: { entityType: "contact", entityId: "c9", labelKey: "tasks.entity.contact" },
|
||||
source: "manual",
|
||||
sourceHref: null,
|
||||
watchers: [{ userId: "u2", label: "Sam Fischer" }],
|
||||
createdAtIso: "2026-01-02T10:00:00.000Z",
|
||||
completedAtIso: null,
|
||||
...overrides,
|
||||
};
|
||||
}
|
||||
|
||||
function data(input: Partial<BuildTaskDetailVMInput> = {}): TaskDetailData {
|
||||
const vm = buildTaskDetailVM({
|
||||
task: source(),
|
||||
assignableUsers: [{ id: "u1", label: "Alex Meier" }],
|
||||
assignableGroups: [{ id: "g1", label: "Vertrieb" }],
|
||||
canWrite: true,
|
||||
canDelete: true,
|
||||
listHref: "/acme/tasks",
|
||||
...input,
|
||||
});
|
||||
if (vm.status !== "ready" || !vm.data) throw new Error("expected ready VM");
|
||||
return vm.data;
|
||||
}
|
||||
|
||||
describe("TaskDetailPage (interim-UI)", () => {
|
||||
it("renders the detail surface + title + linked entity + edit form", () => {
|
||||
const { container, getAllByText } = render(
|
||||
<Router>
|
||||
<TaskDetailPage data={data()} />
|
||||
</Router>,
|
||||
);
|
||||
expect(container.querySelector('[data-ui-id="ui.tasks.detail"]')).toBeInTheDocument();
|
||||
expect(container.querySelector('[data-ui-id="ui.tasks.detail.linkedEntity"]')).toBeInTheDocument();
|
||||
expect(container.querySelector('[data-ui-id="ui.tasks.detail.edit"]')).toBeInTheDocument();
|
||||
// Title appears in both the breadcrumb (active) and the header.
|
||||
expect(getAllByText("Angebot nachfassen").length).toBeGreaterThan(0);
|
||||
});
|
||||
|
||||
it("renders the watcher list with a per-watcher marker", () => {
|
||||
const { container, getByText } = render(
|
||||
<Router>
|
||||
<TaskDetailPage data={data()} />
|
||||
</Router>,
|
||||
);
|
||||
expect(container.querySelector('[data-watcher-id="u2"]')).toBeInTheDocument();
|
||||
expect(getByText("Sam Fischer")).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("exposes complete + delete actions for a writable, non-done task", () => {
|
||||
const { container } = render(
|
||||
<Router>
|
||||
<TaskDetailPage data={data()} />
|
||||
</Router>,
|
||||
);
|
||||
expect(container.querySelector('[data-ui-id="ui.tasks.detail.complete"]')).toBeInTheDocument();
|
||||
expect(container.querySelector('[data-ui-id="ui.tasks.detail.delete"]')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("hides the edit form + action buttons for a read-only viewer", () => {
|
||||
const { container } = render(
|
||||
<Router>
|
||||
<TaskDetailPage data={data({ canWrite: false, canDelete: false })} />
|
||||
</Router>,
|
||||
);
|
||||
expect(container.querySelector('[data-ui-id="ui.tasks.detail.edit"]')).not.toBeInTheDocument();
|
||||
expect(container.querySelector('[data-ui-id="ui.tasks.detail.complete"]')).not.toBeInTheDocument();
|
||||
expect(container.querySelector('[data-ui-id="ui.tasks.detail.delete"]')).not.toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
+262
@@ -0,0 +1,262 @@
|
||||
// AK-P4b Interim-UI (AD-28) — Task detail preview screen composed from ~/ui.
|
||||
// Presentational: renders the unwrapped TaskDetailData; mutations stay server-driven
|
||||
// (<form method="post"> + intent, exactly like the baseline route action). The delete
|
||||
// confirmation is a real ~/ui Dialog (David standard), not a Card fake. No
|
||||
// useLoaderData / server imports. Final Subframe optics land as a design-nachzug.
|
||||
|
||||
import { useState } from "react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { FeatherArchive, FeatherCheck, FeatherTrash2 } from "@subframe/core";
|
||||
import type { TaskDetailData, TaskPriority, TaskStatus } from "@hivegrid/view-models";
|
||||
import { BadgeFeedback } from "~/ui/components/BadgeFeedback";
|
||||
import { Breadcrumbs } from "~/ui/components/Breadcrumbs";
|
||||
import { Button } from "~/ui/components/Button";
|
||||
import { Card } from "~/ui/components/Card";
|
||||
import { Dialog } from "~/ui/components/Dialog";
|
||||
import { IconButton } from "~/ui/components/IconButton";
|
||||
import { Select } from "~/ui/components/Select";
|
||||
import { Tag_Label } from "~/ui/components/Tag_Label";
|
||||
import { TextArea } from "~/ui/components/TextArea";
|
||||
import { TextInput } from "~/ui/components/TextInput";
|
||||
import { DateField } from "./DateField";
|
||||
|
||||
const STATUSES: readonly TaskStatus[] = ["open", "in_progress", "blocked", "done", "cancelled"];
|
||||
const PRIORITIES: readonly TaskPriority[] = ["low", "normal", "high", "urgent"];
|
||||
|
||||
export type TaskDetailPageProps = {
|
||||
data: TaskDetailData;
|
||||
};
|
||||
|
||||
type BadgeFarbe = "subtle-positive" | "subtle-warning" | "subtle-negative" | "subtle-neutral";
|
||||
|
||||
function statusFarbe(status: TaskStatus): BadgeFarbe {
|
||||
switch (status) {
|
||||
case "done":
|
||||
return "subtle-positive";
|
||||
case "blocked":
|
||||
return "subtle-negative";
|
||||
case "in_progress":
|
||||
return "subtle-warning";
|
||||
case "cancelled":
|
||||
case "open":
|
||||
default:
|
||||
return "subtle-neutral";
|
||||
}
|
||||
}
|
||||
|
||||
function MetaRow({ label, value }: { label: string; value: string }) {
|
||||
return (
|
||||
<div className="flex flex-col gap-1">
|
||||
<span className="text-body-small-medium-0 font-body-small-medium-0 text-text-neutral-tertiary">{label}</span>
|
||||
<span className="text-body-default-regular-0 font-body-default-regular-0 text-text-neutral-primary">{value}</span>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export function TaskDetailPage({ data }: TaskDetailPageProps) {
|
||||
const { t, i18n } = useTranslation();
|
||||
const [deleteOpen, setDeleteOpen] = useState(false);
|
||||
const dateFormatter = new Intl.DateTimeFormat(i18n.language, { dateStyle: "medium" });
|
||||
const deadlineLabel = data.deadlineIso ? dateFormatter.format(new Date(data.deadlineIso)) : "—";
|
||||
|
||||
return (
|
||||
<div className="flex w-full max-w-[960px] flex-col gap-6 p-6" data-ui-id="ui.tasks.detail">
|
||||
<Breadcrumbs>
|
||||
<a href={data.listHref} className="no-underline">
|
||||
<Breadcrumbs.Item>{t("tasks.nav.title")}</Breadcrumbs.Item>
|
||||
</a>
|
||||
<Breadcrumbs.Divider />
|
||||
<Breadcrumbs.Item active>{data.title}</Breadcrumbs.Item>
|
||||
</Breadcrumbs>
|
||||
|
||||
{/* Header + action bar */}
|
||||
<div className="flex flex-wrap items-start justify-between gap-4">
|
||||
<div className="flex flex-col gap-2">
|
||||
<span className="text-heading-2 font-heading-2 text-text-neutral-primary">{data.title}</span>
|
||||
<div className="flex flex-wrap items-center gap-2">
|
||||
<BadgeFeedback farbe={statusFarbe(data.status)} size="small">
|
||||
{t(data.statusKey)}
|
||||
</BadgeFeedback>
|
||||
<Tag_Label tone="neutral-subtle" size="small" noAction>
|
||||
{t(data.priorityKey)}
|
||||
</Tag_Label>
|
||||
<span className="text-body-small-regular-0 font-body-small-regular-0 text-text-neutral-tertiary">{t(data.sourceKey)}</span>
|
||||
</div>
|
||||
</div>
|
||||
<div className="flex flex-wrap items-center gap-2" data-ui-id="ui.tasks.detail.actions">
|
||||
{data.canWrite && data.status !== "done" ? (
|
||||
<form method="post">
|
||||
<Button type="submit" name="intent" value="complete" variant="tertiary" icon={<FeatherCheck />} data-ui-id="ui.tasks.detail.complete">
|
||||
{t("tasks.detail.actions.complete")}
|
||||
</Button>
|
||||
</form>
|
||||
) : null}
|
||||
{data.canWrite ? (
|
||||
<form method="post">
|
||||
<Button type="submit" name="intent" value="archive" variant="tertiary" icon={<FeatherArchive />} data-ui-id="ui.tasks.detail.archive">
|
||||
{t("tasks.detail.actions.archive")}
|
||||
</Button>
|
||||
</form>
|
||||
) : null}
|
||||
{data.canDelete ? (
|
||||
<Button type="button" variant="destructive" icon={<FeatherTrash2 />} onClick={() => setDeleteOpen(true)} data-ui-id="ui.tasks.detail.delete">
|
||||
{t("tasks.detail.actions.delete")}
|
||||
</Button>
|
||||
) : null}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Metadata */}
|
||||
<Card>
|
||||
<span className="text-body-default-medium-0 font-body-default-medium-0 text-text-neutral-primary">{t("tasks.detail.section.overview")}</span>
|
||||
<div className="grid w-full grid-cols-1 gap-4 sm:grid-cols-2">
|
||||
<div data-ui-id="ui.tasks.detail.deadline" data-overdue={data.isOverdue}>
|
||||
<MetaRow label={t("tasks.detail.field.deadline")} value={deadlineLabel} />
|
||||
</div>
|
||||
<MetaRow label={t("tasks.detail.field.assignee")} value={data.assignee ? data.assignee.label : t("tasks.detail.unassigned")} />
|
||||
{data.linkedEntity ? (
|
||||
<div data-ui-id="ui.tasks.detail.linkedEntity">
|
||||
<MetaRow label={t(data.linkedEntity.labelKey)} value={data.linkedEntity.entityId} />
|
||||
</div>
|
||||
) : null}
|
||||
<MetaRow label={t("tasks.detail.field.created")} value={dateFormatter.format(new Date(data.createdAtIso))} />
|
||||
</div>
|
||||
{data.description ? (
|
||||
<div className="flex flex-col gap-1">
|
||||
<span className="text-body-small-medium-0 font-body-small-medium-0 text-text-neutral-tertiary">{t("tasks.detail.section.description")}</span>
|
||||
<span className="whitespace-pre-wrap text-body-default-regular-0 font-body-default-regular-0 text-text-neutral-primary">{data.description}</span>
|
||||
</div>
|
||||
) : null}
|
||||
</Card>
|
||||
|
||||
{/* Edit form (writers only) */}
|
||||
{data.canWrite ? (
|
||||
<Card>
|
||||
<span className="text-body-default-medium-0 font-body-default-medium-0 text-text-neutral-primary">{t("tasks.detail.section.edit")}</span>
|
||||
<form method="post" className="flex w-full flex-col gap-4" data-ui-id="ui.tasks.detail.edit">
|
||||
<input type="hidden" name="intent" value="update" />
|
||||
<TextInput label={t("tasks.detail.field.title")} showLabel>
|
||||
<TextInput.Input name="title" defaultValue={data.title} required />
|
||||
</TextInput>
|
||||
<TextArea label={t("tasks.detail.field.description")} showLabel>
|
||||
<TextArea.Input name="description" defaultValue={data.description ?? ""} />
|
||||
</TextArea>
|
||||
<div className="flex flex-wrap items-end gap-4">
|
||||
<Select className="max-w-[200px]" name="status" label={t("tasks.detail.field.status")} showLabel defaultValue={data.status}>
|
||||
{STATUSES.map((status) => (
|
||||
<Select.Item key={status} value={status}>
|
||||
{t(`tasks.status.${status}`)}
|
||||
</Select.Item>
|
||||
))}
|
||||
</Select>
|
||||
<Select className="max-w-[200px]" name="priority" label={t("tasks.detail.field.priority")} showLabel defaultValue={data.priority}>
|
||||
{PRIORITIES.map((priority) => (
|
||||
<Select.Item key={priority} value={priority}>
|
||||
{t(`tasks.priority.${priority}`)}
|
||||
</Select.Item>
|
||||
))}
|
||||
</Select>
|
||||
<DateField label={t("tasks.detail.field.deadline")} name="deadline" defaultValue={data.deadlineIso ? data.deadlineIso.slice(0, 10) : ""} />
|
||||
</div>
|
||||
<Button type="submit" className="w-fit">
|
||||
{t("tasks.detail.actions.save")}
|
||||
</Button>
|
||||
</form>
|
||||
|
||||
<form method="post" className="flex w-full flex-wrap items-end gap-4" data-ui-id="ui.tasks.detail.reassign">
|
||||
<input type="hidden" name="intent" value="reassign" />
|
||||
<Select className="max-w-[200px]" name="assigneeType" label={t("tasks.detail.field.assigneeType")} showLabel defaultValue="user">
|
||||
<Select.Item value="user">{t("tasks.detail.assignee.user")}</Select.Item>
|
||||
<Select.Item value="group">{t("tasks.detail.assignee.group")}</Select.Item>
|
||||
</Select>
|
||||
<Select
|
||||
className="max-w-[240px]"
|
||||
name="assigneeId"
|
||||
label={t("tasks.detail.field.assignee")}
|
||||
showLabel
|
||||
defaultValue={data.assignableUsers[0]?.id ?? data.assignableGroups[0]?.id}
|
||||
>
|
||||
{data.assignableUsers.map((user) => (
|
||||
<Select.Item key={`u-${user.id}`} value={user.id}>
|
||||
{user.label}
|
||||
</Select.Item>
|
||||
))}
|
||||
{data.assignableGroups.map((group) => (
|
||||
<Select.Item key={`g-${group.id}`} value={group.id}>
|
||||
{group.label}
|
||||
</Select.Item>
|
||||
))}
|
||||
</Select>
|
||||
<Button type="submit" variant="secondary">
|
||||
{t("tasks.detail.actions.reassign")}
|
||||
</Button>
|
||||
</form>
|
||||
</Card>
|
||||
) : null}
|
||||
|
||||
{/* Watchers */}
|
||||
<div className="flex flex-col gap-3" data-ui-id="ui.tasks.detail.watchers">
|
||||
<span className="text-body-small-medium-0 font-body-small-medium-0 text-text-neutral-tertiary">{t("tasks.detail.section.watchers")}</span>
|
||||
{data.watchers.length > 0 ? (
|
||||
<ul className="flex flex-col gap-2">
|
||||
{data.watchers.map((watcher) => (
|
||||
<li
|
||||
key={watcher.userId}
|
||||
className="flex items-center justify-between gap-3 rounded-md border border-solid border-border-default bg-surface-neutral-primary px-3 py-2"
|
||||
data-watcher-id={watcher.userId}
|
||||
>
|
||||
<span className="text-body-default-regular-0 font-body-default-regular-0 text-text-neutral-primary">{watcher.label}</span>
|
||||
{data.canWrite ? (
|
||||
<form method="post">
|
||||
<input type="hidden" name="intent" value="removeWatcher" />
|
||||
<input type="hidden" name="userId" value={watcher.userId} />
|
||||
<IconButton type="submit" variant="ghost" size="small" icon={<FeatherTrash2 />} aria-label={t("tasks.detail.actions.removeWatcher")} />
|
||||
</form>
|
||||
) : null}
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
) : (
|
||||
<span className="text-body-small-regular-150 font-body-small-regular-150 text-text-neutral-tertiary">{t("tasks.detail.watchers.empty")}</span>
|
||||
)}
|
||||
{data.canWrite && data.assignableUsers.length > 0 ? (
|
||||
<form method="post" className="flex flex-wrap items-end gap-2">
|
||||
<input type="hidden" name="intent" value="addWatcher" />
|
||||
<Select className="max-w-[240px]" name="userId" label={t("tasks.detail.field.watcher")} showLabel defaultValue={data.assignableUsers[0]?.id}>
|
||||
{data.assignableUsers.map((user) => (
|
||||
<Select.Item key={`w-${user.id}`} value={user.id}>
|
||||
{user.label}
|
||||
</Select.Item>
|
||||
))}
|
||||
</Select>
|
||||
<Button type="submit" variant="secondary">
|
||||
{t("tasks.detail.actions.addWatcher")}
|
||||
</Button>
|
||||
</form>
|
||||
) : null}
|
||||
</div>
|
||||
|
||||
{/* Delete confirmation dialog (real ~/ui Dialog, size XS) */}
|
||||
<Dialog open={deleteOpen} onOpenChange={setDeleteOpen}>
|
||||
<Dialog.Content className="w-[420px] max-w-[90vw] p-8">
|
||||
<div className="flex w-full flex-col gap-6">
|
||||
<div className="flex flex-col gap-2">
|
||||
<span className="text-heading-3 font-heading-3 text-text-neutral-primary">{t("tasks.detail.delete.title")}</span>
|
||||
<span className="text-body-default-regular-150 font-body-default-regular-150 text-text-neutral-secondary">{t("tasks.detail.delete.body")}</span>
|
||||
</div>
|
||||
<div className="flex items-center justify-end gap-2">
|
||||
<Button type="button" variant="tertiary" onClick={() => setDeleteOpen(false)}>
|
||||
{t("tasks.detail.dialog.cancel")}
|
||||
</Button>
|
||||
<form method="post">
|
||||
<Button type="submit" name="intent" value="delete" variant="destructive" icon={<FeatherTrash2 />}>
|
||||
{t("tasks.detail.delete.confirm")}
|
||||
</Button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</Dialog.Content>
|
||||
</Dialog>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
+54
@@ -0,0 +1,54 @@
|
||||
import { vi, describe, it, expect } from "vitest";
|
||||
import "@testing-library/jest-dom";
|
||||
import { render } from "@testing-library/react";
|
||||
import { BrowserRouter as Router } from "react-router";
|
||||
|
||||
import { TaskNewPage, type TaskNewPageProps } from "./TaskNewPage";
|
||||
|
||||
vi.mock("react-i18next", () => ({
|
||||
useTranslation: () => ({ t: (str: string) => str, i18n: { language: "de" } }),
|
||||
}));
|
||||
|
||||
function baseProps(overrides: Partial<TaskNewPageProps> = {}): TaskNewPageProps {
|
||||
return {
|
||||
assignableUsers: [{ id: "u1", label: "Alex Meier" }],
|
||||
assignableGroups: [{ id: "g1", label: "Vertrieb" }],
|
||||
prefill: null,
|
||||
cancelHref: "/acme/tasks",
|
||||
...overrides,
|
||||
};
|
||||
}
|
||||
|
||||
describe("TaskNewPage (interim-UI)", () => {
|
||||
it("renders the create form surface + title/submit/cancel markers", () => {
|
||||
const { container } = render(
|
||||
<Router>
|
||||
<TaskNewPage {...baseProps()} />
|
||||
</Router>,
|
||||
);
|
||||
expect(container.querySelector('[data-ui-id="ui.tasks.new"]')).toBeInTheDocument();
|
||||
expect(container.querySelector('[data-ui-id="ui.tasks.new.title"]')).toBeInTheDocument();
|
||||
expect(container.querySelector('[data-ui-id="ui.tasks.new.submit"]')).toBeInTheDocument();
|
||||
expect(container.querySelector('[data-ui-id="ui.tasks.new.cancel"]')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("renders the entity prefill marker + hidden inputs when prefilled", () => {
|
||||
const { container } = render(
|
||||
<Router>
|
||||
<TaskNewPage {...baseProps({ prefill: { entityType: "contact", entityId: "c9" } })} />
|
||||
</Router>,
|
||||
);
|
||||
expect(container.querySelector('[data-ui-id="ui.tasks.new.prefill"]')).toBeInTheDocument();
|
||||
expect(container.querySelector('input[type="hidden"][name="entityType"][value="contact"]')).toBeInTheDocument();
|
||||
expect(container.querySelector('input[type="hidden"][name="entityId"][value="c9"]')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("omits the prefill block when not prefilled", () => {
|
||||
const { container } = render(
|
||||
<Router>
|
||||
<TaskNewPage {...baseProps()} />
|
||||
</Router>,
|
||||
);
|
||||
expect(container.querySelector('[data-ui-id="ui.tasks.new.prefill"]')).not.toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
+111
@@ -0,0 +1,111 @@
|
||||
// AK-P4b Interim-UI (AD-28) — Task create preview screen composed from ~/ui.
|
||||
// Presentational: the form posts to the route action (server-driven create); the
|
||||
// loader injects the assignee picker options + optional entity pre-fill. No
|
||||
// useLoaderData / server imports. Final Subframe optics land as a design-nachzug.
|
||||
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { FeatherPlus } from "@subframe/core";
|
||||
import type { TaskPriority } from "@hivegrid/view-models";
|
||||
import { Breadcrumbs } from "~/ui/components/Breadcrumbs";
|
||||
import { Button } from "~/ui/components/Button";
|
||||
import { Card } from "~/ui/components/Card";
|
||||
import { Select } from "~/ui/components/Select";
|
||||
import { TextArea } from "~/ui/components/TextArea";
|
||||
import { TextInput } from "~/ui/components/TextInput";
|
||||
import { DateField } from "./DateField";
|
||||
|
||||
const PRIORITIES: readonly TaskPriority[] = ["low", "normal", "high", "urgent"];
|
||||
|
||||
// The ~/ui Select forbids an empty-string option value, so the "creator (default)"
|
||||
// choice uses a sentinel. The route action maps it back to "no explicit assignee".
|
||||
export const TASK_CREATOR_ASSIGNEE = "__creator__";
|
||||
|
||||
export type TaskPickerOption = { readonly id: string; readonly label: string };
|
||||
export type TaskNewPrefill = { readonly entityType: string; readonly entityId: string } | null;
|
||||
|
||||
export type TaskNewPageProps = {
|
||||
assignableUsers: readonly TaskPickerOption[];
|
||||
assignableGroups: readonly TaskPickerOption[];
|
||||
prefill: TaskNewPrefill;
|
||||
/** Back link to the task list (breadcrumb / cancel target). */
|
||||
cancelHref: string;
|
||||
};
|
||||
|
||||
export function TaskNewPage({ assignableUsers, assignableGroups, prefill, cancelHref }: TaskNewPageProps) {
|
||||
const { t } = useTranslation();
|
||||
|
||||
return (
|
||||
<div className="flex w-full max-w-[720px] flex-col gap-6 p-6" data-ui-id="ui.tasks.new">
|
||||
<Breadcrumbs>
|
||||
<a href={cancelHref} className="no-underline">
|
||||
<Breadcrumbs.Item>{t("tasks.nav.title")}</Breadcrumbs.Item>
|
||||
</a>
|
||||
<Breadcrumbs.Divider />
|
||||
<Breadcrumbs.Item active>{t("tasks.new.title")}</Breadcrumbs.Item>
|
||||
</Breadcrumbs>
|
||||
|
||||
<span className="text-heading-2 font-heading-2 text-text-neutral-primary">{t("tasks.new.title")}</span>
|
||||
|
||||
<Card>
|
||||
<form method="post" className="flex w-full flex-col gap-4">
|
||||
<TextInput label={t("tasks.detail.field.title")} showLabel>
|
||||
<TextInput.Input name="title" required data-ui-id="ui.tasks.new.title" />
|
||||
</TextInput>
|
||||
<TextArea label={t("tasks.detail.field.description")} showLabel>
|
||||
<TextArea.Input name="description" />
|
||||
</TextArea>
|
||||
<div className="flex flex-wrap items-end gap-4">
|
||||
<Select className="max-w-[200px]" name="priority" label={t("tasks.detail.field.priority")} showLabel defaultValue="normal">
|
||||
{PRIORITIES.map((priority) => (
|
||||
<Select.Item key={priority} value={priority}>
|
||||
{t(`tasks.priority.${priority}`)}
|
||||
</Select.Item>
|
||||
))}
|
||||
</Select>
|
||||
<DateField label={t("tasks.detail.field.deadline")} name="deadline" />
|
||||
</div>
|
||||
<div className="flex flex-wrap items-end gap-4">
|
||||
<Select className="max-w-[200px]" name="assigneeType" label={t("tasks.detail.field.assigneeType")} showLabel defaultValue="user">
|
||||
<Select.Item value="user">{t("tasks.detail.assignee.user")}</Select.Item>
|
||||
<Select.Item value="group">{t("tasks.detail.assignee.group")}</Select.Item>
|
||||
</Select>
|
||||
<Select className="max-w-[240px]" name="assigneeId" label={t("tasks.detail.field.assignee")} showLabel defaultValue={TASK_CREATOR_ASSIGNEE}>
|
||||
<Select.Item value={TASK_CREATOR_ASSIGNEE}>{t("tasks.new.assignee.default")}</Select.Item>
|
||||
{assignableUsers.map((user) => (
|
||||
<Select.Item key={`u-${user.id}`} value={user.id}>
|
||||
{user.label}
|
||||
</Select.Item>
|
||||
))}
|
||||
{assignableGroups.map((group) => (
|
||||
<Select.Item key={`g-${group.id}`} value={group.id}>
|
||||
{group.label}
|
||||
</Select.Item>
|
||||
))}
|
||||
</Select>
|
||||
</div>
|
||||
|
||||
{prefill ? (
|
||||
<div data-ui-id="ui.tasks.new.prefill">
|
||||
<input type="hidden" name="entityType" value={prefill.entityType} />
|
||||
<input type="hidden" name="entityId" value={prefill.entityId} />
|
||||
<span className="text-body-small-regular-0 font-body-small-regular-0 text-text-neutral-tertiary">
|
||||
{t(`tasks.entity.${prefill.entityType}`)} · {prefill.entityId}
|
||||
</span>
|
||||
</div>
|
||||
) : null}
|
||||
|
||||
<div className="flex items-center gap-2">
|
||||
<Button type="submit" icon={<FeatherPlus />} data-ui-id="ui.tasks.new.submit">
|
||||
{t("tasks.new.actions.create")}
|
||||
</Button>
|
||||
<a href={cancelHref} className="no-underline" data-ui-id="ui.tasks.new.cancel">
|
||||
<Button type="button" variant="tertiary">
|
||||
{t("tasks.new.actions.cancel")}
|
||||
</Button>
|
||||
</a>
|
||||
</div>
|
||||
</form>
|
||||
</Card>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
+101
@@ -0,0 +1,101 @@
|
||||
import { vi, describe, it, expect } from "vitest";
|
||||
import "@testing-library/jest-dom";
|
||||
import { render } from "@testing-library/react";
|
||||
import { BrowserRouter as Router } from "react-router";
|
||||
import {
|
||||
buildTaskListVM,
|
||||
taskPriorityKey,
|
||||
taskStatusKey,
|
||||
type TaskListFilterState,
|
||||
type TaskListRow,
|
||||
} from "@hivegrid/view-models";
|
||||
|
||||
import { TasksListPage } from "./TasksListPage";
|
||||
|
||||
vi.mock("react-i18next", () => ({
|
||||
useTranslation: () => ({ t: (str: string) => str, i18n: { language: "de" } }),
|
||||
}));
|
||||
|
||||
function row(overrides: Partial<TaskListRow> = {}): TaskListRow {
|
||||
return {
|
||||
id: "t1",
|
||||
title: "Angebot nachfassen",
|
||||
status: "open",
|
||||
statusKey: taskStatusKey("open"),
|
||||
priority: "high",
|
||||
priorityKey: taskPriorityKey("high"),
|
||||
deadlineIso: "2026-02-01T10:00:00.000Z",
|
||||
isOverdue: false,
|
||||
assignee: { kind: "user", label: "Alex Meier" },
|
||||
linkedEntity: null,
|
||||
source: "manual",
|
||||
sourceKey: "tasks.source.manual",
|
||||
sourceHref: null,
|
||||
detailHref: "/acme/tasks/t1",
|
||||
...overrides,
|
||||
};
|
||||
}
|
||||
|
||||
const filter: TaskListFilterState = { preset: "all", status: null, priority: null, assignedToUserId: null, includeArchived: false };
|
||||
|
||||
function baseProps() {
|
||||
return { includeDemoData: false, nextHref: null, actions: { onApply: vi.fn() } };
|
||||
}
|
||||
|
||||
describe("TasksListPage (interim-UI)", () => {
|
||||
it("renders the browser surface + table rows from the VM", () => {
|
||||
const vm = buildTaskListVM({ rows: [row()], filter, canWrite: true, canDelete: false, createHref: "/acme/tasks/new" });
|
||||
const { container, getByText } = render(
|
||||
<Router>
|
||||
<TasksListPage vm={vm} {...baseProps()} />
|
||||
</Router>,
|
||||
);
|
||||
expect(container.querySelector('[data-ui-id="ui.tasks.list"]')).toBeInTheDocument();
|
||||
expect(container.querySelector('[data-ui-id="ui.tasks.list.table"]')).toBeInTheDocument();
|
||||
expect(container.querySelector('[data-row-id="t1"]')).toBeInTheDocument();
|
||||
expect(getByText("Angebot nachfassen")).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("shows the empty state when there are no rows", () => {
|
||||
const vm = buildTaskListVM({ rows: [], filter, canWrite: true, canDelete: false, createHref: "/acme/tasks/new" });
|
||||
const { container } = render(
|
||||
<Router>
|
||||
<TasksListPage vm={vm} {...baseProps()} />
|
||||
</Router>,
|
||||
);
|
||||
expect(container.querySelector('[data-ui-id="ui.tasks.list.empty"]')).toBeInTheDocument();
|
||||
expect(container.querySelector('[data-ui-id="ui.tasks.list.table"]')).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("renders the create CTA only when the user may write", () => {
|
||||
const readonlyVm = buildTaskListVM({ rows: [row()], filter, canWrite: false, canDelete: false, createHref: "/acme/tasks/new" });
|
||||
const { container } = render(
|
||||
<Router>
|
||||
<TasksListPage vm={readonlyVm} {...baseProps()} />
|
||||
</Router>,
|
||||
);
|
||||
expect(container.querySelector('[data-ui-id="ui.tasks.list.new"]')).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("renders the preset tabs + status/priority filter selects", () => {
|
||||
const vm = buildTaskListVM({ rows: [row()], filter, canWrite: true, canDelete: false, createHref: "/acme/tasks/new" });
|
||||
const { container, getByText } = render(
|
||||
<Router>
|
||||
<TasksListPage vm={vm} {...baseProps()} />
|
||||
</Router>,
|
||||
);
|
||||
expect(container.querySelector('[data-ui-id="ui.tasks.list.presets"]')).toBeInTheDocument();
|
||||
expect(getByText("tasks.list.filter.status.label")).toBeInTheDocument();
|
||||
expect(getByText("tasks.list.filter.priority.label")).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("shows the pagination link when a next page exists", () => {
|
||||
const vm = buildTaskListVM({ rows: [row()], filter, canWrite: true, canDelete: false, createHref: "/acme/tasks/new", nextCursor: "cur2" });
|
||||
const { container } = render(
|
||||
<Router>
|
||||
<TasksListPage vm={vm} {...{ ...baseProps(), nextHref: "?cursor=cur2" }} />
|
||||
</Router>,
|
||||
);
|
||||
expect(container.querySelector('[data-ui-id="ui.tasks.list.pagination"]')).toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
+242
@@ -0,0 +1,242 @@
|
||||
// AK-P4b Interim-UI (AD-28) — Tasks browser preview screen composed from ~/ui.
|
||||
// Pure presentational component: renders the server-built TaskListVM passed as a
|
||||
// prop and reports preset/filter changes through injected actions (server-side
|
||||
// navigation). No useLoaderData, no server imports. This is the REUSABLE task list
|
||||
// (DoD 8); the standalone /tasks route is its host, entity detail views embed it.
|
||||
// Final Subframe optics land as a tracked design-nachzug once David's D-P4 ships.
|
||||
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { FeatherPlus } from "@subframe/core";
|
||||
import type { TaskListPreset, TaskListRow, TaskListVM, TaskPriority, TaskStatus } from "@hivegrid/view-models";
|
||||
import { BadgeFeedback } from "~/ui/components/BadgeFeedback";
|
||||
import { Button } from "~/ui/components/Button";
|
||||
import { Checkbox } from "~/ui/components/Checkbox";
|
||||
import { EmptyState } from "~/ui/components/EmptyState";
|
||||
import { Select } from "~/ui/components/Select";
|
||||
import { Table } from "~/ui/components/Table";
|
||||
import { Tag_Label } from "~/ui/components/Tag_Label";
|
||||
import { ToggleGroup } from "~/ui/components/ToggleGroup";
|
||||
|
||||
const PRESETS: readonly TaskListPreset[] = ["mine", "created", "all"];
|
||||
const STATUSES: readonly TaskStatus[] = ["open", "in_progress", "blocked", "done", "cancelled"];
|
||||
const PRIORITIES: readonly TaskPriority[] = ["low", "normal", "high", "urgent"];
|
||||
|
||||
// Shared "no filter" sentinel for the status/priority Selects (empty string is not
|
||||
// a valid Select value, so a non-empty sentinel maps back to null).
|
||||
const FILTER_ALL = "__all__";
|
||||
|
||||
export type TaskListQuery = {
|
||||
preset: TaskListPreset;
|
||||
status: TaskStatus | null;
|
||||
priority: TaskPriority | null;
|
||||
includeArchived: boolean;
|
||||
includeDemoData: boolean;
|
||||
};
|
||||
|
||||
export type TasksListActions = {
|
||||
/** Navigate (GET) to the same route with the given preset/filter state. */
|
||||
onApply: (query: TaskListQuery) => void;
|
||||
};
|
||||
|
||||
export type TasksListPageProps = {
|
||||
vm: TaskListVM;
|
||||
/** Whether demo-data rows are currently shown (kept out of the VM). */
|
||||
includeDemoData: boolean;
|
||||
/** Href for the next cursor page, or null on the last page. */
|
||||
nextHref: string | null;
|
||||
actions: TasksListActions;
|
||||
};
|
||||
|
||||
type BadgeFarbe = "subtle-positive" | "subtle-warning" | "subtle-negative" | "subtle-neutral";
|
||||
|
||||
function statusFarbe(status: TaskStatus): BadgeFarbe {
|
||||
switch (status) {
|
||||
case "done":
|
||||
return "subtle-positive";
|
||||
case "blocked":
|
||||
return "subtle-negative";
|
||||
case "in_progress":
|
||||
return "subtle-warning";
|
||||
case "cancelled":
|
||||
case "open":
|
||||
default:
|
||||
return "subtle-neutral";
|
||||
}
|
||||
}
|
||||
|
||||
export function TasksListPage({ vm, includeDemoData, nextHref, actions }: TasksListPageProps) {
|
||||
const { t, i18n } = useTranslation();
|
||||
|
||||
// Loading / not-ready: keep the marker so the shell + e2e see a stable surface.
|
||||
if (vm.status !== "ready" || !vm.data) {
|
||||
return <div className="flex w-full flex-col gap-6 p-6" data-ui-id="ui.tasks.list" />;
|
||||
}
|
||||
|
||||
const { rows, filter, canWrite, createHref, emptyHeadlineKey, emptyBodyKey } = vm.data;
|
||||
const dateFormatter = new Intl.DateTimeFormat(i18n.language, { dateStyle: "medium" });
|
||||
|
||||
function applyPatch(patch: Partial<TaskListQuery>) {
|
||||
actions.onApply({
|
||||
preset: filter.preset,
|
||||
status: filter.status,
|
||||
priority: filter.priority,
|
||||
includeArchived: filter.includeArchived,
|
||||
includeDemoData,
|
||||
...patch,
|
||||
});
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="flex w-full flex-col gap-6 p-6" data-ui-id="ui.tasks.list">
|
||||
{/* Header: title + subtitle (0px rhythm) + create CTA */}
|
||||
<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("tasks.list.title")}</span>
|
||||
<span className="text-body-default-regular-150 font-body-default-regular-150 text-text-neutral-secondary">
|
||||
{t("tasks.list.subtitle")}
|
||||
</span>
|
||||
</div>
|
||||
{canWrite ? (
|
||||
<a href={createHref} className="no-underline" data-ui-id="ui.tasks.list.new">
|
||||
<Button icon={<FeatherPlus />}>{t("tasks.list.actions.new")}</Button>
|
||||
</a>
|
||||
) : null}
|
||||
</div>
|
||||
|
||||
{/* Preset tabs (server-side navigation) */}
|
||||
<div className="flex flex-wrap items-center gap-4" data-ui-id="ui.tasks.list.presets">
|
||||
<ToggleGroup
|
||||
value={filter.preset}
|
||||
onValueChange={(value: string) => {
|
||||
if (PRESETS.includes(value as TaskListPreset)) applyPatch({ preset: value as TaskListPreset });
|
||||
}}
|
||||
>
|
||||
{PRESETS.map((preset) => (
|
||||
<ToggleGroup.Item key={preset} value={preset} aria-label={t(`tasks.list.preset.${preset}`)}>
|
||||
{t(`tasks.list.preset.${preset}`)}
|
||||
</ToggleGroup.Item>
|
||||
))}
|
||||
</ToggleGroup>
|
||||
</div>
|
||||
|
||||
{/* Filter bar (server-side, navigation on change) */}
|
||||
<div className="flex flex-wrap items-center gap-4" data-ui-id="ui.tasks.list.filter">
|
||||
<Select
|
||||
className="max-w-[240px]"
|
||||
label={t("tasks.list.filter.status.label")}
|
||||
showLabel
|
||||
value={filter.status ?? FILTER_ALL}
|
||||
onValueChange={(value: string) => applyPatch({ status: value === FILTER_ALL ? null : (value as TaskStatus) })}
|
||||
>
|
||||
<Select.Item value={FILTER_ALL}>{t("tasks.list.filter.status.all")}</Select.Item>
|
||||
{STATUSES.map((status) => (
|
||||
<Select.Item key={status} value={status}>
|
||||
{t(`tasks.status.${status}`)}
|
||||
</Select.Item>
|
||||
))}
|
||||
</Select>
|
||||
<Select
|
||||
className="max-w-[240px]"
|
||||
label={t("tasks.list.filter.priority.label")}
|
||||
showLabel
|
||||
value={filter.priority ?? FILTER_ALL}
|
||||
onValueChange={(value: string) => applyPatch({ priority: value === FILTER_ALL ? null : (value as TaskPriority) })}
|
||||
>
|
||||
<Select.Item value={FILTER_ALL}>{t("tasks.list.filter.priority.all")}</Select.Item>
|
||||
{PRIORITIES.map((priority) => (
|
||||
<Select.Item key={priority} value={priority}>
|
||||
{t(`tasks.priority.${priority}`)}
|
||||
</Select.Item>
|
||||
))}
|
||||
</Select>
|
||||
<Checkbox
|
||||
label={t("tasks.list.filter.archived")}
|
||||
checked={filter.includeArchived}
|
||||
onCheckedChange={(checked: boolean) => applyPatch({ includeArchived: checked })}
|
||||
/>
|
||||
<Checkbox
|
||||
label={t("tasks.list.filter.demo")}
|
||||
checked={includeDemoData}
|
||||
onCheckedChange={(checked: boolean) => applyPatch({ includeDemoData: checked })}
|
||||
/>
|
||||
</div>
|
||||
|
||||
{rows.length === 0 ? (
|
||||
<div data-ui-id="ui.tasks.list.empty">
|
||||
<EmptyState title={t(emptyHeadlineKey)} body={t(emptyBodyKey)} />
|
||||
</div>
|
||||
) : (
|
||||
<TableView rows={rows} dateFormatter={dateFormatter} t={t} statusFarbe={statusFarbe} />
|
||||
)}
|
||||
|
||||
{nextHref ? (
|
||||
<div className="flex justify-center pt-2" data-ui-id="ui.tasks.list.pagination">
|
||||
<a href={nextHref} className="no-underline">
|
||||
<Button variant="tertiary">{t("tasks.list.pagination.next")}</Button>
|
||||
</a>
|
||||
</div>
|
||||
) : null}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function TableView({
|
||||
rows,
|
||||
dateFormatter,
|
||||
t,
|
||||
statusFarbe,
|
||||
}: {
|
||||
rows: readonly TaskListRow[];
|
||||
dateFormatter: Intl.DateTimeFormat;
|
||||
t: (key: string) => string;
|
||||
statusFarbe: (status: TaskStatus) => BadgeFarbe;
|
||||
}) {
|
||||
return (
|
||||
<div className="w-full overflow-x-auto" data-ui-id="ui.tasks.list.table">
|
||||
<Table
|
||||
header={
|
||||
<Table.HeaderRow>
|
||||
<Table.HeaderCell>{t("tasks.list.column.title")}</Table.HeaderCell>
|
||||
<Table.HeaderCell>{t("tasks.list.column.status")}</Table.HeaderCell>
|
||||
<Table.HeaderCell>{t("tasks.list.column.priority")}</Table.HeaderCell>
|
||||
<Table.HeaderCell>{t("tasks.list.column.assignee")}</Table.HeaderCell>
|
||||
<Table.HeaderCell>{t("tasks.list.column.deadline")}</Table.HeaderCell>
|
||||
</Table.HeaderRow>
|
||||
}
|
||||
>
|
||||
{rows.map((row) => (
|
||||
<Table.Row key={row.id} data-row-id={row.id}>
|
||||
<Table.Cell>
|
||||
<a href={row.detailHref} className="text-body-default-medium-0 font-body-default-medium-0 text-text-feedback-link-default">
|
||||
{row.title}
|
||||
</a>
|
||||
</Table.Cell>
|
||||
<Table.Cell>
|
||||
<BadgeFeedback farbe={statusFarbe(row.status)} size="small">
|
||||
{t(row.statusKey)}
|
||||
</BadgeFeedback>
|
||||
</Table.Cell>
|
||||
<Table.Cell>
|
||||
<Tag_Label tone="neutral-subtle" size="small" noAction>
|
||||
{t(row.priorityKey)}
|
||||
</Tag_Label>
|
||||
</Table.Cell>
|
||||
<Table.Cell>
|
||||
<span className="text-body-default-regular-0 font-body-default-regular-0 text-text-neutral-secondary">
|
||||
{row.assignee ? row.assignee.label : t("tasks.detail.unassigned")}
|
||||
</span>
|
||||
</Table.Cell>
|
||||
<Table.Cell>
|
||||
<span
|
||||
className="text-body-default-regular-0 font-body-default-regular-0 text-text-neutral-secondary"
|
||||
data-overdue={row.isOverdue}
|
||||
>
|
||||
{row.deadlineIso ? dateFormatter.format(new Date(row.deadlineIso)) : "—"}
|
||||
</span>
|
||||
</Table.Cell>
|
||||
</Table.Row>
|
||||
))}
|
||||
</Table>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
+171
@@ -0,0 +1,171 @@
|
||||
// R-P2b — groups bulk add/remove (interim UI per AD-28). David parked groups
|
||||
// for RBAC V2, so this is a `~/ui` preview screen with an open design-nachzug:
|
||||
// a real Dialog (M 720) with the group's members and the remaining tenant
|
||||
// members as checkbox pick lists, wired to the idempotent bulk backend ops.
|
||||
// Pure presentational: VM + action callbacks as props, no loader access.
|
||||
|
||||
import { useState } from "react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import type { GroupMemberRow, GroupsDetailVM } from "@hivegrid/view-models";
|
||||
import { filterGroupMemberRows } from "@hivegrid/view-models";
|
||||
import { Avatar } from "~/ui/components/Avatar";
|
||||
import { Button } from "~/ui/components/Button";
|
||||
import { Checkbox } from "~/ui/components/Checkbox";
|
||||
import { Dialog } from "~/ui/components/Dialog";
|
||||
import { EmptyState } from "~/ui/components/EmptyState";
|
||||
import { SearchInput } from "~/ui/components/SearchInput";
|
||||
|
||||
export type GroupMembersActions = {
|
||||
/** Posts the `bulk-add` intent (idempotent addUsersToGroup). */
|
||||
onAdd: (userIds: string[]) => void;
|
||||
/** Posts the `bulk-remove` intent (idempotent removeUsersFromGroup). */
|
||||
onRemove: (userIds: string[]) => void;
|
||||
};
|
||||
|
||||
export function GroupMembersDialog({
|
||||
vm,
|
||||
actions,
|
||||
submitting,
|
||||
onClose,
|
||||
}: {
|
||||
vm: GroupsDetailVM;
|
||||
actions: GroupMembersActions;
|
||||
submitting: boolean;
|
||||
onClose: () => void;
|
||||
}) {
|
||||
const { t } = useTranslation();
|
||||
const [query, setQuery] = useState("");
|
||||
const [selectedMembers, setSelectedMembers] = useState<ReadonlySet<string>>(new Set());
|
||||
const [selectedCandidates, setSelectedCandidates] = useState<ReadonlySet<string>>(new Set());
|
||||
|
||||
if (vm.status !== "ready" || !vm.data) return null;
|
||||
const data = vm.data;
|
||||
|
||||
const members = filterGroupMemberRows(data.memberRows, query);
|
||||
const candidates = filterGroupMemberRows(data.candidateRows, query);
|
||||
|
||||
function toggle(set: ReadonlySet<string>, userId: string, next: (value: Set<string>) => void) {
|
||||
const updated = new Set(set);
|
||||
if (updated.has(userId)) updated.delete(userId);
|
||||
else updated.add(userId);
|
||||
next(updated);
|
||||
}
|
||||
|
||||
return (
|
||||
<Dialog open onOpenChange={(open: boolean) => (open ? undefined : onClose())}>
|
||||
<Dialog.Content className="w-[720px] max-w-[95vw] p-6">
|
||||
<div className="flex w-full flex-col gap-6" data-ui-id="ui.settings.groups.bulk.dialog">
|
||||
<div className="flex flex-col gap-0">
|
||||
<span className="text-heading-3 font-heading-3 text-text-neutral-primary">
|
||||
{t("settings.members.groups.bulk.title", { name: data.name })}
|
||||
</span>
|
||||
<span className="text-body-default-regular-150 font-body-default-regular-150 text-text-neutral-secondary">
|
||||
{t("settings.members.groups.bulk.description")}
|
||||
</span>
|
||||
</div>
|
||||
|
||||
<SearchInput
|
||||
className="max-w-[320px]"
|
||||
placeholder={t("settings.members.groups.bulk.searchPlaceholder")}
|
||||
hideShortcut
|
||||
value={query}
|
||||
onChange={(event) => setQuery(event.target.value)}
|
||||
/>
|
||||
|
||||
<div className="flex w-full gap-6 mobile:flex-col">
|
||||
<PickList
|
||||
titleKey="settings.members.groups.bulk.membersTitle"
|
||||
rows={members}
|
||||
emptyKey={data.emptyMembersKey}
|
||||
selected={selectedMembers}
|
||||
onToggle={(userId) => toggle(selectedMembers, userId, setSelectedMembers)}
|
||||
dataUiId="ui.settings.groups.bulk.members"
|
||||
/>
|
||||
<PickList
|
||||
titleKey="settings.members.groups.bulk.candidatesTitle"
|
||||
rows={candidates}
|
||||
emptyKey={data.emptyCandidatesKey}
|
||||
selected={selectedCandidates}
|
||||
onToggle={(userId) => toggle(selectedCandidates, userId, setSelectedCandidates)}
|
||||
dataUiId="ui.settings.groups.bulk.candidates"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className="flex w-full flex-wrap items-center justify-end gap-2">
|
||||
<Button variant="tertiary" onClick={onClose}>
|
||||
{t("shared.close")}
|
||||
</Button>
|
||||
{data.canManage ? (
|
||||
<>
|
||||
<Button
|
||||
variant="destructive"
|
||||
disabled={selectedMembers.size === 0}
|
||||
loading={submitting}
|
||||
onClick={() => {
|
||||
actions.onRemove([...selectedMembers]);
|
||||
setSelectedMembers(new Set());
|
||||
}}
|
||||
data-ui-id="ui.settings.groups.bulk.remove"
|
||||
>
|
||||
{t("settings.members.groups.bulk.removeSelected", { count: selectedMembers.size })}
|
||||
</Button>
|
||||
<Button
|
||||
disabled={selectedCandidates.size === 0}
|
||||
loading={submitting}
|
||||
onClick={() => {
|
||||
actions.onAdd([...selectedCandidates]);
|
||||
setSelectedCandidates(new Set());
|
||||
}}
|
||||
data-ui-id="ui.settings.groups.bulk.add"
|
||||
>
|
||||
{t("settings.members.groups.bulk.addSelected", { count: selectedCandidates.size })}
|
||||
</Button>
|
||||
</>
|
||||
) : null}
|
||||
</div>
|
||||
</div>
|
||||
</Dialog.Content>
|
||||
</Dialog>
|
||||
);
|
||||
}
|
||||
|
||||
function PickList({
|
||||
titleKey,
|
||||
rows,
|
||||
emptyKey,
|
||||
selected,
|
||||
onToggle,
|
||||
dataUiId,
|
||||
}: {
|
||||
titleKey: string;
|
||||
rows: readonly GroupMemberRow[];
|
||||
emptyKey: string;
|
||||
selected: ReadonlySet<string>;
|
||||
onToggle: (userId: string) => void;
|
||||
dataUiId: string;
|
||||
}) {
|
||||
const { t } = useTranslation();
|
||||
return (
|
||||
<div className="flex w-full flex-col gap-4" data-ui-id={dataUiId}>
|
||||
<span className="text-body-default-medium-0 font-body-default-medium-0 text-text-neutral-primary">{t(titleKey)}</span>
|
||||
{rows.length === 0 ? (
|
||||
<EmptyState variant="no-results" title={t(emptyKey)} />
|
||||
) : (
|
||||
<div className="flex max-h-[40vh] w-full flex-col gap-2 overflow-y-auto">
|
||||
{rows.map((row) => (
|
||||
<div key={row.userId} className="flex w-full items-center justify-between gap-3">
|
||||
<div className="flex items-center gap-3">
|
||||
<Avatar size="small">{row.initials}</Avatar>
|
||||
<div className="flex flex-col items-start">
|
||||
<span className="whitespace-nowrap text-body-default-regular-0 font-body-default-regular-0 text-text-neutral-primary">{row.name}</span>
|
||||
<span className="whitespace-nowrap text-body-small-regular-0 font-body-small-regular-0 text-text-neutral-tertiary">{row.email}</span>
|
||||
</div>
|
||||
</div>
|
||||
<Checkbox checked={selected.has(row.userId)} onCheckedChange={() => onToggle(row.userId)} />
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
+69
@@ -0,0 +1,69 @@
|
||||
// R-P2b — D-P2 "WF-P2 Admin RBAC" M01 "Mitarbeiter einladen" form in David's
|
||||
// Subframe optics (real Dialog content, S 560 — the members route wraps the
|
||||
// outlet in Dialog.Content). Posts to the existing members/new action, keeping
|
||||
// the invite contract (fields email/first-name/last-name/send-invitation-email,
|
||||
// csrf, data-ui-id ui.settings.members.new.form) untouched.
|
||||
// Role-at-invite from David's wireframe is NOT built: the invitation backend
|
||||
// stores no role — roles are assigned in the list (D01) after acceptance.
|
||||
|
||||
import { useEffect, useState } from "react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { Form, useActionData, useNavigation } from "react-router";
|
||||
import toast from "react-hot-toast";
|
||||
import type { NewMemberActionData } from "~/routes/app.$tenant/settings/members/new";
|
||||
import { useRootData } from "~/utils/data/useRootData";
|
||||
import { Button } from "~/ui/components/Button";
|
||||
import { Checkbox } from "~/ui/components/Checkbox";
|
||||
import { TextInput } from "~/ui/components/TextInput";
|
||||
|
||||
export function InviteMemberForm({ onClose }: { onClose: () => void }) {
|
||||
const { t } = useTranslation();
|
||||
const actionData = useActionData<NewMemberActionData>();
|
||||
const navigation = useNavigation();
|
||||
const rootData = useRootData();
|
||||
const loading = navigation.state === "submitting";
|
||||
// ~/ui Checkbox is controlled-only — mirror it into a hidden field for the action.
|
||||
const [sendEmail, setSendEmail] = useState(false);
|
||||
|
||||
useEffect(() => {
|
||||
if (actionData?.error) toast.error(actionData.error);
|
||||
}, [actionData]);
|
||||
|
||||
return (
|
||||
<Form method="post" className="flex w-full flex-col gap-6" data-ui-id="ui.settings.members.new.form">
|
||||
{rootData.csrf && <input type="hidden" name="csrf" value={rootData.csrf} />}
|
||||
<div className="flex flex-col gap-2">
|
||||
<span className="text-heading-3 font-heading-3 text-text-neutral-primary">{t("settings.members.form.newTitle")}</span>
|
||||
<span className="text-body-default-regular-150 font-body-default-regular-150 text-text-neutral-secondary">
|
||||
{t("settings.members.form.newDescription")}
|
||||
</span>
|
||||
</div>
|
||||
<div className="flex w-full flex-col gap-4">
|
||||
<TextInput className="w-full" label={t("models.user.email")} showLabel>
|
||||
<TextInput.Input name="email" type="email" required autoComplete="off" defaultValue={actionData?.fields?.email} />
|
||||
</TextInput>
|
||||
<div className="flex w-full gap-4">
|
||||
<TextInput className="w-full" label={t("models.user.firstName")} showLabel>
|
||||
<TextInput.Input name="first-name" required autoComplete="off" defaultValue={actionData?.fields?.firstName} />
|
||||
</TextInput>
|
||||
<TextInput className="w-full" label={t("models.user.lastName")} showLabel>
|
||||
<TextInput.Input name="last-name" autoComplete="off" defaultValue={actionData?.fields?.lastName} />
|
||||
</TextInput>
|
||||
</div>
|
||||
{/* Radix renders the form-proxy input for `name` (posts "on" when checked). */}
|
||||
<Checkbox name="send-invitation-email" label={t("settings.members.sendInvitationEmail.title")} checked={sendEmail} onCheckedChange={setSendEmail} />
|
||||
<span className="text-body-small-regular-150 font-body-small-regular-150 text-text-neutral-tertiary">
|
||||
{t("settings.members.sendInvitationEmail.description")}
|
||||
</span>
|
||||
</div>
|
||||
<div className="flex w-full items-center justify-end gap-2">
|
||||
<Button type="button" variant="tertiary" onClick={onClose} data-ui-id="ui.settings.members.new.cancel">
|
||||
{t("shared.cancel")}
|
||||
</Button>
|
||||
<Button type="submit" loading={loading} data-ui-id="ui.settings.members.new.submit">
|
||||
{t("settings.members.actions.new")}
|
||||
</Button>
|
||||
</div>
|
||||
</Form>
|
||||
);
|
||||
}
|
||||
+420
@@ -0,0 +1,420 @@
|
||||
// R-P2b — D-P2 "WF-P2 Admin RBAC" S01 Mitarbeiterliste in David's Subframe optics.
|
||||
// Pure presentational component: renders the server-built MembersListVM passed
|
||||
// as a prop and reports mutations through injected actions (route posts the
|
||||
// intents). No useLoaderData, no server imports (AD-28 / DoD A.5).
|
||||
// S01 — list with search + role/status/2FA filters, invited rows inline
|
||||
// D01 — inline role dropdown per row (checkbox items + link to S02)
|
||||
// M03 — deactivate confirm as a real Dialog (XS 420, danger action)
|
||||
// V01 — last-admin blocker dialog (server code "last-admin" opens it)
|
||||
// Reassign-on-deactivate is Backlog/V2 by David's decision — plain confirm only.
|
||||
|
||||
import { useEffect, useState } from "react";
|
||||
import { Link } from "react-router";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import * as SubframeCore from "@subframe/core";
|
||||
import { FeatherChevronDown, FeatherMoreHorizontal, FeatherPlus, FeatherTrash, FeatherUserCheck, FeatherUserX } from "@subframe/core";
|
||||
import type { MembersListRow, MembersListVM } from "@hivegrid/view-models";
|
||||
import { EMPTY_MEMBERS_FILTER, filterMembersRows, type MembersListFilterState, type MemberStatus } from "@hivegrid/view-models";
|
||||
import { roleDisplayName } from "~/components/core/roles/roleDisplay";
|
||||
import { Avatar } from "~/ui/components/Avatar";
|
||||
import { BadgeFeedback } from "~/ui/components/BadgeFeedback";
|
||||
import { Button } from "~/ui/components/Button";
|
||||
import { Checkbox } from "~/ui/components/Checkbox";
|
||||
import { Dialog } from "~/ui/components/Dialog";
|
||||
import { DropdownMenu } from "~/ui/components/DropdownMenu";
|
||||
import { EmptyState } from "~/ui/components/EmptyState";
|
||||
import { IconButton } from "~/ui/components/IconButton";
|
||||
import { SearchInput } from "~/ui/components/SearchInput";
|
||||
import { Select } from "~/ui/components/Select";
|
||||
import { Table } from "~/ui/components/Table";
|
||||
import { Tabs } from "~/ui/components/Tabs";
|
||||
|
||||
// Non-empty sentinel for the "any" option (empty string is not a valid Select value).
|
||||
const FILTER_ALL = "__all__";
|
||||
const STATUS_OPTIONS: readonly MemberStatus[] = ["active", "invited", "inactive"];
|
||||
|
||||
export type MembersActions = {
|
||||
/** Posts the existing `edit` intent (role add/remove) — D01 inline dropdown. */
|
||||
onToggleRole: (input: { userId: string; roleId: string; add: boolean }) => void;
|
||||
/** Posts the `deactivate` intent after the M03 confirm. */
|
||||
onDeactivate: (input: { userId: string }) => void;
|
||||
/** Posts the `reactivate` intent. */
|
||||
onReactivate: (input: { userId: string }) => void;
|
||||
/** Posts the existing `delete-invitation` intent. */
|
||||
onDeleteInvitation: (input: { invitationId: string }) => void;
|
||||
/** Opens the invite flow (M01 dialog route). */
|
||||
onInvite: () => void;
|
||||
};
|
||||
|
||||
export type MembersPageProps = {
|
||||
vm: MembersListVM;
|
||||
actions: MembersActions;
|
||||
/** Tab bar between S01 (members) and S02 (roles & permissions), plus the D01 dropdown footer link. */
|
||||
rolesTabHref: string | null;
|
||||
/** Href of the member edit route (existing remove flow stays reachable). */
|
||||
editRouteFor: (tenantUserId: string) => string;
|
||||
/** True while a deactivate/reactivate submission is in flight. */
|
||||
submitting: boolean;
|
||||
/** Server said "last-admin" — opens the V01 blocker dialog. */
|
||||
lastAdminBlocked: boolean;
|
||||
};
|
||||
|
||||
export function MembersPage({ vm, actions, rolesTabHref, editRouteFor, submitting, lastAdminBlocked }: MembersPageProps) {
|
||||
const { t } = useTranslation();
|
||||
const [filter, setFilter] = useState<MembersListFilterState>(EMPTY_MEMBERS_FILTER);
|
||||
const [deactivateRow, setDeactivateRow] = useState<MembersListRow | null>(null);
|
||||
const [blockerDismissed, setBlockerDismissed] = useState(false);
|
||||
|
||||
// Server response (code "last-admin") re-opens the blocker; a new attempt resets the dismissal.
|
||||
useEffect(() => {
|
||||
if (lastAdminBlocked) setBlockerDismissed(false);
|
||||
}, [lastAdminBlocked]);
|
||||
|
||||
// Close the confirm dialog when the pending submission finished.
|
||||
useEffect(() => {
|
||||
if (!submitting) setDeactivateRow(null);
|
||||
}, [submitting]);
|
||||
|
||||
if (vm.status !== "ready" || !vm.data) {
|
||||
return <div className="flex w-full flex-col gap-6" data-ui-id="ui.settings.members.page" />;
|
||||
}
|
||||
|
||||
const data = vm.data;
|
||||
const rows = filterMembersRows(data.rows, filter);
|
||||
const hasAnyRows = data.rows.length > 0 || data.pendingInvitations.length > 0;
|
||||
|
||||
return (
|
||||
<div className="flex w-full flex-col gap-6" data-ui-id="ui.settings.members.page">
|
||||
{/* Header: title + description (0px rhythm) + invite CTA (M01) */}
|
||||
<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("settings.members.title")}</span>
|
||||
<span className="text-body-default-regular-150 font-body-default-regular-150 text-text-neutral-secondary">
|
||||
{t("settings.members.description")}
|
||||
</span>
|
||||
</div>
|
||||
{data.canInvite ? (
|
||||
<Button icon={<FeatherPlus />} onClick={actions.onInvite} data-ui-id="ui.settings.members.invite">
|
||||
{t("settings.members.actions.new")}
|
||||
</Button>
|
||||
) : null}
|
||||
</div>
|
||||
|
||||
{/* Tabs: Mitarbeiter | Rollen und Berechtigungen (David's S01 structure) */}
|
||||
{rolesTabHref ? (
|
||||
<Tabs>
|
||||
<Tabs.Item active>{t("settings.members.tabs.members")}</Tabs.Item>
|
||||
<Link to={rolesTabHref} className="contents no-underline" data-ui-id="ui.settings.members.tab.roles">
|
||||
<Tabs.Item>{t("settings.members.tabs.rolesAndPermissions")}</Tabs.Item>
|
||||
</Link>
|
||||
</Tabs>
|
||||
) : null}
|
||||
|
||||
{/* Toolbar: search (name/email/phone) + role/status/2FA filters */}
|
||||
<div className="flex flex-wrap items-end gap-4" data-ui-id="ui.settings.members.search">
|
||||
<SearchInput
|
||||
className="max-w-[320px]"
|
||||
placeholder={t("settings.members.filters.searchPlaceholder")}
|
||||
hideShortcut
|
||||
value={filter.query}
|
||||
onChange={(event) => setFilter((prev) => ({ ...prev, query: event.target.value }))}
|
||||
/>
|
||||
<Select
|
||||
className="max-w-[200px]"
|
||||
label={t("settings.members.filters.role")}
|
||||
showLabel
|
||||
value={filter.roleId ?? FILTER_ALL}
|
||||
onValueChange={(value: string) => setFilter((prev) => ({ ...prev, roleId: value === FILTER_ALL ? null : value }))}
|
||||
>
|
||||
<Select.Item value={FILTER_ALL}>{t("settings.members.filters.all")}</Select.Item>
|
||||
{data.assignableRoles.map((role) => (
|
||||
<Select.Item key={role.id} value={role.id}>
|
||||
{roleDisplayName(role, t)}
|
||||
</Select.Item>
|
||||
))}
|
||||
</Select>
|
||||
<Select
|
||||
className="max-w-[180px]"
|
||||
label={t("settings.members.columns.status")}
|
||||
showLabel
|
||||
value={filter.status ?? FILTER_ALL}
|
||||
onValueChange={(value: string) => setFilter((prev) => ({ ...prev, status: value === FILTER_ALL ? null : (value as MemberStatus) }))}
|
||||
>
|
||||
<Select.Item value={FILTER_ALL}>{t("settings.members.filters.all")}</Select.Item>
|
||||
{STATUS_OPTIONS.map((status) => (
|
||||
<Select.Item key={status} value={status}>
|
||||
{t(`settings.members.status.${status === "inactive" ? "deactivated" : status}`)}
|
||||
</Select.Item>
|
||||
))}
|
||||
</Select>
|
||||
<Select
|
||||
className="max-w-[160px]"
|
||||
label={t("settings.members.columns.twoFactor")}
|
||||
showLabel
|
||||
value={filter.mfa === null ? FILTER_ALL : filter.mfa ? "on" : "off"}
|
||||
onValueChange={(value: string) => setFilter((prev) => ({ ...prev, mfa: value === FILTER_ALL ? null : value === "on" }))}
|
||||
>
|
||||
<Select.Item value={FILTER_ALL}>{t("settings.members.filters.all")}</Select.Item>
|
||||
<Select.Item value="on">{t("settings.members.twoFactor.on")}</Select.Item>
|
||||
<Select.Item value="off">{t("settings.members.twoFactor.off")}</Select.Item>
|
||||
</Select>
|
||||
</div>
|
||||
|
||||
{!hasAnyRows ? (
|
||||
<div data-ui-id="ui.settings.members.empty">
|
||||
<EmptyState title={t(data.emptyHeadlineKey)} body={t(data.emptyBodyKey)} />
|
||||
</div>
|
||||
) : (
|
||||
<div className="w-full overflow-x-auto" data-ui-id="ui.settings.members.table">
|
||||
<Table
|
||||
header={
|
||||
<Table.HeaderRow>
|
||||
<Table.HeaderCell>{t("models.user.object")}</Table.HeaderCell>
|
||||
<Table.HeaderCell>{t("models.role.object")}</Table.HeaderCell>
|
||||
<Table.HeaderCell>{t("settings.members.columns.status")}</Table.HeaderCell>
|
||||
<Table.HeaderCell>{t("settings.members.columns.twoFactor")}</Table.HeaderCell>
|
||||
<Table.HeaderCell> </Table.HeaderCell>
|
||||
</Table.HeaderRow>
|
||||
}
|
||||
>
|
||||
{rows.map((row) => (
|
||||
<MemberRow
|
||||
key={row.tenantUserId}
|
||||
row={row}
|
||||
data={data}
|
||||
actions={actions}
|
||||
editRouteFor={editRouteFor}
|
||||
rolesTabHref={rolesTabHref}
|
||||
onAskDeactivate={() => setDeactivateRow(row)}
|
||||
/>
|
||||
))}
|
||||
{/* Invited users appear inline with status "Eingeladen" (David's S01). */}
|
||||
{data.pendingInvitations.map((invitation) => (
|
||||
<Table.Row key={invitation.id} data-ui-id="ui.settings.members.row">
|
||||
<Table.Cell>
|
||||
<div className="flex items-center gap-3">
|
||||
<Avatar size="small">{invitation.email.charAt(0).toUpperCase()}</Avatar>
|
||||
<div className="flex flex-col items-start">
|
||||
<span className="whitespace-nowrap text-body-default-medium-0 font-body-default-medium-0 text-text-neutral-primary">
|
||||
{invitation.name || invitation.email}
|
||||
</span>
|
||||
<span className="whitespace-nowrap text-body-small-regular-0 font-body-small-regular-0 text-text-neutral-tertiary">
|
||||
{invitation.email}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
</Table.Cell>
|
||||
<Table.Cell>
|
||||
<span className="text-body-default-regular-0 font-body-default-regular-0 text-text-neutral-subtle">—</span>
|
||||
</Table.Cell>
|
||||
<Table.Cell>
|
||||
<BadgeFeedback farbe="subtle-warning">{t("settings.members.status.invited")}</BadgeFeedback>
|
||||
</Table.Cell>
|
||||
<Table.Cell>
|
||||
<span className="text-body-default-regular-0 font-body-default-regular-0 text-text-neutral-subtle">—</span>
|
||||
</Table.Cell>
|
||||
<Table.Cell>
|
||||
<div className="flex grow shrink-0 basis-0 items-center justify-end">
|
||||
{data.canManageMembers ? (
|
||||
<IconButton
|
||||
icon={<FeatherTrash />}
|
||||
title={t("shared.delete")}
|
||||
onClick={() => actions.onDeleteInvitation({ invitationId: invitation.id })}
|
||||
data-ui-id="ui.settings.members.invitation.delete"
|
||||
/>
|
||||
) : null}
|
||||
</div>
|
||||
</Table.Cell>
|
||||
</Table.Row>
|
||||
))}
|
||||
{rows.length === 0 && data.pendingInvitations.length === 0 ? null : null}
|
||||
</Table>
|
||||
{rows.length === 0 && data.pendingInvitations.length === 0 ? (
|
||||
<div className="pt-4" data-ui-id="ui.settings.members.noMatches">
|
||||
<EmptyState title={t(data.noMatchesKey)} body={t(data.emptyBodyKey)} />
|
||||
</div>
|
||||
) : null}
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* M03 — deactivate confirm (real Dialog, XS 420, danger action) */}
|
||||
<Dialog open={deactivateRow !== null} onOpenChange={(open: boolean) => (open ? undefined : setDeactivateRow(null))}>
|
||||
<Dialog.Content className="w-[420px] max-w-[90vw] p-4">
|
||||
{deactivateRow ? (
|
||||
<div className="flex w-full flex-col gap-6" data-ui-id="ui.settings.members.deactivate.dialog">
|
||||
<div className="flex flex-col gap-2">
|
||||
<span className="text-heading-3 font-heading-3 text-text-neutral-primary">{t("settings.members.deactivate.title")}</span>
|
||||
<span className="text-body-default-regular-150 font-body-default-regular-150 text-text-neutral-secondary">
|
||||
{deactivateRow.name} · {deactivateRow.email}
|
||||
</span>
|
||||
<span className="text-body-default-regular-150 font-body-default-regular-150 text-text-neutral-secondary">
|
||||
{t("settings.members.deactivate.body")}
|
||||
</span>
|
||||
<span className="text-body-small-regular-150 font-body-small-regular-150 text-text-neutral-tertiary">
|
||||
{t("settings.members.deactivate.staysVisible")}
|
||||
</span>
|
||||
</div>
|
||||
<div className="flex w-full items-center justify-end gap-2">
|
||||
<Button variant="tertiary" onClick={() => setDeactivateRow(null)} data-ui-id="ui.settings.members.deactivate.cancel">
|
||||
{t("shared.cancel")}
|
||||
</Button>
|
||||
<Button
|
||||
variant="destructive"
|
||||
loading={submitting}
|
||||
onClick={() => actions.onDeactivate({ userId: deactivateRow.userId })}
|
||||
data-ui-id="ui.settings.members.deactivate.confirm"
|
||||
>
|
||||
{t("settings.members.deactivate.confirm")}
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
) : (
|
||||
<div />
|
||||
)}
|
||||
</Dialog.Content>
|
||||
</Dialog>
|
||||
|
||||
{/* V01 — last-admin blocker (server guard result, copy from David's wireframe) */}
|
||||
<Dialog open={lastAdminBlocked && !blockerDismissed} onOpenChange={(open: boolean) => (open ? undefined : setBlockerDismissed(true))}>
|
||||
<Dialog.Content className="w-[420px] max-w-[90vw] p-4">
|
||||
<div className="flex w-full flex-col gap-6" data-ui-id="ui.settings.members.lastAdmin.dialog">
|
||||
<div className="flex flex-col gap-2">
|
||||
<span className="text-heading-3 font-heading-3 text-text-neutral-primary">{t("settings.members.errors.lastAdminTitle")}</span>
|
||||
<span className="text-body-default-regular-150 font-body-default-regular-150 text-text-neutral-secondary">
|
||||
{t("settings.members.errors.lastAdminBody")}
|
||||
</span>
|
||||
</div>
|
||||
<div className="flex w-full items-center justify-end">
|
||||
<Button onClick={() => setBlockerDismissed(true)} data-ui-id="ui.settings.members.lastAdmin.dismiss">
|
||||
{t("settings.members.errors.lastAdminDismiss")}
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
</Dialog.Content>
|
||||
</Dialog>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function MemberRow({
|
||||
row,
|
||||
data,
|
||||
actions,
|
||||
editRouteFor,
|
||||
rolesTabHref,
|
||||
onAskDeactivate,
|
||||
}: {
|
||||
row: MembersListRow;
|
||||
data: NonNullable<MembersListVM["data"]>;
|
||||
actions: MembersActions;
|
||||
editRouteFor: (tenantUserId: string) => string;
|
||||
rolesTabHref: string | null;
|
||||
onAskDeactivate: () => void;
|
||||
}) {
|
||||
const { t } = useTranslation();
|
||||
const roleLabels = row.roles.map((role) => roleDisplayName(role, t)).join(", ");
|
||||
const assignedRoleIds = new Set(row.roles.map((role) => role.id));
|
||||
const badge =
|
||||
row.status === "active" ? ("subtle-positive" as const) : row.status === "inactive" ? ("subtle-neutral" as const) : ("subtle-warning" as const);
|
||||
|
||||
return (
|
||||
<Table.Row data-ui-id="ui.settings.members.row">
|
||||
<Table.Cell>
|
||||
<div className="flex items-center gap-3">
|
||||
<Avatar size="small">{row.initials}</Avatar>
|
||||
<div className="flex flex-col items-start">
|
||||
<span className="whitespace-nowrap text-body-default-medium-0 font-body-default-medium-0 text-text-neutral-primary">{row.name}</span>
|
||||
<span className="whitespace-nowrap text-body-small-regular-0 font-body-small-regular-0 text-text-neutral-tertiary">
|
||||
{row.email}
|
||||
{row.phone ? ` · ${row.phone}` : ""}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
</Table.Cell>
|
||||
<Table.Cell>
|
||||
{/* D01 — inline role dropdown: checkbox item per role + link to S02 */}
|
||||
{data.canEditRoles ? (
|
||||
<SubframeCore.DropdownMenu.Root>
|
||||
<SubframeCore.DropdownMenu.Trigger asChild>
|
||||
<Button variant="tertiary" size="small" iconRight={<FeatherChevronDown />} data-ui-id="ui.settings.members.roleDropdown">
|
||||
{roleLabels || t("settings.members.roles.none")}
|
||||
</Button>
|
||||
</SubframeCore.DropdownMenu.Trigger>
|
||||
<SubframeCore.DropdownMenu.Portal>
|
||||
<SubframeCore.DropdownMenu.Content side="bottom" align="start" sideOffset={4} asChild>
|
||||
<DropdownMenu>
|
||||
<div className="flex w-full flex-col items-start gap-2 px-3 py-2">
|
||||
{data.assignableRoles.map((role) => (
|
||||
<Checkbox
|
||||
key={role.id}
|
||||
label={roleDisplayName(role, t)}
|
||||
checked={assignedRoleIds.has(role.id)}
|
||||
onCheckedChange={(checked: boolean) => actions.onToggleRole({ userId: row.userId, roleId: role.id, add: checked })}
|
||||
/>
|
||||
))}
|
||||
{/* D01 footer entry: jump to S02 ("Rollen und Berechtigungen bearbeiten"). */}
|
||||
{rolesTabHref ? (
|
||||
<Link to={rolesTabHref} className="no-underline" data-ui-id="ui.settings.members.roleDropdown.editRoles">
|
||||
<span className="text-body-small-regular-0 font-body-small-regular-0 text-brand-brand-text-solid-default">
|
||||
{t("settings.members.roles.editRolesLink")}
|
||||
</span>
|
||||
</Link>
|
||||
) : null}
|
||||
</div>
|
||||
</DropdownMenu>
|
||||
</SubframeCore.DropdownMenu.Content>
|
||||
</SubframeCore.DropdownMenu.Portal>
|
||||
</SubframeCore.DropdownMenu.Root>
|
||||
) : (
|
||||
<span className="whitespace-nowrap text-body-default-regular-0 font-body-default-regular-0 text-text-neutral-secondary">
|
||||
{roleLabels || "—"}
|
||||
</span>
|
||||
)}
|
||||
</Table.Cell>
|
||||
<Table.Cell>
|
||||
<BadgeFeedback farbe={badge}>{t(row.statusLabelKey)}</BadgeFeedback>
|
||||
</Table.Cell>
|
||||
<Table.Cell>
|
||||
<BadgeFeedback farbe={row.mfaEnabled ? "subtle-positive" : "subtle-neutral"}>
|
||||
{row.mfaEnabled ? t("settings.members.twoFactor.on") : t("settings.members.twoFactor.off")}
|
||||
</BadgeFeedback>
|
||||
</Table.Cell>
|
||||
<Table.Cell>
|
||||
<div className="flex grow shrink-0 basis-0 items-center justify-end">
|
||||
{data.canManageMembers || data.canEditRoles ? (
|
||||
<SubframeCore.DropdownMenu.Root>
|
||||
<SubframeCore.DropdownMenu.Trigger asChild>
|
||||
<IconButton icon={<FeatherMoreHorizontal />} data-ui-id="ui.settings.members.rowActions" />
|
||||
</SubframeCore.DropdownMenu.Trigger>
|
||||
<SubframeCore.DropdownMenu.Portal>
|
||||
<SubframeCore.DropdownMenu.Content side="bottom" align="end" sideOffset={4} asChild>
|
||||
<DropdownMenu>
|
||||
{row.canDeactivate ? (
|
||||
<DropdownMenu.DropdownItem icon={<FeatherUserX />} onClick={onAskDeactivate} data-ui-id="ui.settings.members.menu.deactivate">
|
||||
{t("settings.members.menu.deactivate")}
|
||||
</DropdownMenu.DropdownItem>
|
||||
) : null}
|
||||
{row.canReactivate ? (
|
||||
<DropdownMenu.DropdownItem
|
||||
icon={<FeatherUserCheck />}
|
||||
onClick={() => actions.onReactivate({ userId: row.userId })}
|
||||
data-ui-id="ui.settings.members.menu.reactivate"
|
||||
>
|
||||
{t("settings.members.menu.reactivate")}
|
||||
</DropdownMenu.DropdownItem>
|
||||
) : null}
|
||||
{data.canManageMembers ? (
|
||||
<Link to={editRouteFor(row.tenantUserId)} className="no-underline">
|
||||
<DropdownMenu.DropdownItem icon={<FeatherTrash />}>{t("settings.members.menu.remove")}</DropdownMenu.DropdownItem>
|
||||
</Link>
|
||||
) : null}
|
||||
</DropdownMenu>
|
||||
</SubframeCore.DropdownMenu.Content>
|
||||
</SubframeCore.DropdownMenu.Portal>
|
||||
</SubframeCore.DropdownMenu.Root>
|
||||
) : null}
|
||||
</div>
|
||||
</Table.Cell>
|
||||
</Table.Row>
|
||||
);
|
||||
}
|
||||
+531
@@ -0,0 +1,531 @@
|
||||
// R-P2b — D-P2 "WF-P2 Admin RBAC" S02 "Rollen und Berechtigungen" in David's
|
||||
// Subframe optics. Pure presentational: renders the server-built RolesListVM
|
||||
// and reports mutations through injected actions (route owns the fetcher).
|
||||
// S02 — merged roles tab: search + type/in-use filters, Typ/Mitglieder columns
|
||||
// M04A — "Rolle anlegen" basics step → M02
|
||||
// M04B — "Rolle duplizieren" basics step (copied permissions) → M02
|
||||
// M02 — large permission editor (L 1200): section sidebar + search + switches
|
||||
// D03 — "Rolle in Nutzung blockiert" delete blocker
|
||||
// David's "Status" column has no data-model backing (no Role.status) and the
|
||||
// "Bereich/Kategorie" select has no Role.category — both omitted, tracked as
|
||||
// design-nachzug. Role duplication = create with the source's permission set
|
||||
// preloaded into the editor (same audited createWorkspaceRole path).
|
||||
|
||||
import { useEffect, useMemo, useState } from "react";
|
||||
import { Link } from "react-router";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import * as SubframeCore from "@subframe/core";
|
||||
import { FeatherCopy, FeatherEdit2, FeatherMoreHorizontal, FeatherPlus, FeatherTrash } from "@subframe/core";
|
||||
import type { RoleEditorInputPermission, RolesListRow, RolesListVM, RoleTypeKey } from "@hivegrid/view-models";
|
||||
import { buildRoleEditorVM, filterRoleEditorSections, togglePermission, EMPTY_ROLES_FILTER, filterRolesRows, type RolesListFilterState } from "@hivegrid/view-models";
|
||||
import { permissionDisplayDescription, permissionDisplayName, roleDisplayDescription, roleDisplayName } from "~/components/core/roles/roleDisplay";
|
||||
import { useLocaleFormatters } from "~/locale/format";
|
||||
import { Alert } from "~/ui/components/Alert";
|
||||
import { Button } from "~/ui/components/Button";
|
||||
import { Dialog } from "~/ui/components/Dialog";
|
||||
import { DropdownMenu } from "~/ui/components/DropdownMenu";
|
||||
import { EmptyState } from "~/ui/components/EmptyState";
|
||||
import { IconButton } from "~/ui/components/IconButton";
|
||||
import { SearchInput } from "~/ui/components/SearchInput";
|
||||
import { Select } from "~/ui/components/Select";
|
||||
import { Switch } from "~/ui/components/Switch";
|
||||
import { Table } from "~/ui/components/Table";
|
||||
import { Tabs } from "~/ui/components/Tabs";
|
||||
import { TextArea } from "~/ui/components/TextArea";
|
||||
import { TextInput } from "~/ui/components/TextInput";
|
||||
|
||||
const FILTER_ALL = "__all__";
|
||||
|
||||
export type RoleMutationInput = { name: string; description: string; permissionNames: string[] };
|
||||
|
||||
export type RolesActions = {
|
||||
/** POSTs the existing create contract (roles/new, action=create). */
|
||||
onCreate: (input: RoleMutationInput) => void;
|
||||
/** POSTs the existing update contract (roles/:id, action=edit). */
|
||||
onUpdate: (roleId: string, input: RoleMutationInput) => void;
|
||||
/** POSTs the existing delete contract (roles/:id, action=delete). */
|
||||
onDelete: (roleId: string) => void;
|
||||
};
|
||||
|
||||
export type RolesPageProps = {
|
||||
vm: RolesListVM;
|
||||
/** App permission catalog feeding the M02 editor sections. */
|
||||
editorCatalog: readonly RoleEditorInputPermission[];
|
||||
/** roleId → assigned permission names (editor prefill + M04B duplication). */
|
||||
rolePermissionNames: Readonly<Record<string, readonly string[]>>;
|
||||
/** Tab bar back to S01 (members). */
|
||||
membersTabHref: string;
|
||||
actions: RolesActions;
|
||||
submitting: boolean;
|
||||
errorMessage: string | null;
|
||||
/** Increments after a successful mutation — closes any open dialog. */
|
||||
closeSignal: number;
|
||||
};
|
||||
|
||||
/** M04A/M04B basics step. */
|
||||
type BasicsState = { source: RolesListRow | null; name: string; description: string };
|
||||
|
||||
/** M02 editor state. roleId null = create (after M04A/M04B). */
|
||||
type EditorState = {
|
||||
roleId: string | null;
|
||||
duplicatedFromName: string | null;
|
||||
name: string;
|
||||
description: string;
|
||||
enabled: ReadonlySet<string>;
|
||||
};
|
||||
|
||||
export function RolesPage({ vm, editorCatalog, rolePermissionNames, membersTabHref, actions, submitting, errorMessage, closeSignal }: RolesPageProps) {
|
||||
const { t } = useTranslation();
|
||||
const formatters = useLocaleFormatters();
|
||||
const [filter, setFilter] = useState<RolesListFilterState>(EMPTY_ROLES_FILTER);
|
||||
const [basics, setBasics] = useState<BasicsState | null>(null);
|
||||
const [editor, setEditor] = useState<EditorState | null>(null);
|
||||
const [deleteRow, setDeleteRow] = useState<RolesListRow | null>(null);
|
||||
|
||||
useEffect(() => {
|
||||
if (closeSignal > 0) {
|
||||
setBasics(null);
|
||||
setEditor(null);
|
||||
setDeleteRow(null);
|
||||
}
|
||||
}, [closeSignal]);
|
||||
|
||||
if (vm.status !== "ready" || !vm.data) {
|
||||
return <div className="flex w-full flex-col gap-6" data-ui-id="ui.settings.rolesAndPermissions.roles" />;
|
||||
}
|
||||
|
||||
const data = vm.data;
|
||||
const rows = filterRolesRows(data.rows, filter);
|
||||
|
||||
function openEditorFor(row: RolesListRow) {
|
||||
setEditor({
|
||||
roleId: row.id,
|
||||
duplicatedFromName: null,
|
||||
name: row.name,
|
||||
description: row.description,
|
||||
enabled: new Set(rolePermissionNames[row.id] ?? []),
|
||||
});
|
||||
}
|
||||
|
||||
function continueToPermissions(state: BasicsState) {
|
||||
setBasics(null);
|
||||
setEditor({
|
||||
roleId: null,
|
||||
duplicatedFromName: state.source ? state.source.name : null,
|
||||
name: state.name,
|
||||
description: state.description,
|
||||
enabled: new Set(state.source ? (rolePermissionNames[state.source.id] ?? []) : []),
|
||||
});
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="flex w-full flex-col gap-6" data-ui-id="ui.settings.rolesAndPermissions.roles">
|
||||
{/* Header: title + subtitle (0px rhythm) + create CTA (M04A) */}
|
||||
<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("settings.members.tabs.rolesAndPermissions")}</span>
|
||||
<span className="text-body-default-regular-150 font-body-default-regular-150 text-text-neutral-secondary">
|
||||
{t("settings.rolesAndPermissions.subtitle")}
|
||||
</span>
|
||||
</div>
|
||||
{data.canCreate ? (
|
||||
<Button
|
||||
icon={<FeatherPlus />}
|
||||
onClick={() => setBasics({ source: null, name: "", description: "" })}
|
||||
data-ui-id="ui.settings.rolesAndPermissions.roles.new"
|
||||
>
|
||||
{t("settings.rolesAndPermissions.create")}
|
||||
</Button>
|
||||
) : null}
|
||||
</div>
|
||||
|
||||
{/* Tabs: Mitarbeiter | Rollen und Berechtigungen (shared with S01) */}
|
||||
<Tabs>
|
||||
<Link to={membersTabHref} className="contents no-underline" data-ui-id="ui.settings.rolesAndPermissions.tab.members">
|
||||
<Tabs.Item>{t("settings.members.tabs.members")}</Tabs.Item>
|
||||
</Link>
|
||||
<Tabs.Item active>{t("settings.members.tabs.rolesAndPermissions")}</Tabs.Item>
|
||||
</Tabs>
|
||||
|
||||
{/* Toolbar: search (name/description) + type/in-use filters */}
|
||||
<div className="flex flex-wrap items-end gap-4" data-ui-id="ui.settings.rolesAndPermissions.roles.filter">
|
||||
<SearchInput
|
||||
className="max-w-[320px]"
|
||||
placeholder={t("settings.rolesAndPermissions.filters.searchPlaceholder")}
|
||||
hideShortcut
|
||||
value={filter.query}
|
||||
onChange={(event) => setFilter((prev) => ({ ...prev, query: event.target.value }))}
|
||||
/>
|
||||
<Select
|
||||
className="max-w-[200px]"
|
||||
label={t("settings.rolesAndPermissions.columns.type")}
|
||||
showLabel
|
||||
value={filter.type ?? FILTER_ALL}
|
||||
onValueChange={(value: string) => setFilter((prev) => ({ ...prev, type: value === FILTER_ALL ? null : (value as RoleTypeKey) }))}
|
||||
>
|
||||
<Select.Item value={FILTER_ALL}>{t("settings.members.filters.all")}</Select.Item>
|
||||
<Select.Item value="system">{t("settings.rolesAndPermissions.type.system")}</Select.Item>
|
||||
<Select.Item value="custom">{t("settings.rolesAndPermissions.type.custom")}</Select.Item>
|
||||
</Select>
|
||||
<Select
|
||||
className="max-w-[200px]"
|
||||
label={t("settings.rolesAndPermissions.filters.inUse")}
|
||||
showLabel
|
||||
value={filter.inUse === null ? FILTER_ALL : filter.inUse ? "yes" : "no"}
|
||||
onValueChange={(value: string) => setFilter((prev) => ({ ...prev, inUse: value === FILTER_ALL ? null : value === "yes" }))}
|
||||
>
|
||||
<Select.Item value={FILTER_ALL}>{t("settings.members.filters.all")}</Select.Item>
|
||||
<Select.Item value="yes">{t("settings.rolesAndPermissions.filters.inUseYes")}</Select.Item>
|
||||
<Select.Item value="no">{t("settings.rolesAndPermissions.filters.inUseNo")}</Select.Item>
|
||||
</Select>
|
||||
</div>
|
||||
|
||||
{data.rows.length === 0 ? (
|
||||
<div data-ui-id="ui.settings.rolesAndPermissions.roles.empty">
|
||||
<EmptyState title={t(data.emptyHeadlineKey)} body={t(data.emptyBodyKey)} />
|
||||
</div>
|
||||
) : (
|
||||
<div className="w-full overflow-x-auto">
|
||||
<Table
|
||||
header={
|
||||
<Table.HeaderRow>
|
||||
<Table.HeaderCell>{t("models.role.object")}</Table.HeaderCell>
|
||||
<Table.HeaderCell>{t("models.role.description")}</Table.HeaderCell>
|
||||
<Table.HeaderCell>{t("settings.rolesAndPermissions.columns.type")}</Table.HeaderCell>
|
||||
<Table.HeaderCell>{t("settings.rolesAndPermissions.columns.members")}</Table.HeaderCell>
|
||||
<Table.HeaderCell>{t("models.permission.plural")}</Table.HeaderCell>
|
||||
<Table.HeaderCell> </Table.HeaderCell>
|
||||
</Table.HeaderRow>
|
||||
}
|
||||
>
|
||||
{rows.map((row) => (
|
||||
<Table.Row key={row.id} data-ui-id="ui.settings.rolesAndPermissions.roles.row">
|
||||
<Table.Cell>
|
||||
<span className="whitespace-nowrap text-body-default-medium-0 font-body-default-medium-0 text-text-neutral-primary">
|
||||
{roleDisplayName({ name: row.name, description: row.description }, t)}
|
||||
</span>
|
||||
</Table.Cell>
|
||||
<Table.Cell>
|
||||
<span className="text-body-default-regular-150 font-body-default-regular-150 text-text-neutral-tertiary">
|
||||
{roleDisplayDescription({ name: row.name, description: row.description }, t) || "—"}
|
||||
</span>
|
||||
</Table.Cell>
|
||||
<Table.Cell>
|
||||
<span className="whitespace-nowrap text-body-default-regular-0 font-body-default-regular-0 text-text-neutral-secondary">
|
||||
{t(row.typeLabelKey)}
|
||||
</span>
|
||||
</Table.Cell>
|
||||
<Table.Cell>
|
||||
<span className="whitespace-nowrap text-body-default-regular-0 font-body-default-regular-0 text-text-neutral-secondary">
|
||||
{formatters.number(row.memberCount)}
|
||||
</span>
|
||||
</Table.Cell>
|
||||
<Table.Cell>
|
||||
<span className="whitespace-nowrap text-body-default-regular-0 font-body-default-regular-0 text-text-neutral-secondary">
|
||||
{t("models.permission.count", { count: row.permissionCount, formattedCount: formatters.number(row.permissionCount) })}
|
||||
</span>
|
||||
</Table.Cell>
|
||||
<Table.Cell>
|
||||
<div className="flex grow shrink-0 basis-0 items-center justify-end">
|
||||
{row.canEdit || row.canDuplicate || row.canDelete ? (
|
||||
<SubframeCore.DropdownMenu.Root>
|
||||
<SubframeCore.DropdownMenu.Trigger asChild>
|
||||
<IconButton icon={<FeatherMoreHorizontal />} data-ui-id="ui.settings.rolesAndPermissions.roles.rowActions" />
|
||||
</SubframeCore.DropdownMenu.Trigger>
|
||||
<SubframeCore.DropdownMenu.Portal>
|
||||
<SubframeCore.DropdownMenu.Content side="bottom" align="end" sideOffset={4} asChild>
|
||||
<DropdownMenu>
|
||||
{row.canEdit ? (
|
||||
<DropdownMenu.DropdownItem icon={<FeatherEdit2 />} onClick={() => openEditorFor(row)}>
|
||||
{t("shared.edit")}
|
||||
</DropdownMenu.DropdownItem>
|
||||
) : null}
|
||||
{row.canDuplicate ? (
|
||||
<DropdownMenu.DropdownItem
|
||||
icon={<FeatherCopy />}
|
||||
onClick={() =>
|
||||
setBasics({
|
||||
source: row,
|
||||
name: t("settings.rolesAndPermissions.duplicate.copyName", { name: row.name }),
|
||||
description: row.description,
|
||||
})
|
||||
}
|
||||
>
|
||||
{t("settings.rolesAndPermissions.duplicate.action")}
|
||||
</DropdownMenu.DropdownItem>
|
||||
) : null}
|
||||
{row.canDelete ? (
|
||||
<DropdownMenu.DropdownItem icon={<FeatherTrash />} onClick={() => setDeleteRow(row)}>
|
||||
{t("shared.delete")}
|
||||
</DropdownMenu.DropdownItem>
|
||||
) : null}
|
||||
</DropdownMenu>
|
||||
</SubframeCore.DropdownMenu.Content>
|
||||
</SubframeCore.DropdownMenu.Portal>
|
||||
</SubframeCore.DropdownMenu.Root>
|
||||
) : null}
|
||||
</div>
|
||||
</Table.Cell>
|
||||
</Table.Row>
|
||||
))}
|
||||
</Table>
|
||||
{rows.length === 0 ? (
|
||||
<div className="pt-4">
|
||||
<EmptyState variant="no-results" title={t(data.noMatchesKey)} body={t(data.emptyBodyKey)} />
|
||||
</div>
|
||||
) : null}
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* M04A / M04B — basics step (S 560) */}
|
||||
<Dialog open={basics !== null} onOpenChange={(open: boolean) => (open ? undefined : setBasics(null))}>
|
||||
<Dialog.Content className="w-[560px] max-w-[90vw] p-6">
|
||||
{basics ? <RoleBasicsDialog state={basics} onChange={setBasics} onContinue={continueToPermissions} onCancel={() => setBasics(null)} /> : <div />}
|
||||
</Dialog.Content>
|
||||
</Dialog>
|
||||
|
||||
{/* M02 — large permission editor (L 1200) */}
|
||||
<Dialog open={editor !== null} onOpenChange={(open: boolean) => (open ? undefined : setEditor(null))}>
|
||||
<Dialog.Content className="w-[1200px] max-w-[95vw] p-6">
|
||||
{editor ? (
|
||||
<RoleEditorDialog
|
||||
state={editor}
|
||||
onChange={setEditor}
|
||||
editorCatalog={editorCatalog}
|
||||
submitting={submitting}
|
||||
errorMessage={errorMessage}
|
||||
onCancel={() => setEditor(null)}
|
||||
onSave={() => {
|
||||
const input = { name: editor.name, description: editor.description, permissionNames: [...editor.enabled] };
|
||||
if (editor.roleId) actions.onUpdate(editor.roleId, input);
|
||||
else actions.onCreate(input);
|
||||
}}
|
||||
/>
|
||||
) : (
|
||||
<div />
|
||||
)}
|
||||
</Dialog.Content>
|
||||
</Dialog>
|
||||
|
||||
{/* Delete confirm / D03 blocker (XS 420) */}
|
||||
<Dialog open={deleteRow !== null} onOpenChange={(open: boolean) => (open ? undefined : setDeleteRow(null))}>
|
||||
<Dialog.Content className="w-[420px] max-w-[90vw] p-4">
|
||||
{deleteRow ? (
|
||||
<div className="flex w-full flex-col gap-6" data-ui-id="ui.settings.rolesAndPermissions.roles.deleteConfirm">
|
||||
<div className="flex flex-col gap-2">
|
||||
<span className="text-heading-3 font-heading-3 text-text-neutral-primary">
|
||||
{deleteRow.deleteBlockedInUse ? t("settings.rolesAndPermissions.deleteBlocked.title") : t("settings.rolesAndPermissions.delete.title")}
|
||||
</span>
|
||||
<span className="text-body-default-regular-150 font-body-default-regular-150 text-text-neutral-secondary">
|
||||
{deleteRow.deleteBlockedInUse
|
||||
? t("settings.rolesAndPermissions.deleteBlocked.description", { name: deleteRow.name, count: deleteRow.memberCount })
|
||||
: t("settings.rolesAndPermissions.delete.description", { name: deleteRow.name })}
|
||||
</span>
|
||||
</div>
|
||||
<div className="flex w-full items-center justify-end gap-2">
|
||||
<Button variant="tertiary" onClick={() => setDeleteRow(null)}>
|
||||
{deleteRow.deleteBlockedInUse ? t("shared.close") : t("shared.cancel")}
|
||||
</Button>
|
||||
{!deleteRow.deleteBlockedInUse ? (
|
||||
<Button
|
||||
variant="destructive"
|
||||
loading={submitting}
|
||||
onClick={() => actions.onDelete(deleteRow.id)}
|
||||
data-ui-id="ui.settings.rolesAndPermissions.roles.deleteSubmit"
|
||||
>
|
||||
{t("shared.delete")}
|
||||
</Button>
|
||||
) : null}
|
||||
</div>
|
||||
</div>
|
||||
) : (
|
||||
<div />
|
||||
)}
|
||||
</Dialog.Content>
|
||||
</Dialog>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function RoleBasicsDialog({
|
||||
state,
|
||||
onChange,
|
||||
onContinue,
|
||||
onCancel,
|
||||
}: {
|
||||
state: BasicsState;
|
||||
onChange: (state: BasicsState) => void;
|
||||
onContinue: (state: BasicsState) => void;
|
||||
onCancel: () => void;
|
||||
}) {
|
||||
const { t } = useTranslation();
|
||||
const isDuplicate = state.source !== null;
|
||||
const nameMissing = state.name.trim().length === 0;
|
||||
|
||||
return (
|
||||
<div className="flex w-full flex-col gap-6" data-ui-id="ui.settings.rolesAndPermissions.roles.basics">
|
||||
<div className="flex flex-col gap-2">
|
||||
<span className="text-heading-3 font-heading-3 text-text-neutral-primary">
|
||||
{isDuplicate ? t("settings.rolesAndPermissions.duplicate.title") : t("settings.rolesAndPermissions.createDialog.title")}
|
||||
</span>
|
||||
<span className="text-body-default-regular-150 font-body-default-regular-150 text-text-neutral-secondary">
|
||||
{isDuplicate
|
||||
? t("settings.rolesAndPermissions.duplicate.hint", { name: state.source?.name ?? "" })
|
||||
: t("settings.rolesAndPermissions.createDialog.description")}
|
||||
</span>
|
||||
</div>
|
||||
<div className="flex w-full flex-col gap-4">
|
||||
<TextInput className="w-full" label={t("models.role.name")} showLabel>
|
||||
<TextInput.Input value={state.name} onChange={(event) => onChange({ ...state, name: event.target.value })} required />
|
||||
</TextInput>
|
||||
<TextArea className="w-full" label={t("models.role.description")} showLabel>
|
||||
<TextArea.Input value={state.description} onChange={(event) => onChange({ ...state, description: event.target.value })} />
|
||||
</TextArea>
|
||||
</div>
|
||||
<div className="flex w-full items-center justify-end gap-2">
|
||||
<Button variant="tertiary" onClick={onCancel}>
|
||||
{t("shared.cancel")}
|
||||
</Button>
|
||||
<Button disabled={nameMissing} onClick={() => onContinue(state)} data-ui-id="ui.settings.rolesAndPermissions.roles.basics.continue">
|
||||
{t("settings.rolesAndPermissions.editor.continue")}
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function RoleEditorDialog({
|
||||
state,
|
||||
onChange,
|
||||
editorCatalog,
|
||||
submitting,
|
||||
errorMessage,
|
||||
onCancel,
|
||||
onSave,
|
||||
}: {
|
||||
state: EditorState;
|
||||
onChange: (state: EditorState) => void;
|
||||
editorCatalog: readonly RoleEditorInputPermission[];
|
||||
submitting: boolean;
|
||||
errorMessage: string | null;
|
||||
onCancel: () => void;
|
||||
onSave: () => void;
|
||||
}) {
|
||||
const { t } = useTranslation();
|
||||
const [query, setQuery] = useState("");
|
||||
const [selectedSection, setSelectedSection] = useState<string | null>(null);
|
||||
|
||||
// Pure VM grouping (scope → David's sections); enabled state comes from the dialog.
|
||||
const sections = useMemo(() => {
|
||||
const vm = buildRoleEditorVM({
|
||||
role: state.roleId ? { id: state.roleId, name: state.name, description: state.description } : null,
|
||||
duplicatedFromName: state.duplicatedFromName,
|
||||
appPermissions: editorCatalog,
|
||||
assignedPermissionNames: [...state.enabled],
|
||||
});
|
||||
return vm.data?.sections ?? [];
|
||||
}, [state.roleId, state.name, state.description, state.duplicatedFromName, state.enabled, editorCatalog]);
|
||||
|
||||
const searched = useMemo(() => filterRoleEditorSections(sections, query), [sections, query]);
|
||||
const visible = query.trim() ? searched : selectedSection ? searched.filter((section) => section.id === selectedSection) : searched;
|
||||
const nameMissing = state.name.trim().length === 0;
|
||||
|
||||
return (
|
||||
<div className="flex w-full flex-col gap-6" data-ui-id="ui.settings.rolesAndPermissions.roles.editor">
|
||||
<div className="flex flex-col gap-2">
|
||||
<span className="text-heading-3 font-heading-3 text-text-neutral-primary">
|
||||
{state.roleId ? t("settings.rolesAndPermissions.editor.title") : t("settings.rolesAndPermissions.createDialog.title")}
|
||||
</span>
|
||||
{state.duplicatedFromName ? (
|
||||
<span className="text-body-default-regular-150 font-body-default-regular-150 text-text-neutral-secondary">
|
||||
{t("settings.rolesAndPermissions.duplicate.hint", { name: state.duplicatedFromName })}
|
||||
</span>
|
||||
) : null}
|
||||
{errorMessage ? <Alert variant="error" title={errorMessage} /> : null}
|
||||
</div>
|
||||
|
||||
<div className="flex w-full gap-6 mobile:flex-col">
|
||||
{/* Sidebar: search + sections (Apple-settings pattern from David's M02) */}
|
||||
<div className="flex w-64 flex-none flex-col gap-4 mobile:w-full">
|
||||
<SearchInput
|
||||
placeholder={t("settings.rolesAndPermissions.editor.searchPlaceholder")}
|
||||
hideShortcut
|
||||
value={query}
|
||||
onChange={(event) => setQuery(event.target.value)}
|
||||
/>
|
||||
<div className="flex flex-col gap-1">
|
||||
<Button
|
||||
variant={selectedSection === null ? "secondary" : "ghost"}
|
||||
className="justify-start"
|
||||
onClick={() => setSelectedSection(null)}
|
||||
>
|
||||
{t("settings.rolesAndPermissions.editor.allSections")}
|
||||
</Button>
|
||||
{sections.map((section) => (
|
||||
<Button
|
||||
key={section.id}
|
||||
variant={selectedSection === section.id ? "secondary" : "ghost"}
|
||||
className="justify-start"
|
||||
onClick={() => setSelectedSection(section.id)}
|
||||
>
|
||||
{`${t(section.labelKey)} (${section.enabledCount}/${section.permissions.length})`}
|
||||
</Button>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Main: role base data + permission rows as switches */}
|
||||
<div className="flex max-h-[60vh] w-full flex-col gap-6 overflow-y-auto pr-2">
|
||||
<div className="flex w-full flex-col gap-4">
|
||||
<span className="text-body-default-medium-0 font-body-default-medium-0 text-text-neutral-primary">
|
||||
{t("settings.rolesAndPermissions.editor.roleSection")}
|
||||
</span>
|
||||
<TextInput className="w-full" label={t("models.role.name")} showLabel>
|
||||
<TextInput.Input value={state.name} onChange={(event) => onChange({ ...state, name: event.target.value })} required />
|
||||
</TextInput>
|
||||
<TextArea className="w-full" label={t("models.role.description")} showLabel>
|
||||
<TextArea.Input value={state.description} onChange={(event) => onChange({ ...state, description: event.target.value })} />
|
||||
</TextArea>
|
||||
</div>
|
||||
|
||||
{visible.length === 0 ? (
|
||||
<EmptyState variant="no-results" title={t("settings.rolesAndPermissions.editor.noMatches")} />
|
||||
) : (
|
||||
visible.map((section) => (
|
||||
<div key={section.id} className="flex w-full flex-col gap-4" data-editor-section={section.id}>
|
||||
<span className="text-body-default-medium-0 font-body-default-medium-0 text-text-neutral-primary">{t(section.labelKey)}</span>
|
||||
<div className="flex w-full flex-col gap-4">
|
||||
{section.permissions.map((permission) => (
|
||||
<div key={permission.name} className="flex w-full items-start justify-between gap-4" data-editor-permission={permission.name}>
|
||||
<div className="flex flex-col gap-0">
|
||||
<span className="text-body-default-regular-0 font-body-default-regular-0 text-text-neutral-primary">
|
||||
{permissionDisplayName({ name: permission.name, description: permission.description }, t)}
|
||||
</span>
|
||||
<span className="text-body-small-regular-150 font-body-small-regular-150 text-text-neutral-tertiary">
|
||||
{permissionDisplayDescription({ name: permission.name, description: permission.description }, t) ?? permission.name}
|
||||
</span>
|
||||
</div>
|
||||
<Switch
|
||||
checked={state.enabled.has(permission.name)}
|
||||
onCheckedChange={(checked: boolean) => onChange({ ...state, enabled: togglePermission(state.enabled, permission.name, checked) })}
|
||||
/>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
))
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="flex w-full items-center justify-end gap-2">
|
||||
<Button variant="tertiary" onClick={onCancel}>
|
||||
{t("shared.cancel")}
|
||||
</Button>
|
||||
<Button loading={submitting} disabled={nameMissing} onClick={onSave} data-ui-id="ui.settings.rolesAndPermissions.roles.editor.save">
|
||||
{t("shared.save")}
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user