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
+54
-161
@@ -4,8 +4,7 @@
|
||||
// archive (read state is mirrored back to the provider best-effort). Module
|
||||
// off -> locked empty; missing email.read_own -> 404 (A.5.3).
|
||||
|
||||
import { type ActionFunctionArgs, type LoaderFunctionArgs, useLoaderData, useSearchParams, Form, Link, useSubmit } from "react-router";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { type ActionFunctionArgs, type LoaderFunctionArgs, useActionData, useLoaderData, useNavigate, useSearchParams, useSubmit } from "react-router";
|
||||
import {
|
||||
buildEmailInboxListVM,
|
||||
decodeInboxCursor,
|
||||
@@ -18,6 +17,11 @@ import {
|
||||
import { getTranslations } from "~/locale/i18next.server";
|
||||
import { validateCSRFToken } from "~/utils/session.server";
|
||||
import { useRootData } from "~/utils/data/useRootData";
|
||||
import {
|
||||
EmailInboxListPage,
|
||||
type EmailInboxAppliedFilters,
|
||||
type EmailInboxBulkIntent,
|
||||
} from "~/components/screens/email-inbox/EmailInboxListPage";
|
||||
import {
|
||||
canReadAllMailboxes,
|
||||
canWriteEmail,
|
||||
@@ -25,7 +29,7 @@ import {
|
||||
requireEmailRead,
|
||||
requireEmailWrite,
|
||||
} from "~/modules/emailInbox/routes/emailInboxAccess.server";
|
||||
import { EMAIL_INBOX_MODULE_KEY, emailComposePath, emailInboxPath, emailMessagePath, emailSettingsPath, notFoundResponse } from "~/modules/emailInbox/routes/emailInboxRoutePaths";
|
||||
import { EMAIL_INBOX_MODULE_KEY, emailComposePath, emailMessagePath, emailSettingsPath, notFoundResponse } from "~/modules/emailInbox/routes/emailInboxRoutePaths";
|
||||
import {
|
||||
bulkUpdateMessages,
|
||||
getProviderMessageRefs,
|
||||
@@ -35,6 +39,7 @@ import {
|
||||
} from "~/modules/emailInbox/db/emailInbox.db.server";
|
||||
import { adapterForProvider, ensureFreshMailboxCreds, loadMailboxCreds } from "~/modules/emailInbox/services/MailboxConnectionService.server";
|
||||
import ServerError from "~/components/ui/errors/ServerError";
|
||||
import { useSaveToast } from "~/hooks/use-save-toast";
|
||||
|
||||
const PAGE_SIZE = 50;
|
||||
|
||||
@@ -138,7 +143,7 @@ export const action = async ({ request, params }: ActionFunctionArgs) => {
|
||||
const intent = String(form.get("intent") ?? "");
|
||||
const messageIds = form.getAll("messageId").map(String).filter(Boolean);
|
||||
if (messageIds.length === 0) {
|
||||
return Response.json({ ok: true, updated: 0 });
|
||||
return Response.json({ ok: false, intent, updated: 0 });
|
||||
}
|
||||
const mailboxes = canReadAllMailboxes(ctx) ? await listMailboxesForTenant(ctx.tenantId) : await listMailboxesForUser(ctx.tenantId, ctx.userId);
|
||||
const mailboxIds = mailboxes.map((m) => m.id);
|
||||
@@ -169,184 +174,72 @@ export const action = async ({ request, params }: ActionFunctionArgs) => {
|
||||
// best-effort mirror
|
||||
}
|
||||
}
|
||||
return Response.json({ ok: true, updated: count });
|
||||
return Response.json({ ok: true, intent, updated: count });
|
||||
}
|
||||
|
||||
if (intent === "archive") {
|
||||
// HiveGrid-side archive only — the provider mailbox stays untouched (M09 F).
|
||||
const { count } = await bulkUpdateMessages(ctx.tenantId, mailboxIds, messageIds, { archived: true });
|
||||
return Response.json({ ok: true, updated: count });
|
||||
return Response.json({
|
||||
ok: true,
|
||||
intent,
|
||||
messageKey: count === 1 ? "emailInbox.toast.messageArchived" : "emailInbox.toast.messagesArchived",
|
||||
updated: count,
|
||||
});
|
||||
}
|
||||
|
||||
throw notFoundResponse();
|
||||
};
|
||||
|
||||
function relativeOrAbsolute(iso: string, locale: string): 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 date.toLocaleTimeString(locale, { hour: "2-digit", minute: "2-digit" });
|
||||
return new Intl.RelativeTimeFormat(locale, { numeric: "auto" }).format(-days, "day");
|
||||
}
|
||||
return date.toLocaleDateString(locale);
|
||||
}
|
||||
|
||||
/** AK-UI-01: the route only wires loader/action — the interim screen renders the UI (AD-28). */
|
||||
export default function EmailInboxRoute() {
|
||||
const { t, i18n } = useTranslation();
|
||||
const rootData = useRootData();
|
||||
const { vm } = useLoaderData<LoaderData>();
|
||||
const actionData = useActionData<{ intent?: string; ok?: boolean; error?: string; messageKey?: string }>();
|
||||
useSaveToast(actionData, { intents: ["archive"] });
|
||||
const [searchParams] = useSearchParams();
|
||||
const submit = useSubmit();
|
||||
const navigate = useNavigate();
|
||||
|
||||
if (vm.status !== "ready" || !vm.data) {
|
||||
return <main className="mx-auto max-w-5xl px-4 py-10" data-ui-id="ui.email.inbox" />;
|
||||
}
|
||||
const { rows, filters, mailboxOptions, nextCursor, hasAnyMailbox, settingsHref, composeHref, canWrite } = vm.data;
|
||||
|
||||
const withParam = (key: string, value: string | null): string => {
|
||||
const applyFilters = (filters: EmailInboxAppliedFilters): void => {
|
||||
const next = new URLSearchParams(searchParams);
|
||||
next.delete("cursor");
|
||||
if (value) next.set(key, value);
|
||||
else next.delete(key);
|
||||
return `?${next.toString()}`;
|
||||
const setOrDelete = (key: string, value: string | null): void => {
|
||||
if (value) next.set(key, value);
|
||||
else next.delete(key);
|
||||
};
|
||||
setOrDelete("q", filters.q.trim() || null);
|
||||
setOrDelete("mailbox", filters.mailboxId);
|
||||
setOrDelete("linked", filters.linked === "all" ? null : filters.linked);
|
||||
setOrDelete("read", filters.read === "all" ? null : filters.read);
|
||||
void submit(next, { method: "get" });
|
||||
};
|
||||
|
||||
const runBulk = (intent: EmailInboxBulkIntent, messageIds: readonly string[]): void => {
|
||||
const form = new FormData();
|
||||
if (rootData.csrf) form.set("csrf", rootData.csrf);
|
||||
form.set("intent", intent);
|
||||
for (const id of messageIds) form.append("messageId", id);
|
||||
void submit(form, { method: "post" });
|
||||
};
|
||||
|
||||
const loadMore = (cursor: string): void => {
|
||||
const next = new URLSearchParams(searchParams);
|
||||
next.set("cursor", cursor);
|
||||
void submit(next, { method: "get" });
|
||||
};
|
||||
|
||||
return (
|
||||
<main className="mx-auto max-w-5xl px-4 py-10" data-ui-id="ui.email.inbox">
|
||||
<div className="flex items-center justify-between">
|
||||
<div>
|
||||
<h1 className="text-foreground text-xl font-semibold">{t("emailInbox.list.title")}</h1>
|
||||
<p className="text-muted-foreground mt-1 text-sm">{t("emailInbox.list.subtitle")}</p>
|
||||
</div>
|
||||
{canWrite && hasAnyMailbox && (
|
||||
<Link to={composeHref} className="bg-theme-600 rounded-md px-4 py-2 text-sm font-medium text-white" data-ui-id="ui.email.inbox.compose">
|
||||
{t("emailInbox.list.compose")}
|
||||
</Link>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{!hasAnyMailbox ? (
|
||||
<div className="mt-10 text-center" data-ui-id="ui.email.inbox.noMailbox">
|
||||
<p className="text-foreground font-medium">{t(vm.data.noMailboxHeadlineKey)}</p>
|
||||
<p className="text-muted-foreground mt-1 text-sm">{t(vm.data.noMailboxBodyKey)}</p>
|
||||
<Link to={settingsHref} className="text-theme-600 mt-3 inline-block text-sm underline">
|
||||
{t("emailInbox.list.connectCta")}
|
||||
</Link>
|
||||
</div>
|
||||
) : (
|
||||
<>
|
||||
<Form method="get" className="mt-4 flex flex-wrap items-center gap-2" data-ui-id="ui.email.inbox.filters">
|
||||
<input
|
||||
type="search"
|
||||
name="q"
|
||||
defaultValue={filters.q}
|
||||
placeholder={t("emailInbox.list.searchPlaceholder")}
|
||||
className="border-border w-64 rounded-md border px-3 py-1.5 text-sm"
|
||||
data-ui-id="ui.email.inbox.search"
|
||||
/>
|
||||
<select name="mailbox" defaultValue={filters.mailboxId ?? ""} className="border-border rounded-md border px-2 py-1.5 text-sm">
|
||||
<option value="">{t("emailInbox.list.filter.allMailboxes")}</option>
|
||||
{mailboxOptions.map((m) => (
|
||||
<option key={m.id} value={m.id}>
|
||||
{m.emailAddress}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
<select name="linked" defaultValue={filters.linked} className="border-border rounded-md border px-2 py-1.5 text-sm">
|
||||
<option value="all">{t("emailInbox.list.filter.linkedAll")}</option>
|
||||
<option value="linked">{t("emailInbox.list.filter.linked")}</option>
|
||||
<option value="unlinked">{t("emailInbox.list.filter.unlinked")}</option>
|
||||
</select>
|
||||
<select name="read" defaultValue={filters.read} className="border-border rounded-md border px-2 py-1.5 text-sm">
|
||||
<option value="all">{t("emailInbox.list.filter.readAll")}</option>
|
||||
<option value="unread">{t("emailInbox.list.filter.unread")}</option>
|
||||
<option value="read">{t("emailInbox.list.filter.read")}</option>
|
||||
</select>
|
||||
<button type="submit" className="border-border rounded-md border px-3 py-1.5 text-sm">
|
||||
{t("emailInbox.list.applyFilters")}
|
||||
</button>
|
||||
</Form>
|
||||
|
||||
{rows.length === 0 ? (
|
||||
<div className="mt-10 text-center" data-ui-id="ui.email.inbox.empty">
|
||||
<p className="text-foreground font-medium">{t(vm.data.emptyHeadlineKey)}</p>
|
||||
<p className="text-muted-foreground mt-1 text-sm">{t(vm.data.emptyBodyKey)}</p>
|
||||
</div>
|
||||
) : (
|
||||
<Form
|
||||
method="post"
|
||||
onChange={(event) => {
|
||||
// Bulk actions submit via the toolbar buttons; row checkboxes only select.
|
||||
event.stopPropagation();
|
||||
}}
|
||||
>
|
||||
{rootData.csrf && <input type="hidden" name="csrf" value={rootData.csrf} />}
|
||||
{canWrite && (
|
||||
<div className="mt-4 flex gap-2" data-ui-id="ui.email.inbox.bulk">
|
||||
<button type="submit" name="intent" value="mark-read" className="border-border rounded-md border px-3 py-1 text-xs">
|
||||
{t("emailInbox.list.bulk.markRead")}
|
||||
</button>
|
||||
<button type="submit" name="intent" value="mark-unread" className="border-border rounded-md border px-3 py-1 text-xs">
|
||||
{t("emailInbox.list.bulk.markUnread")}
|
||||
</button>
|
||||
<button type="submit" name="intent" value="archive" className="border-border rounded-md border px-3 py-1 text-xs">
|
||||
{t("emailInbox.list.bulk.archive")}
|
||||
</button>
|
||||
</div>
|
||||
)}
|
||||
<ul className="divide-border mt-2 divide-y" data-ui-id="ui.email.inbox.list">
|
||||
{rows.map((row) => (
|
||||
<li key={row.id} className="flex items-center gap-3 py-3" data-row-id={row.id} data-unread={!row.isRead}>
|
||||
{canWrite && <input type="checkbox" name="messageId" value={row.id} aria-label={t("emailInbox.list.selectRow")} />}
|
||||
<Link to={row.detailHref} className="min-w-0 flex-1">
|
||||
<div className="flex items-baseline justify-between gap-3">
|
||||
<p className={`truncate text-sm ${row.isRead ? "text-muted-foreground" : "text-foreground font-semibold"}`}>
|
||||
{row.fromName ?? row.fromAddress}
|
||||
{row.isNewsletter && (
|
||||
<span className="border-border text-muted-foreground ml-2 rounded border px-1 text-[10px]">{t("emailInbox.list.newsletterBadge")}</span>
|
||||
)}
|
||||
</p>
|
||||
<span className="text-muted-foreground shrink-0 text-xs">{relativeOrAbsolute(row.sentAt, i18n.language)}</span>
|
||||
</div>
|
||||
<p className={`truncate text-sm ${row.isRead ? "text-muted-foreground" : "text-foreground"}`}>
|
||||
{row.subject ?? t("emailInbox.list.noSubject")}
|
||||
{row.hasAttachments && <span className="ml-1">📎</span>}
|
||||
</p>
|
||||
<div className="flex items-center gap-2">
|
||||
<p className="text-muted-foreground truncate text-xs">{row.snippet}</p>
|
||||
{row.links.map((link) => (
|
||||
<span key={`${link.type}:${link.id}`} className="border-border text-muted-foreground shrink-0 rounded border px-1 text-[10px]" data-link-type={link.type}>
|
||||
{t(`emailInbox.list.linkBadge.${link.type}`)}
|
||||
</span>
|
||||
))}
|
||||
</div>
|
||||
</Link>
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
</Form>
|
||||
)}
|
||||
|
||||
{nextCursor && (
|
||||
<div className="mt-4 text-center">
|
||||
<button
|
||||
type="button"
|
||||
className="border-border rounded-md border px-4 py-2 text-sm"
|
||||
data-ui-id="ui.email.inbox.more"
|
||||
onClick={() => {
|
||||
const next = new URLSearchParams(searchParams);
|
||||
next.set("cursor", nextCursor);
|
||||
submit(next, { method: "get" });
|
||||
}}
|
||||
>
|
||||
{t("emailInbox.list.loadMore")}
|
||||
</button>
|
||||
</div>
|
||||
)}
|
||||
</>
|
||||
)}
|
||||
</main>
|
||||
<EmailInboxListPage
|
||||
vm={vm}
|
||||
actions={{
|
||||
onApplyFilters: applyFilters,
|
||||
onBulk: runBulk,
|
||||
onLoadMore: loadMore,
|
||||
onCompose: () => void navigate(vm.data?.composeHref ?? "."),
|
||||
onOpenSettings: () => void navigate(vm.data?.settingsHref ?? "."),
|
||||
}}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user