147 lines
6.2 KiB
TypeScript
147 lines
6.2 KiB
TypeScript
// 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>
|
|
);
|
|
}
|