176 lines
8.3 KiB
TypeScript
176 lines
8.3 KiB
TypeScript
// 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[];
|
|
audienceOptions: readonly { kind: "team" | "location"; ref: string; label: string }[];
|
|
submitting: boolean;
|
|
actions: HrAdminAnnouncementsActions;
|
|
};
|
|
|
|
const EMPTY = { title: "", body: "", audienceRef: "", requiresAck: false, pinned: false };
|
|
|
|
export function HrAdminAnnouncementsPage({ rows, audiences, audienceOptions, 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, audienceRef: "" }))}
|
|
>
|
|
{audiences.map((a) => (
|
|
<Select.Item key={a} value={a}>
|
|
{t(`hr.audience.${a}`)}
|
|
</Select.Item>
|
|
))}
|
|
</Select>
|
|
{form.audienceKind !== "all" ? (
|
|
<Select
|
|
label={t("hr.announcements.field.audienceRef")}
|
|
showLabel
|
|
value={form.audienceRef}
|
|
onValueChange={(value: string) => setForm((s) => ({ ...s, audienceRef: value }))}
|
|
>
|
|
{audienceOptions
|
|
.filter((option) => option.kind === form.audienceKind)
|
|
.map((option) => (
|
|
<Select.Item key={`${option.kind}:${option.ref}`} value={option.ref}>
|
|
{option.label}
|
|
</Select.Item>
|
|
))}
|
|
</Select>
|
|
) : null}
|
|
</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>
|
|
);
|
|
}
|