Refresh HiveGrid Cloud reference snapshot
This commit is contained in:
1 parent
5e99e14772
commit
7f88026f79
5955 files changed
+1177325
-188362
No files matched your search
+339
@@ -0,0 +1,339 @@
|
||||
import { useRef, useState } from "react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { FeatherArrowLeft, FeatherFile, FeatherPaperclip, FeatherSend, FeatherSettings, FeatherX } from "@subframe/core";
|
||||
import { parseRecipients, type EmailComposeVM } from "@hivegrid/view-models";
|
||||
import { Alert } from "~/ui/components/Alert";
|
||||
import { Button } from "~/ui/components/Button";
|
||||
import { Card } from "~/ui/components/Card";
|
||||
import { EmptyState } from "~/ui/components/EmptyState";
|
||||
import { IconButton } from "~/ui/components/IconButton";
|
||||
import { Loader } from "~/ui/components/Loader";
|
||||
import { Select } from "~/ui/components/Select";
|
||||
import { TextArea } from "~/ui/components/TextArea";
|
||||
import { TextInput } from "~/ui/components/TextInput";
|
||||
|
||||
/** AK-UI-03 interim (AD-28): compose form composed from ~/ui until David's final delta lands. */
|
||||
|
||||
/** Mirrors the server cap (emails.new.tsx) so the user sees the problem before sending. */
|
||||
export const COMPOSE_ATTACHMENT_MAX_BYTES = 10 * 1024 * 1024;
|
||||
|
||||
/** Sentinel for the "no template" option — Radix Select items must not use "". */
|
||||
const NO_TEMPLATE = "none";
|
||||
|
||||
export type EmailComposePayload = {
|
||||
readonly mailboxId: string;
|
||||
readonly to: string;
|
||||
readonly cc: string;
|
||||
readonly bcc: string;
|
||||
readonly subject: string;
|
||||
readonly body: string;
|
||||
readonly replyToMessageId: string | null;
|
||||
readonly quotedHtml: string;
|
||||
readonly attachments: readonly File[];
|
||||
};
|
||||
|
||||
export type EmailComposeActions = {
|
||||
readonly onSend: (payload: EmailComposePayload) => void | Promise<void>;
|
||||
readonly onBack: () => void;
|
||||
readonly onOpenSettings: () => void;
|
||||
};
|
||||
|
||||
function attachmentSizeLabel(sizeBytes: number): string {
|
||||
return `${Math.max(1, Math.round(sizeBytes / 1024))} KB`;
|
||||
}
|
||||
|
||||
/** Templates carry html; the compose body is plain text (the action escapes it). */
|
||||
function templateBodyAsText(htmlBody: string): string {
|
||||
return htmlBody
|
||||
.replace(/<[^>]+>/gu, " ")
|
||||
.replace(/\s+/gu, " ")
|
||||
.trim();
|
||||
}
|
||||
|
||||
export function EmailComposePage({
|
||||
vm,
|
||||
actions,
|
||||
actionErrorKey,
|
||||
submitting,
|
||||
}: {
|
||||
vm: EmailComposeVM;
|
||||
actions: EmailComposeActions;
|
||||
actionErrorKey?: string;
|
||||
submitting?: boolean;
|
||||
}): React.JSX.Element {
|
||||
const { t } = useTranslation();
|
||||
const readyData = vm.status === "ready" ? vm.data : undefined;
|
||||
const fileInputRef = useRef<HTMLInputElement>(null);
|
||||
const [mailboxId, setMailboxId] = useState<string>(readyData?.defaultMailboxId ?? "");
|
||||
const [to, setTo] = useState<string>(readyData?.prefill.to ?? "");
|
||||
const [cc, setCc] = useState("");
|
||||
const [bcc, setBcc] = useState("");
|
||||
const [subject, setSubject] = useState<string>(readyData?.prefill.subject ?? "");
|
||||
const [body, setBody] = useState("");
|
||||
const [attachments, setAttachments] = useState<readonly File[]>([]);
|
||||
const [touchedRecipients, setTouchedRecipients] = useState(false);
|
||||
|
||||
if (vm.status === "idle" || vm.status === "loading") {
|
||||
return (
|
||||
<div className="flex w-full flex-col items-start gap-6 px-6 py-6" data-ui-id="ui.email.compose">
|
||||
<Card data-ui-id="ui.email.compose.loading">
|
||||
<div className="flex w-full items-center gap-3">
|
||||
<Loader />
|
||||
<div className="flex flex-col items-start">
|
||||
<span className="text-body-default-medium-0 font-body-default-medium-0 text-text-neutral-primary">
|
||||
{t("emailInbox.compose.loading.headline")}
|
||||
</span>
|
||||
<span className="text-body-small-regular-150 font-body-small-regular-150 text-text-neutral-tertiary">
|
||||
{t("emailInbox.compose.loading.body")}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
</Card>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
if (vm.status === "error" || !readyData) {
|
||||
return (
|
||||
<div className="flex w-full flex-col items-start gap-6 px-6 py-6" data-ui-id="ui.email.compose">
|
||||
<EmptyState
|
||||
outlined
|
||||
variant="error"
|
||||
title={t("emailInbox.compose.error.headline")}
|
||||
body={vm.status === "error" ? t(vm.error.messageKey) : t("emailInbox.compose.error.body")}
|
||||
data-ui-id="ui.email.compose.error"
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
const { mailboxes, templates, prefill, noMailboxKey } = readyData;
|
||||
const oversizedAttachment = attachments.some((file) => file.size > COMPOSE_ATTACHMENT_MAX_BYTES);
|
||||
const recipientCount = parseRecipients(to).length;
|
||||
const recipientsInvalid = recipientCount === 0;
|
||||
const canSend = !recipientsInvalid && !oversizedAttachment && mailboxId !== "" && submitting !== true;
|
||||
|
||||
function addFiles(selected: FileList | null): void {
|
||||
if (!selected) return;
|
||||
const picked = Array.from(selected);
|
||||
setAttachments((current) => [...current, ...picked]);
|
||||
if (fileInputRef.current) fileInputRef.current.value = "";
|
||||
}
|
||||
|
||||
function removeFile(index: number): void {
|
||||
setAttachments((current) => current.filter((_, position) => position !== index));
|
||||
}
|
||||
|
||||
function send(): void {
|
||||
setTouchedRecipients(true);
|
||||
if (!canSend) return;
|
||||
void actions.onSend({
|
||||
mailboxId,
|
||||
to,
|
||||
cc,
|
||||
bcc,
|
||||
subject,
|
||||
body,
|
||||
replyToMessageId: prefill.replyToMessageId,
|
||||
quotedHtml: prefill.quotedHtml,
|
||||
attachments,
|
||||
});
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="bg-surface-neutral-primary flex w-full flex-col items-start" data-ui-id="ui.email.compose">
|
||||
<div className="border-border-default bg-surface-neutral-secondary mobile:flex-col mobile:px-4 flex w-full items-start justify-between gap-4 border-b border-solid px-6 py-6">
|
||||
<div className="flex flex-col items-start gap-1">
|
||||
<Button variant="tertiary" size="small" icon={<FeatherArrowLeft />} onClick={actions.onBack} data-ui-id="ui.email.compose.back">
|
||||
{t("emailInbox.compose.back")}
|
||||
</Button>
|
||||
<h1 className="text-heading- font-heading- text-text-neutral-primary">{t("emailInbox.compose.title")}</h1>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="mobile:px-4 flex w-full flex-col items-start gap-4 px-6 py-6">
|
||||
{mailboxes.length === 0 ? (
|
||||
<EmptyState
|
||||
outlined
|
||||
title={t(noMailboxKey)}
|
||||
body={t("emailInbox.list.noMailbox.body")}
|
||||
action={
|
||||
<Button variant="tertiary" icon={<FeatherSettings />} onClick={actions.onOpenSettings} data-ui-id="ui.email.compose.connect">
|
||||
{t("emailInbox.list.connectCta")}
|
||||
</Button>
|
||||
}
|
||||
data-ui-id="ui.email.compose.noMailbox"
|
||||
/>
|
||||
) : (
|
||||
<>
|
||||
{actionErrorKey ? (
|
||||
<Alert variant="error" notDismissible title={t(actionErrorKey)} className="w-full" data-ui-id="ui.email.compose.error" />
|
||||
) : null}
|
||||
|
||||
<Card className="w-full">
|
||||
<div className="flex w-full max-w-[768px] flex-col items-start gap-4">
|
||||
<Select
|
||||
className="w-full"
|
||||
label={t("emailInbox.compose.mailbox")}
|
||||
value={mailboxId}
|
||||
onValueChange={setMailboxId}
|
||||
data-ui-id="ui.email.compose.mailbox"
|
||||
>
|
||||
{mailboxes.map((mailbox) => (
|
||||
<Select.Item key={mailbox.id} value={mailbox.id}>
|
||||
{mailbox.emailAddress}
|
||||
</Select.Item>
|
||||
))}
|
||||
</Select>
|
||||
|
||||
<TextInput
|
||||
className="w-full"
|
||||
label={t("emailInbox.compose.to")}
|
||||
error={touchedRecipients && recipientsInvalid}
|
||||
message={touchedRecipients && recipientsInvalid ? t("emailInbox.compose.error.no_recipients") : undefined}
|
||||
>
|
||||
<TextInput.Input
|
||||
value={to}
|
||||
placeholder={t("emailInbox.compose.recipientsPlaceholder")}
|
||||
onChange={(event) => setTo(event.target.value)}
|
||||
onBlur={() => setTouchedRecipients(true)}
|
||||
data-ui-id="ui.email.compose.to"
|
||||
/>
|
||||
</TextInput>
|
||||
|
||||
<TextInput className="w-full" label={t("emailInbox.compose.cc")}>
|
||||
<TextInput.Input
|
||||
value={cc}
|
||||
placeholder={t("emailInbox.compose.recipientsPlaceholder")}
|
||||
onChange={(event) => setCc(event.target.value)}
|
||||
data-ui-id="ui.email.compose.cc"
|
||||
/>
|
||||
</TextInput>
|
||||
|
||||
<TextInput className="w-full" label={t("emailInbox.compose.bcc")}>
|
||||
<TextInput.Input
|
||||
value={bcc}
|
||||
placeholder={t("emailInbox.compose.recipientsPlaceholder")}
|
||||
onChange={(event) => setBcc(event.target.value)}
|
||||
data-ui-id="ui.email.compose.bcc"
|
||||
/>
|
||||
</TextInput>
|
||||
|
||||
{templates.length > 0 ? (
|
||||
<Select
|
||||
className="w-full"
|
||||
label={t("emailInbox.compose.template")}
|
||||
placeholder={t("emailInbox.compose.noTemplate")}
|
||||
value={NO_TEMPLATE}
|
||||
onValueChange={(value) => {
|
||||
const template = templates.find((candidate) => candidate.id === value);
|
||||
if (!template) return;
|
||||
setSubject(template.subject);
|
||||
setBody(templateBodyAsText(template.htmlBody));
|
||||
}}
|
||||
data-ui-id="ui.email.compose.template"
|
||||
>
|
||||
<Select.Item value={NO_TEMPLATE}>{t("emailInbox.compose.noTemplate")}</Select.Item>
|
||||
{templates.map((template) => (
|
||||
<Select.Item key={template.id} value={template.id}>
|
||||
{template.name}
|
||||
</Select.Item>
|
||||
))}
|
||||
</Select>
|
||||
) : null}
|
||||
|
||||
<TextInput className="w-full" label={t("emailInbox.compose.subject")}>
|
||||
<TextInput.Input value={subject} onChange={(event) => setSubject(event.target.value)} data-ui-id="ui.email.compose.subject" />
|
||||
</TextInput>
|
||||
|
||||
<TextArea className="w-full" label={t("emailInbox.compose.body")}>
|
||||
<TextArea.Input
|
||||
className="h-auto min-h-[192px] w-full"
|
||||
value={body}
|
||||
onChange={(event) => setBody(event.target.value)}
|
||||
data-ui-id="ui.email.compose.body"
|
||||
/>
|
||||
</TextArea>
|
||||
|
||||
{prefill.quotedHtml ? (
|
||||
<span className="text-body-small-regular-150 font-body-small-regular-150 text-text-neutral-tertiary">
|
||||
{t("emailInbox.compose.quotedHint")}
|
||||
</span>
|
||||
) : null}
|
||||
|
||||
<div className="flex w-full flex-col items-start gap-2">
|
||||
<span className="text-body-small-medium-0 font-body-small-medium-0 text-text-neutral-primary">
|
||||
{t("emailInbox.compose.attachments")}
|
||||
</span>
|
||||
{/* The ~/ui FileUpload component is display-only (no input, hardcoded copy),
|
||||
* so the real picker stays a hidden native input driven by a ~/ui Button. */}
|
||||
<input
|
||||
ref={fileInputRef}
|
||||
type="file"
|
||||
multiple
|
||||
className="hidden"
|
||||
onChange={(event) => addFiles(event.target.files)}
|
||||
data-ui-id="ui.email.compose.attachments"
|
||||
/>
|
||||
<Button
|
||||
variant="secondary"
|
||||
icon={<FeatherPaperclip />}
|
||||
onClick={() => fileInputRef.current?.click()}
|
||||
data-ui-id="ui.email.compose.attachments.add"
|
||||
>
|
||||
{t("emailInbox.compose.attachment.add")}
|
||||
</Button>
|
||||
{attachments.map((file, index) => {
|
||||
const tooLarge = file.size > COMPOSE_ATTACHMENT_MAX_BYTES;
|
||||
return (
|
||||
<div
|
||||
key={`${file.name}:${String(index)}`}
|
||||
className="border-border-default flex w-full items-center gap-3 rounded-md border border-solid px-3 py-2"
|
||||
data-attachment-name={file.name}
|
||||
data-attachment-oversized={tooLarge}
|
||||
>
|
||||
<FeatherFile className="text-body-large font-body-large text-icon-neutral-secondary flex-none" />
|
||||
<span className="text-body-small-medium-0 font-body-small-medium-0 text-text-neutral-primary min-w-0 grow shrink-0 basis-0 truncate">
|
||||
{file.name}
|
||||
</span>
|
||||
<span
|
||||
className={
|
||||
tooLarge
|
||||
? "text-body-small-regular-0 font-body-small-regular-0 text-text-feedback-negative flex-none whitespace-nowrap"
|
||||
: "text-body-small-regular-0 font-body-small-regular-0 text-text-neutral-tertiary flex-none whitespace-nowrap"
|
||||
}
|
||||
>
|
||||
{tooLarge ? t("emailInbox.compose.error.attachment_too_large") : attachmentSizeLabel(file.size)}
|
||||
</span>
|
||||
<IconButton
|
||||
size="small"
|
||||
icon={<FeatherX />}
|
||||
onClick={() => removeFile(index)}
|
||||
aria-label={t("emailInbox.compose.attachment.remove")}
|
||||
data-ui-id="ui.email.compose.attachment.remove"
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
|
||||
<div className="flex w-full items-center justify-end gap-2 pt-2">
|
||||
<Button
|
||||
variant="primary"
|
||||
icon={<FeatherSend />}
|
||||
loading={submitting === true}
|
||||
disabled={!canSend}
|
||||
onClick={send}
|
||||
data-ui-id="ui.email.compose.send"
|
||||
>
|
||||
{t("emailInbox.compose.send")}
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
</Card>
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
+400
@@ -0,0 +1,400 @@
|
||||
import { useState } from "react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { Link } from "react-router";
|
||||
import { FeatherArchive, FeatherMailOpen, FeatherMail, FeatherPaperclip, FeatherPenSquare, FeatherSettings } from "@subframe/core";
|
||||
import type { EmailInboxFilters, EmailInboxListVM, EmailInboxRow } from "@hivegrid/view-models";
|
||||
import { PAGE_HEADER_ICON_CLASS, PageHeader } from "../shared/PageShell";
|
||||
import { useLocaleFormatters, type LocaleFormatters } from "~/locale/format";
|
||||
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 { Loader } from "~/ui/components/Loader";
|
||||
import { SearchInput } from "~/ui/components/SearchInput";
|
||||
import { Select } from "~/ui/components/Select";
|
||||
import { Table } from "~/ui/components/Table";
|
||||
import { useLiveFilter } from "~/hooks/use-live-filter";
|
||||
|
||||
/** AK-UI-01 interim (AD-28): inbox list composed from ~/ui until David's final delta lands. */
|
||||
|
||||
export type EmailInboxBulkIntent = "mark-read" | "mark-unread" | "archive";
|
||||
|
||||
export type EmailInboxAppliedFilters = {
|
||||
readonly q: string;
|
||||
readonly mailboxId: string | null;
|
||||
readonly linked: EmailInboxFilters["linked"];
|
||||
readonly read: EmailInboxFilters["read"];
|
||||
};
|
||||
|
||||
export type EmailInboxListActions = {
|
||||
readonly onApplyFilters: (filters: EmailInboxAppliedFilters) => void;
|
||||
readonly onBulk: (intent: EmailInboxBulkIntent, messageIds: readonly string[]) => void | Promise<void>;
|
||||
readonly onLoadMore: (cursor: string) => void;
|
||||
readonly onCompose: () => void;
|
||||
readonly onOpenSettings: () => void;
|
||||
};
|
||||
|
||||
/** Sentinel for the "all mailboxes" option — Radix Select items must not use "". */
|
||||
const ALL_MAILBOXES = "all";
|
||||
|
||||
/** Same semantics as the previous inline route markup: relative below 7 days,
|
||||
* absolute otherwise; formatters pin the fixed app time zone (React #418). */
|
||||
function sentAtLabel(iso: string, formatters: LocaleFormatters): string {
|
||||
const date = new Date(iso);
|
||||
const ageMs = Date.now() - date.getTime();
|
||||
if (ageMs < 7 * 86_400_000) {
|
||||
const days = Math.floor(ageMs / 86_400_000);
|
||||
if (days === 0) return formatters.date(date, { hour: "2-digit", minute: "2-digit" });
|
||||
return formatters.relativeTime(-days, "day", { numeric: "auto" });
|
||||
}
|
||||
return formatters.date(date);
|
||||
}
|
||||
|
||||
function rowTextTone(row: EmailInboxRow): string {
|
||||
return row.isRead
|
||||
? "text-body-small-regular-150 font-body-small-regular-150 text-text-neutral-tertiary"
|
||||
: "text-body-small-medium-150 font-body-small-medium-150 text-text-neutral-primary";
|
||||
}
|
||||
|
||||
export function EmailInboxListPage({ vm, actions }: { vm: EmailInboxListVM; actions: EmailInboxListActions }): React.JSX.Element {
|
||||
const { t } = useTranslation();
|
||||
const formatters = useLocaleFormatters();
|
||||
const readyData = vm.status === "ready" ? vm.data : undefined;
|
||||
const [selectedIds, setSelectedIds] = useState<ReadonlySet<string>>(new Set());
|
||||
const [archiveDialogOpen, setArchiveDialogOpen] = useState(false);
|
||||
const [archiving, setArchiving] = useState(false);
|
||||
const [draftFilters, setDraftFilters] = useState<EmailInboxAppliedFilters>(() => ({
|
||||
q: readyData?.filters.q ?? "",
|
||||
mailboxId: readyData?.filters.mailboxId ?? null,
|
||||
linked: readyData?.filters.linked ?? "all",
|
||||
read: readyData?.filters.read ?? "all",
|
||||
}));
|
||||
|
||||
// Live filter: selects apply their fresh draft immediately, the search input
|
||||
// debounced against the currently applied query.
|
||||
useLiveFilter(draftFilters.q.trim(), readyData?.filters.q?.trim() ?? "", () =>
|
||||
actions.onApplyFilters({ ...draftFilters, q: draftFilters.q.trim() })
|
||||
);
|
||||
|
||||
function updateFilters(patch: Partial<EmailInboxAppliedFilters>): void {
|
||||
const next = { ...draftFilters, ...patch };
|
||||
setDraftFilters(next);
|
||||
actions.onApplyFilters(next);
|
||||
}
|
||||
|
||||
if (vm.status === "idle" || vm.status === "loading") {
|
||||
return (
|
||||
<div className="flex w-full flex-col items-start gap-6 px-6 py-6" data-ui-id="ui.email.inbox">
|
||||
<Card data-ui-id="ui.email.inbox.loading">
|
||||
<div className="flex w-full items-center gap-3">
|
||||
<Loader />
|
||||
<div className="flex flex-col items-start">
|
||||
<span className="text-body-default-medium-0 font-body-default-medium-0 text-text-neutral-primary">
|
||||
{t("emailInbox.list.loading.headline")}
|
||||
</span>
|
||||
<span className="text-body-small-regular-150 font-body-small-regular-150 text-text-neutral-tertiary">
|
||||
{t("emailInbox.list.loading.body")}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
</Card>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
if (vm.status === "error" || !readyData) {
|
||||
return (
|
||||
<div className="flex w-full flex-col items-start gap-6 px-6 py-6" data-ui-id="ui.email.inbox">
|
||||
<EmptyState
|
||||
outlined
|
||||
variant="error"
|
||||
title={t("emailInbox.list.error.headline")}
|
||||
body={vm.status === "error" ? t(vm.error.messageKey) : t("emailInbox.list.error.body")}
|
||||
data-ui-id="ui.email.inbox.error"
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
const { rows, mailboxOptions, nextCursor, canWrite, hasAnyMailbox } = readyData;
|
||||
const selectedVisibleIds = rows.filter((row) => selectedIds.has(row.id)).map((row) => row.id);
|
||||
const allVisibleSelected = rows.length > 0 && selectedVisibleIds.length === rows.length;
|
||||
|
||||
function toggleRow(id: string, checked: boolean): void {
|
||||
setSelectedIds((current) => {
|
||||
const next = new Set(current);
|
||||
if (checked) next.add(id);
|
||||
else next.delete(id);
|
||||
return next;
|
||||
});
|
||||
}
|
||||
|
||||
function toggleAllVisible(checked: boolean): void {
|
||||
setSelectedIds(checked ? new Set(rows.map((row) => row.id)) : new Set());
|
||||
}
|
||||
|
||||
function applyFilters(): void {
|
||||
actions.onApplyFilters({ ...draftFilters, q: draftFilters.q.trim() });
|
||||
}
|
||||
|
||||
function runBulk(intent: EmailInboxBulkIntent): void {
|
||||
if (selectedVisibleIds.length === 0) return;
|
||||
void actions.onBulk(intent, selectedVisibleIds);
|
||||
setSelectedIds(new Set());
|
||||
}
|
||||
|
||||
async function confirmArchive(): Promise<void> {
|
||||
if (selectedVisibleIds.length === 0) return;
|
||||
setArchiving(true);
|
||||
try {
|
||||
await actions.onBulk("archive", selectedVisibleIds);
|
||||
setSelectedIds(new Set());
|
||||
setArchiveDialogOpen(false);
|
||||
} finally {
|
||||
setArchiving(false);
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="bg-surface-neutral-primary flex w-full flex-col items-start" data-ui-id="ui.email.inbox">
|
||||
<PageHeader
|
||||
icon={<FeatherMail className={PAGE_HEADER_ICON_CLASS} />}
|
||||
title={t("emailInbox.list.title")}
|
||||
subtitle={t("emailInbox.list.subtitle")}
|
||||
actions={
|
||||
canWrite && hasAnyMailbox ? (
|
||||
<Button variant="primary" icon={<FeatherPenSquare />} onClick={actions.onCompose} data-ui-id="ui.email.inbox.compose">
|
||||
{t("emailInbox.list.compose")}
|
||||
</Button>
|
||||
) : undefined
|
||||
}
|
||||
/>
|
||||
|
||||
<div className="mobile:px-4 flex w-full flex-col items-start gap-4 px-6 py-6">
|
||||
{!hasAnyMailbox ? (
|
||||
<EmptyState
|
||||
outlined
|
||||
title={t(readyData.noMailboxHeadlineKey)}
|
||||
body={t(readyData.noMailboxBodyKey)}
|
||||
action={
|
||||
<Button variant="tertiary" icon={<FeatherSettings />} onClick={actions.onOpenSettings} data-ui-id="ui.email.inbox.connect">
|
||||
{t("emailInbox.list.connectCta")}
|
||||
</Button>
|
||||
}
|
||||
data-ui-id="ui.email.inbox.noMailbox"
|
||||
/>
|
||||
) : (
|
||||
<>
|
||||
<div className="mobile:flex-col mobile:items-stretch flex w-full flex-wrap items-center gap-2" data-ui-id="ui.email.inbox.filters">
|
||||
<SearchInput
|
||||
className="w-64 max-w-[256px]"
|
||||
placeholder={t("emailInbox.list.searchPlaceholder")}
|
||||
hideShortcut
|
||||
value={draftFilters.q}
|
||||
onChange={(event) => setDraftFilters((current) => ({ ...current, q: event.target.value }))}
|
||||
onKeyDown={(event) => {
|
||||
if (event.key === "Enter") applyFilters();
|
||||
}}
|
||||
data-ui-id="ui.email.inbox.search"
|
||||
/>
|
||||
<Select
|
||||
className="w-56 min-w-[160px]"
|
||||
placeholder={t("emailInbox.list.filter.allMailboxes")}
|
||||
value={draftFilters.mailboxId ?? ALL_MAILBOXES}
|
||||
onValueChange={(value) => updateFilters({ mailboxId: value === ALL_MAILBOXES ? null : value })}
|
||||
data-ui-id="ui.email.inbox.filter.mailbox"
|
||||
>
|
||||
<Select.Item value={ALL_MAILBOXES}>{t("emailInbox.list.filter.allMailboxes")}</Select.Item>
|
||||
{mailboxOptions.map((mailbox) => (
|
||||
<Select.Item key={mailbox.id} value={mailbox.id}>
|
||||
{mailbox.emailAddress}
|
||||
</Select.Item>
|
||||
))}
|
||||
</Select>
|
||||
<Select
|
||||
className="w-48 min-w-[140px]"
|
||||
value={draftFilters.linked}
|
||||
onValueChange={(value) => updateFilters({ linked: value as EmailInboxAppliedFilters["linked"] })}
|
||||
data-ui-id="ui.email.inbox.filter.linked"
|
||||
>
|
||||
<Select.Item value="all">{t("emailInbox.list.filter.linkedAll")}</Select.Item>
|
||||
<Select.Item value="linked">{t("emailInbox.list.filter.linked")}</Select.Item>
|
||||
<Select.Item value="unlinked">{t("emailInbox.list.filter.unlinked")}</Select.Item>
|
||||
</Select>
|
||||
<Select
|
||||
className="w-48 min-w-[140px]"
|
||||
value={draftFilters.read}
|
||||
onValueChange={(value) => updateFilters({ read: value as EmailInboxAppliedFilters["read"] })}
|
||||
data-ui-id="ui.email.inbox.filter.read"
|
||||
>
|
||||
<Select.Item value="all">{t("emailInbox.list.filter.readAll")}</Select.Item>
|
||||
<Select.Item value="unread">{t("emailInbox.list.filter.unread")}</Select.Item>
|
||||
<Select.Item value="read">{t("emailInbox.list.filter.read")}</Select.Item>
|
||||
</Select>
|
||||
</div>
|
||||
|
||||
{canWrite ? (
|
||||
<div className="flex w-full flex-wrap items-center gap-2" data-ui-id="ui.email.inbox.bulk">
|
||||
<span className="text-body-small-regular-0 font-body-small-regular-0 text-text-neutral-tertiary">
|
||||
{t("emailInbox.list.bulk.selectedCount", { count: selectedVisibleIds.length })}
|
||||
</span>
|
||||
<Button
|
||||
variant="tertiary"
|
||||
size="small"
|
||||
icon={<FeatherMailOpen />}
|
||||
disabled={selectedVisibleIds.length === 0}
|
||||
onClick={() => runBulk("mark-read")}
|
||||
data-ui-id="ui.email.inbox.bulk.markRead"
|
||||
>
|
||||
{t("emailInbox.list.bulk.markRead")}
|
||||
</Button>
|
||||
<Button
|
||||
variant="tertiary"
|
||||
size="small"
|
||||
icon={<FeatherMail />}
|
||||
disabled={selectedVisibleIds.length === 0}
|
||||
onClick={() => runBulk("mark-unread")}
|
||||
data-ui-id="ui.email.inbox.bulk.markUnread"
|
||||
>
|
||||
{t("emailInbox.list.bulk.markUnread")}
|
||||
</Button>
|
||||
<Button
|
||||
variant="tertiary"
|
||||
size="small"
|
||||
icon={<FeatherArchive />}
|
||||
disabled={selectedVisibleIds.length === 0}
|
||||
onClick={() => setArchiveDialogOpen(true)}
|
||||
data-ui-id="ui.email.inbox.bulk.archive"
|
||||
>
|
||||
{t("emailInbox.list.bulk.archive")}
|
||||
</Button>
|
||||
</div>
|
||||
) : null}
|
||||
|
||||
{rows.length === 0 ? (
|
||||
<EmptyState outlined title={t(readyData.emptyHeadlineKey)} body={t(readyData.emptyBodyKey)} data-ui-id="ui.email.inbox.empty" />
|
||||
) : (
|
||||
<div className="w-full overflow-x-auto" data-ui-id="ui.email.inbox.list">
|
||||
<Table
|
||||
header={
|
||||
<Table.HeaderRow>
|
||||
{canWrite ? (
|
||||
<Table.HeaderCell className="w-10">
|
||||
<Checkbox
|
||||
hideLabel
|
||||
checked={allVisibleSelected}
|
||||
onCheckedChange={toggleAllVisible}
|
||||
aria-label={t("emailInbox.list.selectAll")}
|
||||
/>
|
||||
</Table.HeaderCell>
|
||||
) : null}
|
||||
<Table.HeaderCell>{t("emailInbox.list.table.sender")}</Table.HeaderCell>
|
||||
<Table.HeaderCell>{t("emailInbox.list.table.subject")}</Table.HeaderCell>
|
||||
<Table.HeaderCell>{t("emailInbox.list.table.mailbox")}</Table.HeaderCell>
|
||||
<Table.HeaderCell>{t("emailInbox.list.table.date")}</Table.HeaderCell>
|
||||
</Table.HeaderRow>
|
||||
}
|
||||
>
|
||||
{rows.map((row) => (
|
||||
<Table.Row key={row.id} data-row-id={row.id} data-unread={!row.isRead}>
|
||||
{canWrite ? (
|
||||
<Table.Cell className="w-10">
|
||||
<Checkbox
|
||||
hideLabel
|
||||
checked={selectedIds.has(row.id)}
|
||||
onCheckedChange={(checked) => toggleRow(row.id, checked)}
|
||||
aria-label={t("emailInbox.list.selectRow")}
|
||||
/>
|
||||
</Table.Cell>
|
||||
) : null}
|
||||
<Table.Cell>
|
||||
<div className="flex min-w-0 items-center gap-2">
|
||||
<span className={`truncate ${rowTextTone(row)}`}>{row.fromName ?? row.fromAddress}</span>
|
||||
{row.isNewsletter ? (
|
||||
<BadgeFeedback farbe="subtle-neutral" size="small">
|
||||
{t("emailInbox.list.newsletterBadge")}
|
||||
</BadgeFeedback>
|
||||
) : null}
|
||||
</div>
|
||||
</Table.Cell>
|
||||
<Table.Cell>
|
||||
<div className="flex min-w-0 flex-col items-start">
|
||||
<Link to={row.detailHref} className="flex min-w-0 items-center gap-1">
|
||||
<span className={`truncate ${rowTextTone(row)}`}>{row.subject ?? t("emailInbox.list.noSubject")}</span>
|
||||
{row.hasAttachments ? (
|
||||
<FeatherPaperclip className="text-body-small-regular-0 font-body-small-regular-0 text-icon-neutral-tertiary flex-none" />
|
||||
) : null}
|
||||
</Link>
|
||||
<div className="flex min-w-0 items-center gap-2">
|
||||
{row.snippet ? (
|
||||
<span className="text-body-extra-small-regular-0 font-body-extra-small-regular-0 text-text-neutral-tertiary truncate">
|
||||
{row.snippet}
|
||||
</span>
|
||||
) : null}
|
||||
{row.links.map((link) => (
|
||||
<BadgeFeedback key={`${link.type}:${link.id}`} farbe="subtle-neutral" size="small" data-link-type={link.type}>
|
||||
{t(`emailInbox.list.linkBadge.${link.type}`)}
|
||||
</BadgeFeedback>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
</Table.Cell>
|
||||
<Table.Cell>
|
||||
<span className="text-body-small-regular-0 font-body-small-regular-0 text-text-neutral-tertiary truncate">
|
||||
{row.mailbox.emailAddress}
|
||||
</span>
|
||||
</Table.Cell>
|
||||
<Table.Cell>
|
||||
<span className="text-body-small-regular-0 font-body-small-regular-0 text-text-neutral-tertiary whitespace-nowrap">
|
||||
{sentAtLabel(row.sentAt, formatters)}
|
||||
</span>
|
||||
</Table.Cell>
|
||||
</Table.Row>
|
||||
))}
|
||||
</Table>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{nextCursor ? (
|
||||
<div className="flex w-full items-center justify-center">
|
||||
<Button variant="secondary" onClick={() => actions.onLoadMore(nextCursor)} data-ui-id="ui.email.inbox.more">
|
||||
{t("emailInbox.list.loadMore")}
|
||||
</Button>
|
||||
</div>
|
||||
) : null}
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
|
||||
<Dialog open={archiveDialogOpen} onOpenChange={(open: boolean) => (open ? undefined : setArchiveDialogOpen(false))}>
|
||||
<Dialog.Content
|
||||
className="w-[420px] max-w-[90vw] p-4"
|
||||
aria-label={t("emailInbox.list.archiveDialog.title")}
|
||||
data-ui-id="ui.email.inbox.archiveDialog"
|
||||
>
|
||||
<div className="flex w-full flex-col items-start gap-2">
|
||||
<span className="text-heading-0 font-heading-0 text-text-neutral-primary">{t("emailInbox.list.archiveDialog.title")}</span>
|
||||
<span className="text-body-default-regular-150 font-body-default-regular-150 text-text-neutral-secondary">
|
||||
{t("emailInbox.list.archiveDialog.body", { count: selectedVisibleIds.length })}
|
||||
</span>
|
||||
</div>
|
||||
<div className="flex w-full items-center justify-end gap-2 pt-4">
|
||||
<Button variant="tertiary" disabled={archiving} onClick={() => setArchiveDialogOpen(false)}>
|
||||
{t("emailInbox.list.archiveDialog.cancel")}
|
||||
</Button>
|
||||
<Button
|
||||
variant="destructive"
|
||||
loading={archiving}
|
||||
onClick={() => void confirmArchive()}
|
||||
data-ui-id="ui.email.inbox.archiveConfirm"
|
||||
>
|
||||
{t("emailInbox.list.archiveDialog.confirm")}
|
||||
</Button>
|
||||
</div>
|
||||
</Dialog.Content>
|
||||
</Dialog>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
+176
@@ -0,0 +1,176 @@
|
||||
// VA-P23 interim-UI (AD-28) — mailbox connect settings screen composed from
|
||||
// ~/ui: PageShell header, provider connect actions, mailbox cards with status
|
||||
// badge, initial-sync progress and Klartext errors. Presentational; the route
|
||||
// owns loader/action, mutations POST via plain Forms (csrf prop, same pattern
|
||||
// as CalendarConnectionsPage). Final Subframe optics = tracked design-nachzug.
|
||||
|
||||
import { Form } from "react-router";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { FeatherMail, FeatherPlus } from "@subframe/core";
|
||||
import type { EmailMailboxListVM, EmailMailboxRow, EmailMailboxStatus } 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 { useLocaleFormatters } from "~/locale/format";
|
||||
import { PAGE_HEADER_ICON_CLASS, PageBackLink, PageBody, PageHeader, PageIntro, PageShell } from "../shared/PageShell";
|
||||
|
||||
export type EmailMailboxSettingsPageProps = {
|
||||
vm: EmailMailboxListVM;
|
||||
csrf: string | null;
|
||||
flash: "connected" | "error" | null;
|
||||
/** Path back to the integrations catalog (settings/integrations). */
|
||||
backHref: string;
|
||||
/** Inside the Erweiterungen hub (AK-SET-01) the hub owns the header. */
|
||||
embedded?: boolean;
|
||||
};
|
||||
|
||||
function statusBadgeTone(status: EmailMailboxStatus): "subtle-positive" | "subtle-negative" | "subtle-neutral" {
|
||||
if (status === "active") return "subtle-positive";
|
||||
if (status === "error" || status === "revoked") return "subtle-negative";
|
||||
return "subtle-neutral";
|
||||
}
|
||||
|
||||
function MailboxCard({ row, csrf }: { row: EmailMailboxRow; csrf: string | null }) {
|
||||
const { t } = useTranslation();
|
||||
const formatters = useLocaleFormatters();
|
||||
return (
|
||||
<div className="flex w-full flex-col gap-2 rounded-lg border border-solid border-border-default bg-surface-neutral-primary p-4" data-row-id={row.id}>
|
||||
<div className="flex w-full flex-wrap items-start justify-between gap-2">
|
||||
<div className="flex flex-col gap-1">
|
||||
<div className="flex items-center gap-2">
|
||||
<span className="text-body-default-medium-0 font-body-default-medium-0 text-text-neutral-primary">{row.emailAddress}</span>
|
||||
<BadgeFeedback farbe="subtle-neutral" size="small">
|
||||
{t(row.providerKey)}
|
||||
</BadgeFeedback>
|
||||
</div>
|
||||
{row.lastSyncAt ? (
|
||||
<span className="text-body-small-regular-150 font-body-small-regular-150 text-text-neutral-tertiary">
|
||||
{t("emailInbox.settings.lastSync")}: {formatters.dateTime(row.lastSyncAt)}
|
||||
</span>
|
||||
) : null}
|
||||
</div>
|
||||
<div className="flex items-center gap-2">
|
||||
<span data-status={row.status}>
|
||||
<BadgeFeedback farbe={statusBadgeTone(row.status)} size="small">
|
||||
{t(row.statusKey)}
|
||||
</BadgeFeedback>
|
||||
</span>
|
||||
{row.isOwn ? (
|
||||
<Form method="post">
|
||||
{csrf ? <input type="hidden" name="csrf" value={csrf} /> : null}
|
||||
<input type="hidden" name="intent" value="disconnect" />
|
||||
<input type="hidden" name="mailboxId" value={row.id} />
|
||||
<Button type="submit" variant="destructive" size="small" data-ui-id="ui.email.settings.disconnect">
|
||||
{t("emailInbox.settings.disconnect")}
|
||||
</Button>
|
||||
</Form>
|
||||
) : null}
|
||||
</div>
|
||||
</div>
|
||||
{row.initialSync.status !== "completed" ? (
|
||||
<span
|
||||
className="text-body-small-regular-150 font-body-small-regular-150 text-text-neutral-tertiary"
|
||||
data-ui-id="ui.email.settings.initialSync"
|
||||
data-sync-status={row.initialSync.status}
|
||||
>
|
||||
{t(row.initialSync.statusKey)}
|
||||
{row.initialSync.progressPercent !== null && ` — ${row.initialSync.progressPercent}%`}
|
||||
{row.initialSync.fetchedCount !== null && ` (${t("emailInbox.settings.initialSync.fetched", { count: row.initialSync.fetchedCount })})`}
|
||||
</span>
|
||||
) : null}
|
||||
{row.lastErrorText ? (
|
||||
<span className="text-body-small-regular-150 font-body-small-regular-150 text-text-feedback-negative" data-ui-id="ui.email.settings.error">
|
||||
{row.lastErrorText.startsWith("emailInbox.") ? t(row.lastErrorText) : row.lastErrorText}
|
||||
</span>
|
||||
) : null}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export function EmailMailboxSettingsPage({ vm, csrf, flash, backHref, embedded = false }: EmailMailboxSettingsPageProps) {
|
||||
const { t } = useTranslation();
|
||||
|
||||
if (vm.status !== "ready" || !vm.data) {
|
||||
return <PageShell uiId="ui.email.settings" />;
|
||||
}
|
||||
const { rows, canConnect, configuredProviders, emptyHeadlineKey, emptyBodyKey, notConfiguredKey } = vm.data;
|
||||
const anyConfigured = configuredProviders.gmail || configuredProviders.microsoft;
|
||||
|
||||
// AK-SET-01: hoisted so the connect buttons survive in both the standalone
|
||||
// header and the hub's intro row.
|
||||
const connectActions =
|
||||
canConnect && anyConfigured ? (
|
||||
<>
|
||||
{configuredProviders.gmail ? (
|
||||
<Form method="post">
|
||||
{csrf ? <input type="hidden" name="csrf" value={csrf} /> : null}
|
||||
<input type="hidden" name="intent" value="connect-gmail" />
|
||||
<Button type="submit" icon={<FeatherPlus />} data-ui-id="ui.email.settings.connect.gmail">
|
||||
{t("emailInbox.settings.connectGmail")}
|
||||
</Button>
|
||||
</Form>
|
||||
) : null}
|
||||
{configuredProviders.microsoft ? (
|
||||
<Form method="post">
|
||||
{csrf ? <input type="hidden" name="csrf" value={csrf} /> : null}
|
||||
<input type="hidden" name="intent" value="connect-microsoft" />
|
||||
<Button type="submit" icon={<FeatherPlus />} data-ui-id="ui.email.settings.connect.microsoft">
|
||||
{t("emailInbox.settings.connectMicrosoft")}
|
||||
</Button>
|
||||
</Form>
|
||||
) : null}
|
||||
</>
|
||||
) : null
|
||||
;
|
||||
|
||||
return (
|
||||
<PageShell uiId="ui.email.settings">
|
||||
{embedded ? null : (
|
||||
<PageHeader
|
||||
icon={<FeatherMail className={PAGE_HEADER_ICON_CLASS} />}
|
||||
title={t("emailInbox.settings.title")}
|
||||
subtitle={t("emailInbox.settings.subtitle")}
|
||||
actions={connectActions}
|
||||
/>
|
||||
)}
|
||||
<PageBody>
|
||||
{embedded ? (
|
||||
<div className="mobile:flex-col mobile:items-start flex w-full items-start justify-between gap-4">
|
||||
<PageIntro uiId="ui.email.settings.intro">{t("emailInbox.settings.subtitle")}</PageIntro>
|
||||
{connectActions ? <div className="flex items-center gap-2">{connectActions}</div> : null}
|
||||
</div>
|
||||
) : (
|
||||
<PageBackLink to={backHref} label={t("integrations.connections.back")} uiId="ui.email.settings.back" />
|
||||
)}
|
||||
{flash === "connected" ? (
|
||||
<div data-ui-id="ui.email.settings.flash.connected">
|
||||
<Alert variant="success" title={t("emailInbox.settings.flash.connected")} />
|
||||
</div>
|
||||
) : null}
|
||||
{flash === "error" ? (
|
||||
<div data-ui-id="ui.email.settings.flash.error">
|
||||
<Alert variant="error" title={t("emailInbox.settings.flash.error")} />
|
||||
</div>
|
||||
) : null}
|
||||
{!anyConfigured ? (
|
||||
<div data-ui-id="ui.email.settings.notConfigured">
|
||||
<Alert variant="warning" title={t(notConfiguredKey)} />
|
||||
</div>
|
||||
) : null}
|
||||
|
||||
{rows.length === 0 ? (
|
||||
<div data-ui-id="ui.email.settings.empty">
|
||||
<EmptyState title={t(emptyHeadlineKey)} body={t(emptyBodyKey)} />
|
||||
</div>
|
||||
) : (
|
||||
<div className="flex w-full flex-col gap-3" data-ui-id="ui.email.settings.list">
|
||||
{rows.map((row) => (
|
||||
<MailboxCard key={row.id} row={row} csrf={csrf} />
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
</PageBody>
|
||||
</PageShell>
|
||||
);
|
||||
}
|
||||
+467
@@ -0,0 +1,467 @@
|
||||
import { useState } from "react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { Link } from "react-router";
|
||||
import {
|
||||
FeatherArrowLeft,
|
||||
FeatherCornerUpLeft,
|
||||
FeatherCornerUpRight,
|
||||
FeatherDownload,
|
||||
FeatherFile,
|
||||
FeatherImage,
|
||||
FeatherLink,
|
||||
FeatherMail,
|
||||
FeatherMailOpen,
|
||||
FeatherUnlink,
|
||||
} from "@subframe/core";
|
||||
import type { EmailAttachmentVM, EmailMessageDetailVM, EmailThreadMessageVM } from "@hivegrid/view-models";
|
||||
import { useLocaleFormatters, type LocaleFormatters } from "~/locale/format";
|
||||
import { Accordion } from "~/ui/components/Accordion";
|
||||
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 { Loader } from "~/ui/components/Loader";
|
||||
import { TextInput } from "~/ui/components/TextInput";
|
||||
|
||||
/** AK-UI-02 interim (AD-28): message detail composed from ~/ui until David's final delta lands. */
|
||||
|
||||
export type EmailMessageDetailLinkTargets = {
|
||||
readonly kontaktId: string | null;
|
||||
readonly leadId: string | null;
|
||||
readonly projektId: string | null;
|
||||
};
|
||||
|
||||
export type EmailMessageDetailActions = {
|
||||
readonly onSetLink: (targets: EmailMessageDetailLinkTargets) => void | Promise<void>;
|
||||
readonly onClearLink: () => void | Promise<void>;
|
||||
readonly onImportAttachment: (attachmentId: string) => void | Promise<void>;
|
||||
readonly onToggleRead: () => void | Promise<void>;
|
||||
readonly onLoadImages: () => void;
|
||||
readonly onReply: () => void;
|
||||
readonly onForward: () => void;
|
||||
readonly onBack: () => void;
|
||||
};
|
||||
|
||||
/** Formatters pin the fixed app time zone — a raw toLocaleString would drift
|
||||
* between server and client render (React #418). */
|
||||
function sentAtLabel(iso: string, formatters: LocaleFormatters): string {
|
||||
return formatters.dateTime(new Date(iso));
|
||||
}
|
||||
|
||||
/** Same rounding the previous inline route markup used. */
|
||||
function attachmentSizeLabel(sizeBytes: number): string {
|
||||
return `${Math.max(1, Math.round(sizeBytes / 1024))} KB`;
|
||||
}
|
||||
|
||||
function ThreadEntry({
|
||||
entry,
|
||||
allowExternalImages,
|
||||
onLoadImages,
|
||||
formatters,
|
||||
}: {
|
||||
entry: EmailThreadMessageVM;
|
||||
allowExternalImages: boolean;
|
||||
onLoadImages: () => void;
|
||||
formatters: LocaleFormatters;
|
||||
}): React.JSX.Element {
|
||||
const { t } = useTranslation();
|
||||
return (
|
||||
<Accordion
|
||||
variant="card"
|
||||
defaultOpen={entry.isFocused}
|
||||
className="w-full"
|
||||
data-thread-id={entry.id}
|
||||
data-focused={entry.isFocused}
|
||||
trigger={
|
||||
<div className="flex w-full items-center justify-between gap-4 px-4 py-3">
|
||||
<div className="flex min-w-0 flex-col items-start">
|
||||
<span className="text-body-default-medium-0 font-body-default-medium-0 text-text-neutral-primary truncate">
|
||||
{entry.fromName ?? entry.fromAddress}
|
||||
</span>
|
||||
<span className="text-body-small-regular-0 font-body-small-regular-0 text-text-neutral-tertiary truncate">
|
||||
{t("emailInbox.detail.to")} {entry.toSummary}
|
||||
</span>
|
||||
</div>
|
||||
<div className="flex flex-none items-center gap-2">
|
||||
<span className="text-body-small-regular-0 font-body-small-regular-0 text-text-neutral-tertiary whitespace-nowrap">
|
||||
{sentAtLabel(entry.sentAt, formatters)}
|
||||
</span>
|
||||
<Accordion.Chevron />
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
>
|
||||
<div className="flex w-full flex-col items-start gap-3 px-4 pb-4">
|
||||
{entry.blockedImageCount > 0 && !allowExternalImages ? (
|
||||
<Alert
|
||||
variant="warning"
|
||||
title={t("emailInbox.detail.imagesBlocked", { count: entry.blockedImageCount })}
|
||||
actions={
|
||||
<Button variant="tertiary" size="small" icon={<FeatherImage />} onClick={onLoadImages}>
|
||||
{t("emailInbox.detail.loadImages")}
|
||||
</Button>
|
||||
}
|
||||
className="w-full"
|
||||
data-ui-id="ui.email.detail.blockedImages"
|
||||
/>
|
||||
) : null}
|
||||
{/* Sanitized server-side (dompurify) — safe to inject. */}
|
||||
<div
|
||||
className="prose prose-sm text-body-default-regular-150 font-body-default-regular-150 text-text-neutral-primary max-w-none"
|
||||
dangerouslySetInnerHTML={{ __html: entry.safeBodyHtml }}
|
||||
data-ui-id="ui.email.detail.body"
|
||||
/>
|
||||
</div>
|
||||
</Accordion>
|
||||
);
|
||||
}
|
||||
|
||||
export function EmailMessageDetailPage({
|
||||
vm,
|
||||
actions,
|
||||
actionErrorKey,
|
||||
justSent,
|
||||
}: {
|
||||
vm: EmailMessageDetailVM;
|
||||
actions: EmailMessageDetailActions;
|
||||
actionErrorKey?: string;
|
||||
justSent?: boolean;
|
||||
}): React.JSX.Element {
|
||||
const { t } = useTranslation();
|
||||
const formatters = useLocaleFormatters();
|
||||
const readyData = vm.status === "ready" ? vm.data : undefined;
|
||||
const [linkDialogOpen, setLinkDialogOpen] = useState(false);
|
||||
const [clearLinkDialogOpen, setClearLinkDialogOpen] = useState(false);
|
||||
const [importTarget, setImportTarget] = useState<EmailAttachmentVM | null>(null);
|
||||
const [busy, setBusy] = useState(false);
|
||||
const [linkDraft, setLinkDraft] = useState<{ kontaktId: string; leadId: string; projektId: string }>({
|
||||
kontaktId: "",
|
||||
leadId: "",
|
||||
projektId: "",
|
||||
});
|
||||
|
||||
if (vm.status === "idle" || vm.status === "loading") {
|
||||
return (
|
||||
<div className="flex w-full flex-col items-start gap-6 px-6 py-6" data-ui-id="ui.email.detail">
|
||||
<Card data-ui-id="ui.email.detail.loading">
|
||||
<div className="flex w-full items-center gap-3">
|
||||
<Loader />
|
||||
<div className="flex flex-col items-start">
|
||||
<span className="text-body-default-medium-0 font-body-default-medium-0 text-text-neutral-primary">
|
||||
{t("emailInbox.detail.loading.headline")}
|
||||
</span>
|
||||
<span className="text-body-small-regular-150 font-body-small-regular-150 text-text-neutral-tertiary">
|
||||
{t("emailInbox.detail.loading.body")}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
</Card>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
if (vm.status === "error" || !readyData) {
|
||||
return (
|
||||
<div className="flex w-full flex-col items-start gap-6 px-6 py-6" data-ui-id="ui.email.detail">
|
||||
<EmptyState
|
||||
outlined
|
||||
variant="error"
|
||||
title={t("emailInbox.detail.error.headline")}
|
||||
body={vm.status === "error" ? t(vm.error.messageKey) : t("emailInbox.detail.error.body")}
|
||||
data-ui-id="ui.email.detail.error"
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
const { subject, mailbox, thread, attachments, match, canWrite, allowExternalImages } = readyData;
|
||||
const focused = thread.find((entry) => entry.isFocused) ?? thread[0];
|
||||
const focusedIsRead = focused?.isRead ?? false;
|
||||
|
||||
async function runBusy(action: () => void | Promise<void>, close: () => void): Promise<void> {
|
||||
setBusy(true);
|
||||
try {
|
||||
await action();
|
||||
close();
|
||||
} finally {
|
||||
setBusy(false);
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="bg-surface-neutral-primary flex w-full flex-col items-start" data-ui-id="ui.email.detail">
|
||||
<div className="border-border-default bg-surface-neutral-secondary mobile:flex-col mobile:px-4 flex w-full items-start justify-between gap-4 border-b border-solid px-6 py-6">
|
||||
<div className="flex min-w-0 flex-col items-start gap-1">
|
||||
<Button variant="tertiary" size="small" icon={<FeatherArrowLeft />} onClick={actions.onBack} data-ui-id="ui.email.detail.back">
|
||||
{t("emailInbox.detail.back")}
|
||||
</Button>
|
||||
<h1 className="text-heading- font-heading- text-text-neutral-primary">{subject ?? t("emailInbox.list.noSubject")}</h1>
|
||||
<span className="text-body-default-regular-150 font-body-default-regular-150 text-text-neutral-tertiary">{mailbox.emailAddress}</span>
|
||||
</div>
|
||||
{canWrite ? (
|
||||
<div className="flex flex-none flex-wrap items-center gap-2">
|
||||
<Button variant="primary" icon={<FeatherCornerUpLeft />} onClick={actions.onReply} data-ui-id="ui.email.detail.reply">
|
||||
{t("emailInbox.detail.reply")}
|
||||
</Button>
|
||||
<Button variant="secondary" icon={<FeatherCornerUpRight />} onClick={actions.onForward} data-ui-id="ui.email.detail.forward">
|
||||
{t("emailInbox.detail.forward")}
|
||||
</Button>
|
||||
<Button
|
||||
variant="tertiary"
|
||||
icon={focusedIsRead ? <FeatherMail /> : <FeatherMailOpen />}
|
||||
onClick={() => void actions.onToggleRead()}
|
||||
data-ui-id="ui.email.detail.toggleRead"
|
||||
>
|
||||
{focusedIsRead ? t("emailInbox.detail.toggleRead.markUnread") : t("emailInbox.detail.toggleRead.markRead")}
|
||||
</Button>
|
||||
</div>
|
||||
) : null}
|
||||
</div>
|
||||
|
||||
<div className="mobile:px-4 flex w-full flex-col items-start gap-4 px-6 py-6">
|
||||
{justSent ? (
|
||||
<Alert
|
||||
variant="success"
|
||||
notDismissible
|
||||
title={t("emailInbox.detail.sent.headline")}
|
||||
description={t("emailInbox.detail.sent.body")}
|
||||
className="w-full"
|
||||
data-ui-id="ui.email.detail.sent"
|
||||
/>
|
||||
) : null}
|
||||
|
||||
{actionErrorKey ? (
|
||||
<Alert variant="error" notDismissible title={t(actionErrorKey)} className="w-full" data-ui-id="ui.email.detail.actionError" />
|
||||
) : null}
|
||||
|
||||
<Card className="w-full" data-ui-id="ui.email.detail.linkEditor">
|
||||
<div className="mobile:flex-col mobile:items-start flex w-full items-center justify-between gap-4">
|
||||
<div className="flex min-w-0 flex-wrap items-center gap-2">
|
||||
<span className="text-body-small-regular-150 font-body-small-regular-150 text-text-neutral-tertiary">{t(match.sourceKey)}</span>
|
||||
{match.links.map((link) => (
|
||||
<Link key={`${link.type}:${link.id}`} to={link.href} data-link-type={link.type}>
|
||||
<BadgeFeedback farbe="subtle-neutral" size="small">
|
||||
{t(`emailInbox.list.linkBadge.${link.type}`)}
|
||||
</BadgeFeedback>
|
||||
</Link>
|
||||
))}
|
||||
{match.links.length === 0 ? (
|
||||
<span className="text-body-small-regular-150 font-body-small-regular-150 text-text-neutral-tertiary">
|
||||
{t("emailInbox.detail.match.noneHint")}
|
||||
</span>
|
||||
) : null}
|
||||
</div>
|
||||
{canWrite ? (
|
||||
<div className="flex flex-none items-center gap-2">
|
||||
<Button
|
||||
variant="secondary"
|
||||
size="small"
|
||||
icon={<FeatherLink />}
|
||||
onClick={() => {
|
||||
setLinkDraft({ kontaktId: "", leadId: "", projektId: "" });
|
||||
setLinkDialogOpen(true);
|
||||
}}
|
||||
data-ui-id="ui.email.detail.setLink"
|
||||
>
|
||||
{t("emailInbox.detail.applyLink")}
|
||||
</Button>
|
||||
<Button
|
||||
variant="tertiary"
|
||||
size="small"
|
||||
icon={<FeatherUnlink />}
|
||||
disabled={match.links.length === 0}
|
||||
onClick={() => setClearLinkDialogOpen(true)}
|
||||
data-ui-id="ui.email.detail.clearLink"
|
||||
>
|
||||
{t("emailInbox.detail.clearLink")}
|
||||
</Button>
|
||||
</div>
|
||||
) : null}
|
||||
</div>
|
||||
</Card>
|
||||
|
||||
<div className="flex w-full flex-col items-start gap-2" data-ui-id="ui.email.detail.thread">
|
||||
{thread.map((entry) => (
|
||||
<ThreadEntry
|
||||
key={entry.id}
|
||||
entry={entry}
|
||||
allowExternalImages={allowExternalImages}
|
||||
onLoadImages={actions.onLoadImages}
|
||||
formatters={formatters}
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
|
||||
{attachments.length > 0 ? (
|
||||
<Card className="w-full" data-ui-id="ui.email.detail.attachments">
|
||||
<div className="flex w-full flex-col items-start gap-3">
|
||||
<span className="text-body-default-medium-0 font-body-default-medium-0 text-text-neutral-primary">
|
||||
{t("emailInbox.detail.attachments")}
|
||||
</span>
|
||||
<div className="flex w-full flex-col items-start gap-2">
|
||||
{attachments.map((attachment) => (
|
||||
<div
|
||||
key={attachment.attachmentId}
|
||||
className="border-border-default flex w-full items-center gap-3 rounded-md border border-solid px-3 py-2"
|
||||
data-attachment-id={attachment.attachmentId}
|
||||
>
|
||||
<FeatherFile className="text-body-large font-body-large text-icon-neutral-secondary flex-none" />
|
||||
<span className="text-body-small-medium-0 font-body-small-medium-0 text-text-neutral-primary min-w-0 grow shrink-0 basis-0 truncate">
|
||||
{attachment.filename}
|
||||
</span>
|
||||
<span className="text-body-small-regular-0 font-body-small-regular-0 text-text-neutral-tertiary flex-none whitespace-nowrap">
|
||||
{attachmentSizeLabel(attachment.sizeBytes)}
|
||||
</span>
|
||||
{attachment.downloadHref ? (
|
||||
<Link to={attachment.downloadHref} className="flex-none">
|
||||
<Button variant="tertiary" size="small" icon={<FeatherDownload />}>
|
||||
{t("emailInbox.detail.attachment.download")}
|
||||
</Button>
|
||||
</Link>
|
||||
) : canWrite ? (
|
||||
<Button
|
||||
variant="tertiary"
|
||||
size="small"
|
||||
className="flex-none"
|
||||
onClick={() => setImportTarget(attachment)}
|
||||
data-ui-id="ui.email.detail.attachment.import"
|
||||
>
|
||||
{t("emailInbox.detail.attachment.import")}
|
||||
</Button>
|
||||
) : null}
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
</Card>
|
||||
) : null}
|
||||
</div>
|
||||
|
||||
<Dialog open={linkDialogOpen} onOpenChange={(open: boolean) => (open ? undefined : setLinkDialogOpen(false))}>
|
||||
<Dialog.Content className="w-[420px] max-w-[90vw] p-4" aria-label={t("emailInbox.detail.linkDialog.title")} data-ui-id="ui.email.detail.linkDialog">
|
||||
<div className="flex w-full flex-col items-start gap-2">
|
||||
<span className="text-heading-0 font-heading-0 text-text-neutral-primary">{t("emailInbox.detail.linkDialog.title")}</span>
|
||||
<span className="text-body-default-regular-150 font-body-default-regular-150 text-text-neutral-secondary">
|
||||
{t("emailInbox.detail.linkDialog.body")}
|
||||
</span>
|
||||
</div>
|
||||
<div className="flex w-full flex-col items-start gap-3 pt-4">
|
||||
<TextInput className="w-full" label={t("emailInbox.detail.linkKontakt")}>
|
||||
<TextInput.Input
|
||||
value={linkDraft.kontaktId}
|
||||
placeholder={t("emailInbox.detail.linkIdPlaceholder")}
|
||||
onChange={(event) => setLinkDraft((current) => ({ ...current, kontaktId: event.target.value }))}
|
||||
data-ui-id="ui.email.detail.linkDialog.kontaktId"
|
||||
/>
|
||||
</TextInput>
|
||||
<TextInput className="w-full" label={t("emailInbox.detail.linkLead")}>
|
||||
<TextInput.Input
|
||||
value={linkDraft.leadId}
|
||||
placeholder={t("emailInbox.detail.linkIdPlaceholder")}
|
||||
onChange={(event) => setLinkDraft((current) => ({ ...current, leadId: event.target.value }))}
|
||||
data-ui-id="ui.email.detail.linkDialog.leadId"
|
||||
/>
|
||||
</TextInput>
|
||||
<TextInput className="w-full" label={t("emailInbox.detail.linkProjekt")}>
|
||||
<TextInput.Input
|
||||
value={linkDraft.projektId}
|
||||
placeholder={t("emailInbox.detail.linkIdPlaceholder")}
|
||||
onChange={(event) => setLinkDraft((current) => ({ ...current, projektId: event.target.value }))}
|
||||
data-ui-id="ui.email.detail.linkDialog.projektId"
|
||||
/>
|
||||
</TextInput>
|
||||
</div>
|
||||
<div className="flex w-full items-center justify-end gap-2 pt-4">
|
||||
<Button variant="tertiary" disabled={busy} onClick={() => setLinkDialogOpen(false)}>
|
||||
{t("emailInbox.detail.linkDialog.cancel")}
|
||||
</Button>
|
||||
<Button
|
||||
variant="primary"
|
||||
loading={busy}
|
||||
disabled={!linkDraft.kontaktId.trim() && !linkDraft.leadId.trim() && !linkDraft.projektId.trim()}
|
||||
onClick={() =>
|
||||
void runBusy(
|
||||
() =>
|
||||
actions.onSetLink({
|
||||
kontaktId: linkDraft.kontaktId.trim() || null,
|
||||
leadId: linkDraft.leadId.trim() || null,
|
||||
projektId: linkDraft.projektId.trim() || null,
|
||||
}),
|
||||
() => setLinkDialogOpen(false)
|
||||
)
|
||||
}
|
||||
data-ui-id="ui.email.detail.linkDialog.confirm"
|
||||
>
|
||||
{t("emailInbox.detail.linkDialog.confirm")}
|
||||
</Button>
|
||||
</div>
|
||||
</Dialog.Content>
|
||||
</Dialog>
|
||||
|
||||
<Dialog open={clearLinkDialogOpen} onOpenChange={(open: boolean) => (open ? undefined : setClearLinkDialogOpen(false))}>
|
||||
<Dialog.Content
|
||||
className="w-[420px] max-w-[90vw] p-4"
|
||||
aria-label={t("emailInbox.detail.clearLinkDialog.title")}
|
||||
data-ui-id="ui.email.detail.clearLinkDialog"
|
||||
>
|
||||
<div className="flex w-full flex-col items-start gap-2">
|
||||
<span className="text-heading-0 font-heading-0 text-text-neutral-primary">{t("emailInbox.detail.clearLinkDialog.title")}</span>
|
||||
<span className="text-body-default-regular-150 font-body-default-regular-150 text-text-neutral-secondary">
|
||||
{t("emailInbox.detail.clearLinkDialog.body")}
|
||||
</span>
|
||||
</div>
|
||||
<div className="flex w-full items-center justify-end gap-2 pt-4">
|
||||
<Button variant="tertiary" disabled={busy} onClick={() => setClearLinkDialogOpen(false)}>
|
||||
{t("emailInbox.detail.clearLinkDialog.cancel")}
|
||||
</Button>
|
||||
<Button
|
||||
variant="destructive"
|
||||
loading={busy}
|
||||
onClick={() => void runBusy(() => actions.onClearLink(), () => setClearLinkDialogOpen(false))}
|
||||
data-ui-id="ui.email.detail.clearLinkDialog.confirm"
|
||||
>
|
||||
{t("emailInbox.detail.clearLinkDialog.confirm")}
|
||||
</Button>
|
||||
</div>
|
||||
</Dialog.Content>
|
||||
</Dialog>
|
||||
|
||||
<Dialog open={importTarget !== null} onOpenChange={(open: boolean) => (open ? undefined : setImportTarget(null))}>
|
||||
<Dialog.Content
|
||||
className="w-[420px] max-w-[90vw] p-4"
|
||||
aria-label={t("emailInbox.detail.importDialog.title")}
|
||||
data-ui-id="ui.email.detail.importDialog"
|
||||
>
|
||||
<div className="flex w-full flex-col items-start gap-2">
|
||||
<span className="text-heading-0 font-heading-0 text-text-neutral-primary">{t("emailInbox.detail.importDialog.title")}</span>
|
||||
<span className="text-body-default-regular-150 font-body-default-regular-150 text-text-neutral-secondary">
|
||||
{t("emailInbox.detail.importDialog.body", {
|
||||
filename: importTarget?.filename ?? "",
|
||||
size: importTarget ? attachmentSizeLabel(importTarget.sizeBytes) : "",
|
||||
})}
|
||||
</span>
|
||||
</div>
|
||||
<div className="flex w-full items-center justify-end gap-2 pt-4">
|
||||
<Button variant="tertiary" disabled={busy} onClick={() => setImportTarget(null)}>
|
||||
{t("emailInbox.detail.importDialog.cancel")}
|
||||
</Button>
|
||||
<Button
|
||||
variant="primary"
|
||||
loading={busy}
|
||||
onClick={() => {
|
||||
const target = importTarget;
|
||||
if (!target) return;
|
||||
void runBusy(() => actions.onImportAttachment(target.attachmentId), () => setImportTarget(null));
|
||||
}}
|
||||
data-ui-id="ui.email.detail.importDialog.confirm"
|
||||
>
|
||||
{t("emailInbox.detail.importDialog.confirm")}
|
||||
</Button>
|
||||
</div>
|
||||
</Dialog.Content>
|
||||
</Dialog>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
|
||||
|
||||
exports[`AK-UI-03 email compose interim visual baseline > renders the interim blank, reply, and no-mailbox states from ~/ui 1`] = `"<main data-ui-id="ui.email.compose.interim.visualBaseline"><div class="bg-surface-neutral-primary flex w-full flex-col items-start" data-ui-id="ui.email.compose"><div class="border-border-default bg-surface-neutral-secondary mobile:flex-col mobile:px-4 flex w-full items-start justify-between gap-4 border-b border-solid px-6 py-6"><div class="flex flex-col items-start gap-1"><button class="group/3b777358 flex cursor-pointer items-center justify-center rounded-md text-left focus-within:shadow-focus disabled:cursor-default disabled:bg-surface-neutral-disabled disabled:pointer-events-none hover:disabled:cursor-default hover:disabled:bg-surface-neutral-disabled active:disabled:cursor-default active:disabled:bg-surface-neutral-disabled h-8 gap-2 px-3 py-2 border border-solid border-border-default bg-surface-neutral-primary hover:border hover:border-solid hover:border-border-strong hover:bg-surface-neutral-secondary active:bg-surface-neutral-tertiary" type="button" data-ui-id="ui.email.compose.back"><span class="text-body-default-regular-0 font-body-default-regular-0 group-disabled/3b777358:text-icon-neutral-disabled text-icon-neutral-on-subtle icon-wrapper-module_root__-l6uP"><span class="icon-wrapper-module_root__-l6uP"><svg data-visual-icon="true"></svg></span></span><div class="hidden h-4 w-4 flex-none items-center justify-center gap-2"><div class="text-body-extra-small-regular-150 font-body-extra-small-regular-150 group-disabled/3b777358:text-icon-neutral-disabled group-hover/3b777358:group-disabled/3b777358:text-icon-neutral-on-solid group-active/3b777358:group-disabled/3b777358:text-icon-neutral-disabled text-icon-neutral-on-subtle loader-module_root__-0Kak"></div></div><span class="whitespace-nowrap text-body-default-regular-0 font-body-default-regular-0 group-disabled/3b777358:text-text-neutral-disabled text-text-neutral-primary">emailInbox.compose.back</span></button><h1 class="text-heading- font-heading- text-text-neutral-primary">emailInbox.compose.title</h1></div></div><div class="mobile:px-4 flex w-full flex-col items-start gap-4 px-6 py-6"><div class="group/56067c50 flex flex-col items-start gap-4 rounded-md border border-solid border-border-default bg-surface-neutral-secondary px-4 py-4 shadow-sm w-full"><div class="flex w-full max-w-[768px] flex-col items-start gap-4"><div class="group/bb88f90b flex min-w-[192px] max-w-[320px] cursor-pointer flex-col items-start gap-4 w-full" data-ui-id="ui.email.compose.mailbox"><div class="hidden flex-col items-start gap-3"><span class="text-body-default-medium-0 font-body-default-medium-0 text-text-neutral-secondary">emailInbox.compose.mailbox</span></div><div class="flex w-full flex-col items-start gap-4 rounded-[4px]"><div class="flex w-full flex-col items-start rounded-sm border border-solid border-border-strong bg-surface-neutral-primary group-hover/bb88f90b:border group-hover/bb88f90b:border-solid group-hover/bb88f90b:border-brand-brand-border-solid-hover group-hover/bb88f90b:bg-surface-neutral-secondary group-focus-within/bb88f90b:bg-surface-neutral-secondary group-focus-within/bb88f90b:shadow-focus"><button class="select-module_trigger__L7Z7z group/7ce1d396 flex h-9 w-full min-w-0 items-center justify-between gap-2 overflow-hidden px-3 py-3 text-left" type="button" role="combobox" aria-controls="radix-_r_0_" aria-expanded="false" aria-autocomplete="none" dir="ltr" data-state="closed" aria-label="emailInbox.compose.mailbox"><span class="group/21c51472 min-w-0 truncate whitespace-nowrap text-body-default-regular-0 font-body-default-regular-0 text-text-neutral-subtle select-module_value__4AkUy"><span style="pointer-events: none;"><span class="group/c3085a74 text-body-default-regular-0 font-body-default-regular-0 text-text-neutral-tertiary h-auto grow shrink-0 basis-0">info@handwerk.test</span></span></span><span class="flex-none text-body-default-medium-0 font-body-default-medium-0 text-icon-neutral-tertiary icon-wrapper-module_root__-l6uP"><svg data-visual-icon="true"></svg></span></button></div></div></div><label class="group/be48ca43 flex h-full min-w-[192px] max-w-[320px] cursor-pointer flex-col items-start justify-center gap-4 w-full"><div class="hidden flex-col items-start gap-3"><span class="text-body-default-medium-0 font-body-default-medium-0 text-text-neutral-secondary">emailInbox.compose.to</span></div><div class="flex h-9 w-full min-w-[80px] flex-none items-center gap-2 rounded-sm border border-solid border-border-strong bg-surface-neutral-primary px-3 group-hover/be48ca43:border group-hover/be48ca43:border-solid group-hover/be48ca43:border-brand-brand-border-solid-hover group-hover/be48ca43:bg-surface-neutral-secondary group-focus-within/be48ca43:bg-surface-neutral-secondary group-focus-within/be48ca43:shadow-focus"><div class="flex grow shrink-0 basis-0 items-center self-stretch"><div class="hidden items-center gLine truncated
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
|
||||
|
||||
exports[`AK-UI-02 email detail interim visual baseline > renders the interim thread and read-only states from ~/ui 1`] = `"<main data-ui-id="ui.email.detail.interim.visualBaseline"><div class="bg-surface-neutral-primary flex w-full flex-col items-start" data-ui-id="ui.email.detail"><div class="border-border-default bg-surface-neutral-secondary mobile:flex-col mobile:px-4 flex w-full items-start justify-between gap-4 border-b border-solid px-6 py-6"><div class="flex min-w-0 flex-col items-start gap-1"><button class="group/3b777358 flex cursor-pointer items-center justify-center rounded-md text-left focus-within:shadow-focus disabled:cursor-default disabled:bg-surface-neutral-disabled disabled:pointer-events-none hover:disabled:cursor-default hover:disabled:bg-surface-neutral-disabled active:disabled:cursor-default active:disabled:bg-surface-neutral-disabled h-8 gap-2 px-3 py-2 border border-solid border-border-default bg-surface-neutral-primary hover:border hover:border-solid hover:border-border-strong hover:bg-surface-neutral-secondary active:bg-surface-neutral-tertiary" type="button" data-ui-id="ui.email.detail.back"><span class="text-body-default-regular-0 font-body-default-regular-0 group-disabled/3b777358:text-icon-neutral-disabled text-icon-neutral-on-subtle icon-wrapper-module_root__-l6uP"><span class="icon-wrapper-module_root__-l6uP"><svg data-visual-icon="true"></svg></span></span><div class="hidden h-4 w-4 flex-none items-center justify-center gap-2"><div class="text-body-extra-small-regular-150 font-body-extra-small-regular-150 group-disabled/3b777358:text-icon-neutral-disabled group-hover/3b777358:group-disabled/3b777358:text-icon-neutral-on-solid group-active/3b777358:group-disabled/3b777358:text-icon-neutral-disabled text-icon-neutral-on-subtle loader-module_root__-0Kak"></div></div><span class="whitespace-nowrap text-body-default-regular-0 font-body-default-regular-0 group-disabled/3b777358:text-text-neutral-disabled text-text-neutral-primary">emailInbox.detail.back</span></button><h1 class="text-heading- font-heading- text-text-neutral-primary">Re: Angebot für Projekt Nordlicht</h1><span class="text-body-default-regular-150 font-body-default-regular-150 text-text-neutral-tertiary">info@handwerk.test</span></div><div class="flex flex-none flex-wrap items-center gap-2"><button class="group/3b777358 flex h-9 cursor-pointer items-center justify-center gap-3 rounded-md border-none bg-brand-brand-surface-solid-default px-4 py-2.5 text-left hover:bg-brand-brand-surface-solid-hover active:bg-brand-brand-surface-solid-active focus-within:shadow-focus disabled:cursor-default disabled:bg-surface-neutral-disabled disabled:pointer-events-none hover:disabled:cursor-default hover:disabled:bg-surface-neutral-disabled active:disabled:cursor-default active:disabled:bg-surface-neutral-disabled" type="button" data-ui-id="ui.email.detail.reply"><span class="text-body-default-regular-0 font-body-default-regular-0 text-icon-neutral-on-solid group-disabled/3b777358:text-icon-neutral-disabled icon-wrapper-module_root__-l6uP"><span class="icon-wrapper-module_root__-l6uP"><svg data-visual-icon="true"></svg></span></span><div class="hidden h-4 w-4 flex-none items-center justify-center gap-2"><div class="text-body-extra-small-regular-150 font-body-extra-small-regular-150 text-icon-neutral-on-solid group-disabled/3b777358:text-icon-neutral-disabled group-hover/3b777358:group-disabled/3b777358:text-icon-neutral-on-solid group-active/3b777358:group-disabled/3b777358:text-icon-neutral-disabled loader-module_root__-0Kak"></div></div><span class="whitespace-nowrap text-body-default-regular-0 font-body-default-regular-0 text-text-neutral-on-solid group-disabled/3b777358:text-text-neutral-disabled">emailInbox.detail.reply</span></button><button class="group/3b777358 flex h-9 cursor-pointer items-center justify-center gap-3 rounded-md border-none px-4 py-2.5 text-left focus-within:shadow-focus disabled:cursor-default disabled:bg-surface-neutral-disabled disabled:pointer-events-none hover:disabled:cursor-default hover:disabled:bg-surface-neutral-disabled active:disabled:cursor-default active:disabled:bg-surface-neutral-disabled bg-brand-brand-secondary-surface-subtle-default hover:bg-brand-brand-secondary-surface-subtle-hover active:bg-brand-brand-secondary-surface-subtle-active" type="button" data-ui-id="ui.email.detail.forward"><span class="text-body-default-regular-0 font-body-default-regular-0 group-disabled/3b777358:text-icon-neutral-disabled text-icon-neutral-primary icon-wrapper-module_root__-l6uP"><span class="icon-wrapper-module_root__-l6uP"><svg data-visual-icon="true"></svg></span></span><div class="hidden h-4 w-4 flex-none items-center justify-center gap-2"><div class="text-body-extra-small-regular-150 font-body-extra-small-regular-150 group-disabled/3b777358:text-icon-neutral-disabled group-hover/3b777358:group-disabled/3b777358:text-icon-neutral-on-solid group-active/3b777358:group-disabled/3b777358:text-icon-neutrLine truncated
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
|
||||
|
||||
exports[`AK-UI-01 email inbox interim visual baseline > renders the interim list, empty, and no-mailbox states from ~/ui 1`] = `"<main data-ui-id="ui.email.inbox.interim.visualBaseline"><div class="bg-surface-neutral-primary flex w-full flex-col items-start" data-ui-id="ui.email.inbox"><div class="flex w-full items-start gap-4 border-b border-solid border-border-default bg-surface-neutral-secondary px-6 py-5 mobile:flex-col mobile:px-4"><div class="flex grow shrink-0 basis-0 flex-col items-start gap-1"><div class="flex items-center gap-2"><span class="text-heading- font-heading- text-icon-neutral-tertiary icon-wrapper-module_root__-l6uP"><svg data-visual-icon="true"></svg></span><h1 class="text-subtitle font-subtitle text-text-neutral-primary mobile:text-heading- mobile:font-heading-">emailInbox.list.title</h1></div><p class="text-body-small-regular-150 font-body-small-regular-150 text-text-neutral-tertiary">emailInbox.list.subtitle</p></div><div class="flex items-center gap-2 mobile:w-full mobile:flex-none mobile:flex-wrap"><button class="group/3b777358 flex h-9 cursor-pointer items-center justify-center gap-3 rounded-md border-none bg-brand-brand-surface-solid-default px-4 py-2.5 text-left hover:bg-brand-brand-surface-solid-hover active:bg-brand-brand-surface-solid-active focus-within:shadow-focus disabled:cursor-default disabled:bg-surface-neutral-disabled disabled:pointer-events-none hover:disabled:cursor-default hover:disabled:bg-surface-neutral-disabled active:disabled:cursor-default active:disabled:bg-surface-neutral-disabled" type="button" data-ui-id="ui.email.inbox.compose"><span class="text-body-default-regular-0 font-body-default-regular-0 text-icon-neutral-on-solid group-disabled/3b777358:text-icon-neutral-disabled icon-wrapper-module_root__-l6uP"><span class="icon-wrapper-module_root__-l6uP"><svg data-visual-icon="true"></svg></span></span><div class="hidden h-4 w-4 flex-none items-center justify-center gap-2"><div class="text-body-extra-small-regular-150 font-body-extra-small-regular-150 text-icon-neutral-on-solid group-disabled/3b777358:text-icon-neutral-disabled group-hover/3b777358:group-disabled/3b777358:text-icon-neutral-on-solid group-active/3b777358:group-disabled/3b777358:text-icon-neutral-disabled loader-module_root__-0Kak"></div></div><span class="whitespace-nowrap text-body-default-regular-0 font-body-default-regular-0 text-text-neutral-on-solid group-disabled/3b777358:text-text-neutral-disabled">emailInbox.list.compose</span></button></div></div><div class="mobile:px-4 flex w-full flex-col items-start gap-4 px-6 py-6"><div class="mobile:flex-col mobile:items-stretch flex w-full flex-wrap items-center gap-2" data-ui-id="ui.email.inbox.filters"><div class="group/75a35ed3 flex cursor-pointer flex-col items-start justify-center gap-4 w-64 max-w-[256px]" data-ui-id="ui.email.inbox.search"><div class="hidden flex-col items-start gap-3"></div><label class="flex h-9 w-full min-w-[288px] max-w-[320px] flex-none cursor-text items-center gap-2.5 rounded-sm border border-solid border-border-strong bg-surface-neutral-primary px-3 group-hover/75a35ed3:bg-surface-neutral-secondary group-focus-within/75a35ed3:bg-surface-neutral-secondary group-focus-within/75a35ed3:shadow-focus"><span class="text-body-default-regular-0 font-body-default-regular-0 text-icon-neutral-tertiary icon-wrapper-module_root__-l6uP"><svg data-visual-icon="true"></svg></span><input class="grow shrink-0 basis-0 self-stretch border-0 bg-transparent text-body-default-regular-0 font-body-default-regular-0 text-text-neutral-secondary outline-none placeholder:text-text-neutral-subtle" style="box-shadow: none;" placeholder="emailInbox.list.searchPlaceholder" type="search" value=""><div class="items-center gap-1 rounded-sm group-focus-within/75a35ed3:hidden hidden"><div class="group/97bdb082 flex min-h-[20px] items-center justify-center rounded-sm border border-solid border-surface-feedback-subtle-neutral bg-surface-feedback-subtle-neutral px-1 py-0.5"><span class="whitespace-nowrap text-body-small-regular-0 font-body-small-regular-0 text-text-neutral-on-subtle">Strg K</span></div></div><span class="hidden text-body-default-regular-0 font-body-default-regular-0 text-icon-neutral-tertiary animate-spin icon-wrapper-module_root__-l6uP"><svg data-visual-icon="true"></svg></span><div class="hidden h-5 w-5 flex-none items-center justify-center rounded-round cursor-pointer hover:bg-surface-neutral-tertiary"><span class="text-body-default-regular-0 font-body-default-regular-0 text-icon-neutral-tertiary icon-wrapper-module_root__-l6uP"><svg data-visual-icon="true"></svg></span></div></label></div><div class="group/bb88f90b flex max-w-[320px] cursor-pointer flex-col items-start gap-4 w-56 min-w-[160px]" data-ui-id="ui.email.inbox.filter.mailbox"><div class="hidden flex-col items-start gap-3"></div><div class="flex w-full flex-col items-start gap-4 rounded-[4px]"><div class="flex w-full flex-col items-start rounded-sm border border-solid bordeLine truncated
|
||||
+62
@@ -0,0 +1,62 @@
|
||||
import { buildComposePrefill, buildEmailComposeVM, type EmailComposeVM } from "@hivegrid/view-models";
|
||||
|
||||
import { EmailComposePage } from "./EmailComposePage";
|
||||
|
||||
export const EMAIL_COMPOSE_INTERIM_VISUAL_SCREENS = ["blank", "reply", "no-mailbox"] as const;
|
||||
|
||||
export type EmailComposeInterimVisualScreen = (typeof EMAIL_COMPOSE_INTERIM_VISUAL_SCREENS)[number];
|
||||
|
||||
const MAILBOXES = [
|
||||
{ id: "mailbox-1", emailAddress: "info@handwerk.test", provider: "gmail" as const, isDefaultForUser: true },
|
||||
{ id: "mailbox-2", emailAddress: "office@handwerk.test", provider: "microsoft" as const, isDefaultForUser: false },
|
||||
];
|
||||
|
||||
const TEMPLATES = [
|
||||
{ id: "tpl-1", name: "Angebot Nachfassen", subject: "Ihr Angebot", htmlBody: "<p>Guten Tag, haben Sie unser Angebot erhalten?</p>" },
|
||||
];
|
||||
|
||||
/** The original stays far in the past so the quoted block (which carries the
|
||||
* ISO timestamp) never depends on the test run date. */
|
||||
const ORIGINAL = {
|
||||
id: "msg-1",
|
||||
direction: "inbound" as const,
|
||||
fromAddress: "erika@example.test",
|
||||
fromName: "Erika Beispiel",
|
||||
toSummary: "info@handwerk.test",
|
||||
subject: "Angebot für Projekt Nordlicht",
|
||||
sentAtIso: "2020-01-03T09:30:00.000Z",
|
||||
safeBodyHtml: "<p>Vielen Dank, wir prüfen das Angebot.</p>",
|
||||
};
|
||||
|
||||
export function createEmailComposeInterimVisualVMs(): Record<EmailComposeInterimVisualScreen, EmailComposeVM> {
|
||||
const base = {
|
||||
mailboxes: MAILBOXES,
|
||||
defaultMailboxId: "mailbox-1",
|
||||
templates: TEMPLATES,
|
||||
backHref: "/acme/emails",
|
||||
};
|
||||
|
||||
return {
|
||||
blank: buildEmailComposeVM({ ...base, prefill: buildComposePrefill({ mode: "blank", original: null }) }),
|
||||
reply: buildEmailComposeVM({
|
||||
...base,
|
||||
backHref: "/acme/emails/msg-1",
|
||||
prefill: buildComposePrefill({ mode: "reply", original: ORIGINAL }),
|
||||
}),
|
||||
"no-mailbox": buildEmailComposeVM({
|
||||
...base,
|
||||
mailboxes: [],
|
||||
defaultMailboxId: null,
|
||||
templates: [],
|
||||
prefill: buildComposePrefill({ mode: "blank", original: null }),
|
||||
}),
|
||||
};
|
||||
}
|
||||
|
||||
const noOp = (): void => undefined;
|
||||
|
||||
/** Shared ready-state fixture for the AK-UI-03 interim markup baseline. */
|
||||
export function EmailComposeInterimVisualFixture({ screen }: { screen: EmailComposeInterimVisualScreen }): React.JSX.Element {
|
||||
const vms = createEmailComposeInterimVisualVMs();
|
||||
return <EmailComposePage vm={vms[screen]} actions={{ onSend: noOp, onBack: noOp, onOpenSettings: noOp }} />;
|
||||
}
|
||||
+105
@@ -0,0 +1,105 @@
|
||||
// @vitest-environment jsdom
|
||||
import "@testing-library/jest-dom/vitest";
|
||||
import React from "react";
|
||||
import { MemoryRouter } from "react-router";
|
||||
import { fireEvent, render } from "@testing-library/react";
|
||||
import { describe, expect, it, vi } from "vitest";
|
||||
|
||||
import { buildComposePrefill, buildEmailComposeVM } from "@hivegrid/view-models";
|
||||
import { EmailComposePage } from "./EmailComposePage";
|
||||
import { EMAIL_COMPOSE_INTERIM_VISUAL_SCREENS, EmailComposeInterimVisualFixture } from "./email-compose-interim.visual-fixture";
|
||||
|
||||
vi.mock("react-i18next", () => ({
|
||||
useTranslation: () => ({
|
||||
t: (key: string, values?: Record<string, unknown>) => (values ? `${key}:${Object.values(values).join("/")}` : key),
|
||||
i18n: { language: "de" },
|
||||
}),
|
||||
}));
|
||||
|
||||
describe("AK-UI-03 email compose interim visual baseline", () => {
|
||||
it("renders the interim blank, reply, and no-mailbox states from ~/ui", () => {
|
||||
const { container } = render(
|
||||
<MemoryRouter>
|
||||
<main data-ui-id="ui.email.compose.interim.visualBaseline">
|
||||
{EMAIL_COMPOSE_INTERIM_VISUAL_SCREENS.map((screen) => (
|
||||
<EmailComposeInterimVisualFixture key={screen} screen={screen} />
|
||||
))}
|
||||
</main>
|
||||
</MemoryRouter>
|
||||
);
|
||||
|
||||
expect(container.querySelectorAll("[data-ui-id='ui.email.compose']")).toHaveLength(3);
|
||||
// blank + reply render the form; no-mailbox renders the connect state instead.
|
||||
expect(container.querySelectorAll("[data-ui-id='ui.email.compose.send']")).toHaveLength(2);
|
||||
expect(container.querySelectorAll("[data-ui-id='ui.email.compose.bcc']")).toHaveLength(2);
|
||||
expect(container.querySelectorAll("[data-ui-id='ui.email.compose.noMailbox']")).toHaveLength(1);
|
||||
expect(container.querySelectorAll("[data-ui-id='ui.email.compose.connect']")).toHaveLength(1);
|
||||
|
||||
const stableMarkup = container.innerHTML.replace(/<svg\b[^>]*>[\s\S]*?<\/svg>/gu, '<svg data-visual-icon="true"></svg>');
|
||||
expect(stableMarkup).toMatchSnapshot();
|
||||
});
|
||||
|
||||
it("blocks sending until the recipient field parses to at least one address", () => {
|
||||
const { container } = render(
|
||||
<MemoryRouter>
|
||||
<EmailComposeInterimVisualFixture screen="blank" />
|
||||
</MemoryRouter>
|
||||
);
|
||||
|
||||
const send = container.querySelector("[data-ui-id='ui.email.compose.send']");
|
||||
expect(send).toBeDisabled();
|
||||
|
||||
const to = container.querySelector("[data-ui-id='ui.email.compose.to']") as HTMLInputElement;
|
||||
fireEvent.change(to, { target: { value: "kein-at-zeichen" } });
|
||||
expect(send).toBeDisabled();
|
||||
|
||||
fireEvent.change(to, { target: { value: "erika@example.test" } });
|
||||
expect(send).toBeEnabled();
|
||||
});
|
||||
|
||||
it("prefills the reply recipient and hands the quoted original back on send", () => {
|
||||
const onSend = vi.fn();
|
||||
const vm = buildEmailComposeVM({
|
||||
mailboxes: [{ id: "mailbox-1", emailAddress: "info@handwerk.test", provider: "gmail", isDefaultForUser: true }],
|
||||
defaultMailboxId: "mailbox-1",
|
||||
templates: [],
|
||||
backHref: "/acme/emails/msg-1",
|
||||
prefill: buildComposePrefill({
|
||||
mode: "reply",
|
||||
original: {
|
||||
id: "msg-1",
|
||||
direction: "inbound",
|
||||
fromAddress: "erika@example.test",
|
||||
fromName: "Erika Beispiel",
|
||||
toSummary: "info@handwerk.test",
|
||||
subject: "Angebot",
|
||||
sentAtIso: "2020-01-03T09:30:00.000Z",
|
||||
safeBodyHtml: "<p>Danke</p>",
|
||||
},
|
||||
}),
|
||||
});
|
||||
|
||||
const { container } = render(
|
||||
<MemoryRouter>
|
||||
<EmailComposePage vm={vm} actions={{ onSend, onBack: () => undefined, onOpenSettings: () => undefined }} />
|
||||
</MemoryRouter>
|
||||
);
|
||||
|
||||
const to = container.querySelector("[data-ui-id='ui.email.compose.to']") as HTMLInputElement;
|
||||
expect(to.value).toBe("erika@example.test");
|
||||
|
||||
fireEvent.change(container.querySelector("[data-ui-id='ui.email.compose.bcc']") as HTMLInputElement, {
|
||||
target: { value: "chef@handwerk.test" },
|
||||
});
|
||||
fireEvent.click(container.querySelector("[data-ui-id='ui.email.compose.send']") as HTMLButtonElement);
|
||||
|
||||
expect(onSend).toHaveBeenCalledTimes(1);
|
||||
const payload = onSend.mock.calls[0]?.[0] as Record<string, unknown>;
|
||||
expect(payload.to).toBe("erika@example.test");
|
||||
// bcc reached the action contract but had no field before AK-UI-03.
|
||||
expect(payload.bcc).toBe("chef@handwerk.test");
|
||||
expect(payload.replyToMessageId).toBe("msg-1");
|
||||
expect(String(payload.quotedHtml)).toContain("<blockquote");
|
||||
expect(payload.attachments).toEqual([]);
|
||||
});
|
||||
});
|
||||
+104
@@ -0,0 +1,104 @@
|
||||
import { buildEmailMessageDetailVM, emailMatchSourceKey, type EmailMessageDetailVM, type EmailThreadMessageVM } from "@hivegrid/view-models";
|
||||
|
||||
import { EmailMessageDetailPage } from "./EmailMessageDetailPage";
|
||||
|
||||
export const EMAIL_DETAIL_INTERIM_VISUAL_SCREENS = ["thread", "readonly"] as const;
|
||||
|
||||
export type EmailDetailInterimVisualScreen = (typeof EMAIL_DETAIL_INTERIM_VISUAL_SCREENS)[number];
|
||||
|
||||
/** sentAt values stay far in the past so the markup snapshot never depends on
|
||||
* the test run date (the screen renders absolute timestamps). */
|
||||
const THREAD: EmailThreadMessageVM[] = [
|
||||
{
|
||||
id: "msg-0",
|
||||
direction: "outbound",
|
||||
fromName: "Handwerk GmbH",
|
||||
fromAddress: "info@handwerk.test",
|
||||
toSummary: "erika@example.test",
|
||||
ccSummary: null,
|
||||
subject: "Angebot für Projekt Nordlicht",
|
||||
safeBodyHtml: "<p>Guten Tag, anbei unser Angebot.</p>",
|
||||
blockedImageCount: 0,
|
||||
sentAt: "2020-01-02T09:00:00.000Z",
|
||||
isRead: true,
|
||||
isFocused: false,
|
||||
collapsedByDefault: true,
|
||||
},
|
||||
{
|
||||
id: "msg-1",
|
||||
direction: "inbound",
|
||||
fromName: "Erika Beispiel",
|
||||
fromAddress: "erika@example.test",
|
||||
toSummary: "info@handwerk.test",
|
||||
ccSummary: "buchhaltung@example.test",
|
||||
subject: "Re: Angebot für Projekt Nordlicht",
|
||||
safeBodyHtml: "<p>Vielen Dank, wir prüfen das Angebot.</p>",
|
||||
blockedImageCount: 3,
|
||||
sentAt: "2020-01-03T09:30:00.000Z",
|
||||
isRead: false,
|
||||
isFocused: true,
|
||||
collapsedByDefault: false,
|
||||
},
|
||||
];
|
||||
|
||||
export function createEmailDetailInterimVisualVMs(): Record<EmailDetailInterimVisualScreen, EmailMessageDetailVM> {
|
||||
const base = {
|
||||
focusedId: "msg-1",
|
||||
subject: "Re: Angebot für Projekt Nordlicht",
|
||||
mailbox: { emailAddress: "info@handwerk.test", provider: "gmail" as const },
|
||||
thread: THREAD,
|
||||
replyHref: "/acme/emails/new?replyTo=msg-1",
|
||||
forwardHref: "/acme/emails/new?forward=msg-1",
|
||||
backHref: "/acme/emails",
|
||||
allowExternalImages: false,
|
||||
};
|
||||
|
||||
return {
|
||||
thread: buildEmailMessageDetailVM({
|
||||
...base,
|
||||
attachments: [
|
||||
{ attachmentId: "att-1", filename: "angebot-nordlicht.pdf", sizeBytes: 245_760, importedFileId: null, downloadHref: null },
|
||||
{ attachmentId: "att-2", filename: "aufmass.xlsx", sizeBytes: 18_432, importedFileId: "file-1", downloadHref: "/acme/files/file-1" },
|
||||
],
|
||||
match: {
|
||||
links: [
|
||||
{ type: "kontakt", id: "contact-1", href: "/acme/contacts/contact-1" },
|
||||
{ type: "projekt", id: "project-1", href: "/acme/projects/project-1" },
|
||||
],
|
||||
confidence: "manual",
|
||||
sourceKey: emailMatchSourceKey("manual"),
|
||||
isManual: true,
|
||||
},
|
||||
canWrite: true,
|
||||
}),
|
||||
readonly: buildEmailMessageDetailVM({
|
||||
...base,
|
||||
attachments: [],
|
||||
match: { links: [], confidence: "none", sourceKey: emailMatchSourceKey("none"), isManual: false },
|
||||
canWrite: false,
|
||||
}),
|
||||
};
|
||||
}
|
||||
|
||||
const noOp = (): void => undefined;
|
||||
|
||||
/** Shared ready-state fixture for the AK-UI-02 interim markup baseline. */
|
||||
export function EmailDetailInterimVisualFixture({ screen }: { screen: EmailDetailInterimVisualScreen }): React.JSX.Element {
|
||||
const vms = createEmailDetailInterimVisualVMs();
|
||||
return (
|
||||
<EmailMessageDetailPage
|
||||
vm={vms[screen]}
|
||||
justSent={screen === "thread"}
|
||||
actions={{
|
||||
onSetLink: noOp,
|
||||
onClearLink: noOp,
|
||||
onImportAttachment: noOp,
|
||||
onToggleRead: noOp,
|
||||
onLoadImages: noOp,
|
||||
onReply: noOp,
|
||||
onForward: noOp,
|
||||
onBack: noOp,
|
||||
}}
|
||||
/>
|
||||
);
|
||||
}
|
||||
+99
@@ -0,0 +1,99 @@
|
||||
// @vitest-environment jsdom
|
||||
import "@testing-library/jest-dom/vitest";
|
||||
import React from "react";
|
||||
import { MemoryRouter } from "react-router";
|
||||
import { fireEvent, render } from "@testing-library/react";
|
||||
import { describe, expect, it, vi } from "vitest";
|
||||
|
||||
import { EMAIL_DETAIL_INTERIM_VISUAL_SCREENS, EmailDetailInterimVisualFixture } from "./email-detail-interim.visual-fixture";
|
||||
|
||||
vi.mock("react-i18next", () => ({
|
||||
useTranslation: () => ({
|
||||
t: (key: string, values?: Record<string, unknown>) => (values ? `${key}:${Object.values(values).join("/")}` : key),
|
||||
i18n: { language: "de" },
|
||||
}),
|
||||
}));
|
||||
|
||||
vi.mock("~/locale/format", () => ({
|
||||
useLocaleFormatters: () => ({
|
||||
locale: "de",
|
||||
number: (value: number) => String(value),
|
||||
currency: (value: number, currency: string) => `${value.toFixed(2)} ${currency}`,
|
||||
currencyFromCents: (value: number, currency: string) => `${(value / 100).toFixed(2)} ${currency}`,
|
||||
percent: (value: number) => `${value}%`,
|
||||
compact: (value: number) => String(value),
|
||||
date: (value: Date | number | string) => new Date(value).toISOString(),
|
||||
dateTime: (value: Date | number | string) => new Date(value).toISOString(),
|
||||
relativeTime: (value: number, unit: string) => `${value} ${unit}`,
|
||||
relativeDate: (value: Date | number | string) => new Date(value).toISOString(),
|
||||
}),
|
||||
}));
|
||||
|
||||
describe("AK-UI-02 email detail interim visual baseline", () => {
|
||||
it("renders the interim thread and read-only states from ~/ui", () => {
|
||||
const { container } = render(
|
||||
<MemoryRouter>
|
||||
<main data-ui-id="ui.email.detail.interim.visualBaseline">
|
||||
{EMAIL_DETAIL_INTERIM_VISUAL_SCREENS.map((screen) => (
|
||||
<EmailDetailInterimVisualFixture key={screen} screen={screen} />
|
||||
))}
|
||||
</main>
|
||||
</MemoryRouter>
|
||||
);
|
||||
|
||||
expect(container.querySelectorAll("[data-ui-id='ui.email.detail']")).toHaveLength(2);
|
||||
expect(container.querySelectorAll("[data-ui-id='ui.email.detail.thread']")).toHaveLength(2);
|
||||
// The read-only screen hides every write affordance (canWrite === false).
|
||||
expect(container.querySelectorAll("[data-ui-id='ui.email.detail.reply']")).toHaveLength(1);
|
||||
expect(container.querySelectorAll("[data-ui-id='ui.email.detail.toggleRead']")).toHaveLength(1);
|
||||
expect(container.querySelectorAll("[data-ui-id='ui.email.detail.setLink']")).toHaveLength(1);
|
||||
expect(container.querySelectorAll("[data-ui-id='ui.email.detail.attachments']")).toHaveLength(1);
|
||||
expect(container.querySelectorAll("[data-ui-id='ui.email.detail.sent']")).toHaveLength(1);
|
||||
// Blocked external images stay behind the explicit opt-in.
|
||||
expect(container.querySelectorAll("[data-ui-id='ui.email.detail.blockedImages']")).toHaveLength(2);
|
||||
|
||||
const stableMarkup = container.innerHTML.replace(/<svg\b[^>]*>[\s\S]*?<\/svg>/gu, '<svg data-visual-icon="true"></svg>');
|
||||
expect(stableMarkup).toMatchSnapshot();
|
||||
});
|
||||
|
||||
it("opens the link assignment as a real ~/ui dialog with a lead field", async () => {
|
||||
const { findByText, container } = render(
|
||||
<MemoryRouter>
|
||||
<EmailDetailInterimVisualFixture screen="thread" />
|
||||
</MemoryRouter>
|
||||
);
|
||||
|
||||
const setLinkButton = container.querySelector("[data-ui-id='ui.email.detail.setLink']");
|
||||
expect(setLinkButton).not.toBeNull();
|
||||
fireEvent.click(setLinkButton as HTMLButtonElement);
|
||||
|
||||
expect(await findByText("emailInbox.detail.linkDialog.title")).toBeInTheDocument();
|
||||
const dialog = document.querySelector("[data-ui-id='ui.email.detail.linkDialog']");
|
||||
expect(dialog).not.toBeNull();
|
||||
// leadId was accepted by the action but had no field before AK-UI-02.
|
||||
expect(dialog?.querySelector("[data-ui-id='ui.email.detail.linkDialog.leadId']")).not.toBeNull();
|
||||
|
||||
// Confirm stays disabled until at least one id is entered.
|
||||
const confirm = dialog?.querySelector("[data-ui-id='ui.email.detail.linkDialog.confirm']");
|
||||
expect(confirm).toBeDisabled();
|
||||
fireEvent.change(dialog?.querySelector("[data-ui-id='ui.email.detail.linkDialog.leadId']") as HTMLInputElement, {
|
||||
target: { value: "lead-1" },
|
||||
});
|
||||
expect(confirm).toBeEnabled();
|
||||
});
|
||||
|
||||
it("confirms removing an assignment through a destructive dialog", async () => {
|
||||
const { findByText, container } = render(
|
||||
<MemoryRouter>
|
||||
<EmailDetailInterimVisualFixture screen="thread" />
|
||||
</MemoryRouter>
|
||||
);
|
||||
|
||||
const clearButton = container.querySelector("[data-ui-id='ui.email.detail.clearLink']");
|
||||
expect(clearButton).toBeEnabled();
|
||||
fireEvent.click(clearButton as HTMLButtonElement);
|
||||
|
||||
expect(await findByText("emailInbox.detail.clearLinkDialog.title")).toBeInTheDocument();
|
||||
expect(document.querySelector("[data-ui-id='ui.email.detail.clearLinkDialog']")).not.toBeNull();
|
||||
});
|
||||
});
|
||||
+103
@@ -0,0 +1,103 @@
|
||||
import { buildEmailInboxListVM, type EmailInboxFilters, type EmailInboxListVM } from "@hivegrid/view-models";
|
||||
|
||||
import { EmailInboxListPage } from "./EmailInboxListPage";
|
||||
|
||||
export const EMAIL_INBOX_INTERIM_VISUAL_SCREENS = ["list", "empty", "no-mailbox"] as const;
|
||||
|
||||
export type EmailInboxInterimVisualScreen = (typeof EMAIL_INBOX_INTERIM_VISUAL_SCREENS)[number];
|
||||
|
||||
const FIXTURE_FILTERS: EmailInboxFilters = {
|
||||
mailboxId: null,
|
||||
direction: "all",
|
||||
linked: "all",
|
||||
read: "all",
|
||||
q: "",
|
||||
showArchived: false,
|
||||
};
|
||||
|
||||
const FIXTURE_MAILBOXES = [
|
||||
{ id: "mailbox-1", emailAddress: "sales@example.test" },
|
||||
{ id: "mailbox-2", emailAddress: "office@example.test" },
|
||||
];
|
||||
|
||||
/** sentAt values stay far in the past so the list renders absolute dates —
|
||||
* keeps the markup snapshot independent of the test run date. */
|
||||
export function createEmailInboxInterimVisualVMs(): Record<EmailInboxInterimVisualScreen, EmailInboxListVM> {
|
||||
const base = {
|
||||
filters: FIXTURE_FILTERS,
|
||||
mailboxOptions: FIXTURE_MAILBOXES,
|
||||
canWrite: true,
|
||||
composeHref: "/acme/emails/new",
|
||||
settingsHref: "/acme/settings/integrations/email",
|
||||
};
|
||||
|
||||
return {
|
||||
list: buildEmailInboxListVM({
|
||||
...base,
|
||||
hasAnyMailbox: true,
|
||||
nextCursor: "2020-01-02T10:00:00.000Z~msg-2",
|
||||
rows: [
|
||||
{
|
||||
id: "msg-1",
|
||||
detailHref: "/acme/emails/msg-1",
|
||||
fromName: "Erika Beispiel",
|
||||
fromAddress: "erika@example.test",
|
||||
subject: "Angebot für Projekt Nordlicht",
|
||||
snippet: "Hallo, anbei das aktualisierte Angebot mit den besprochenen Positionen …",
|
||||
sentAt: "2020-01-03T09:30:00.000Z",
|
||||
direction: "inbound",
|
||||
isRead: false,
|
||||
hasAttachments: true,
|
||||
isNewsletter: false,
|
||||
mailbox: { id: "mailbox-1", emailAddress: "sales@example.test", provider: "gmail" },
|
||||
links: [
|
||||
{ type: "kontakt", id: "contact-1", href: "/acme/contacts/contact-1" },
|
||||
{ type: "projekt", id: "project-1", href: "/acme/projects/project-1" },
|
||||
],
|
||||
},
|
||||
{
|
||||
id: "msg-2",
|
||||
detailHref: "/acme/emails/msg-2",
|
||||
fromName: null,
|
||||
fromAddress: "newsletter@example.test",
|
||||
subject: null,
|
||||
snippet: null,
|
||||
sentAt: "2020-01-02T10:00:00.000Z",
|
||||
direction: "inbound",
|
||||
isRead: true,
|
||||
hasAttachments: false,
|
||||
isNewsletter: true,
|
||||
mailbox: { id: "mailbox-2", emailAddress: "office@example.test", provider: "microsoft" },
|
||||
links: [{ type: "lead", id: "lead-1", href: "/acme/leads/lead-1" }],
|
||||
},
|
||||
],
|
||||
}),
|
||||
empty: buildEmailInboxListVM({
|
||||
...base,
|
||||
hasAnyMailbox: true,
|
||||
nextCursor: null,
|
||||
rows: [],
|
||||
}),
|
||||
"no-mailbox": buildEmailInboxListVM({
|
||||
...base,
|
||||
mailboxOptions: [],
|
||||
hasAnyMailbox: false,
|
||||
nextCursor: null,
|
||||
rows: [],
|
||||
canWrite: false,
|
||||
}),
|
||||
};
|
||||
}
|
||||
|
||||
const noOp = (): void => undefined;
|
||||
|
||||
/** Shared ready-state fixture for the AK-UI-01 interim markup baseline. */
|
||||
export function EmailInboxInterimVisualFixture({ screen }: { screen: EmailInboxInterimVisualScreen }): React.JSX.Element {
|
||||
const vms = createEmailInboxInterimVisualVMs();
|
||||
return (
|
||||
<EmailInboxListPage
|
||||
vm={vms[screen]}
|
||||
actions={{ onApplyFilters: noOp, onBulk: noOp, onLoadMore: noOp, onCompose: noOp, onOpenSettings: noOp }}
|
||||
/>
|
||||
);
|
||||
}
|
||||
+71
@@ -0,0 +1,71 @@
|
||||
// @vitest-environment jsdom
|
||||
import "@testing-library/jest-dom/vitest";
|
||||
import React from "react";
|
||||
import { MemoryRouter } from "react-router";
|
||||
import { fireEvent, render } from "@testing-library/react";
|
||||
import { describe, expect, it, vi } from "vitest";
|
||||
|
||||
import { EMAIL_INBOX_INTERIM_VISUAL_SCREENS, EmailInboxInterimVisualFixture } from "./email-inbox-interim.visual-fixture";
|
||||
|
||||
vi.mock("react-i18next", () => ({
|
||||
useTranslation: () => ({
|
||||
t: (key: string, values?: Record<string, unknown>) => (values ? `${key}:${Object.values(values).join("/")}` : key),
|
||||
i18n: { language: "de" },
|
||||
}),
|
||||
}));
|
||||
|
||||
vi.mock("~/locale/format", () => ({
|
||||
useLocaleFormatters: () => ({
|
||||
locale: "de",
|
||||
number: (value: number) => String(value),
|
||||
currency: (value: number, currency: string) => `${value.toFixed(2)} ${currency}`,
|
||||
currencyFromCents: (value: number, currency: string) => `${(value / 100).toFixed(2)} ${currency}`,
|
||||
percent: (value: number) => `${value}%`,
|
||||
compact: (value: number) => String(value),
|
||||
date: (value: Date | number | string) => new Date(value).toISOString(),
|
||||
dateTime: (value: Date | number | string) => new Date(value).toISOString(),
|
||||
relativeTime: (value: number, unit: string) => `${value} ${unit}`,
|
||||
relativeDate: (value: Date | number | string) => new Date(value).toISOString(),
|
||||
}),
|
||||
}));
|
||||
|
||||
describe("AK-UI-01 email inbox interim visual baseline", () => {
|
||||
it("renders the interim list, empty, and no-mailbox states from ~/ui", () => {
|
||||
const { container } = render(
|
||||
<MemoryRouter>
|
||||
<main data-ui-id="ui.email.inbox.interim.visualBaseline">
|
||||
{EMAIL_INBOX_INTERIM_VISUAL_SCREENS.map((screen) => (
|
||||
<EmailInboxInterimVisualFixture key={screen} screen={screen} />
|
||||
))}
|
||||
</main>
|
||||
</MemoryRouter>
|
||||
);
|
||||
|
||||
expect(container.querySelectorAll("[data-ui-id='ui.email.inbox']")).toHaveLength(3);
|
||||
expect(container.querySelectorAll("[data-ui-id='ui.email.inbox.list']")).toHaveLength(1);
|
||||
expect(container.querySelectorAll("[data-ui-id='ui.email.inbox.empty']")).toHaveLength(1);
|
||||
expect(container.querySelectorAll("[data-ui-id='ui.email.inbox.noMailbox']")).toHaveLength(1);
|
||||
const stableMarkup = container.innerHTML.replace(/<svg\b[^>]*>[\s\S]*?<\/svg>/gu, '<svg data-visual-icon="true"></svg>');
|
||||
expect(stableMarkup).toMatchSnapshot();
|
||||
});
|
||||
|
||||
it("opens the archive confirmation as a real ~/ui dialog", async () => {
|
||||
const { findByText, container } = render(
|
||||
<MemoryRouter>
|
||||
<EmailInboxInterimVisualFixture screen="list" />
|
||||
</MemoryRouter>
|
||||
);
|
||||
|
||||
const firstRowCheckbox = container.querySelector("tbody [aria-label='emailInbox.list.selectRow']");
|
||||
expect(firstRowCheckbox).not.toBeNull();
|
||||
fireEvent.click(firstRowCheckbox as HTMLButtonElement);
|
||||
|
||||
const archiveButton = container.querySelector("[data-ui-id='ui.email.inbox.bulk.archive']");
|
||||
expect(archiveButton).not.toBeNull();
|
||||
expect(archiveButton).toBeEnabled();
|
||||
fireEvent.click(archiveButton as HTMLButtonElement);
|
||||
|
||||
expect(await findByText("emailInbox.list.archiveDialog.title")).toBeInTheDocument();
|
||||
expect(document.querySelector("[data-ui-id='ui.email.inbox.archiveDialog']")).not.toBeNull();
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user