2 Commits

Author SHA1 Message Date
maaz519 36f43d7d2a refactor(inbox): fold mail INTO the Inbox (one unified surface, no Mail tab)
The Inbox is the single communication surface — mentions, needs-reply, system
alerts, support updates AND the mail behind them, all in one list. Removed the
separate Mail tab.

- Inbox is now two-pane: the item list (crm.inbox.*) on the left; clicking an item
  tied to a thread opens its conversation (MailReader) on the right to read + reply.
  Non-threaded items (e.g. system alerts) show their detail. Item actions
  (Done/Snooze/Archive) work for every item.
- Compose new mail (in-app or email) from the Inbox header.
- mail.tsx trimmed to reusable MailReader + NewMailModal (no standalone tab);
  sidebar + dashboard reverted to no Mail entry.
- The existing work-item Inbox stays the notifier; this makes it the reader too.
  HTML bodies still render in a sandboxed iframe. tsc + next build clean.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-18 16:43:48 +05:30
maaz519 46aa7a767c feat(mail): dedicated Mail reader in the CRM
A Mail surface in the Communication group, distinct from Messenger (chat) and the
work-item Inbox: read app-to-app + email messages (subject + rendered body), reply,
and compose (in-app to a person, or external to an email).

- mail-api.ts: crm.mail.list/history/reply + compose (crm.mail.internal/send), reusing
  the messenger directory for the people picker. Live via the AppShell SDK; mock in demo mode.
- mail.tsx: thread list + reader + reply + New-mail composer. HTML bodies render inside a
  SANDBOXED iframe (no scripts) — safe against untrusted email HTML.
- Wired into the sidebar (Communication) + dashboard switch.

The existing work-item Inbox stays as the notifier (IIOS's projector already flags new
mail there); this is where you read it. tsc + next build clean.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-18 16:38:16 +05:30
4 changed files with 349 additions and 34 deletions
+96 -33
View File
@@ -1,16 +1,17 @@
"use client"; "use client";
// ============================================================ // ============================================================
// Inbox — a personalized work/awareness feed IIOS projects from // Inbox — the ONE unified communication surface. It lists everything
// events (mentions, needs-reply, support updates, …), surfaced via // IIOS surfaces for you (mentions, needs-reply, system alerts, support
// the be-crm data door (crm.inbox.*). List + filter by state, and // updates, …) AND the mail behind them: click an item tied to a thread
// mark items done / snoozed / archived. Items are created by IIOS's // and its conversation opens on the right to read + reply. Compose new
// projector, never here. Mock when the Shell isn't configured. // mail from here too. Items come from crm.inbox.*; threads from crm.mail.*.
// ============================================================ // ============================================================
import { useState } from "react"; import { useEffect, useState } from "react";
import { Btn, Icon, PageHead, Pill } from "./ui"; import { Btn, Icon, PageHead, Pill, useToast } from "./ui";
import { useInboxData, type InboxState, type UiInboxItem } from "@/lib/inbox-api"; import { useInboxData, type InboxState, type UiInboxItem } from "@/lib/inbox-api";
import { MailReader, NewMailModal } from "./mail";
const KIND_LABEL: Record<string, string> = { const KIND_LABEL: Record<string, string> = {
MENTION: "Mention", NEEDS_REPLY: "Needs reply", NEEDS_REVIEW: "Needs review", NEEDS_APPROVAL: "Needs approval", MENTION: "Mention", NEEDS_REPLY: "Needs reply", NEEDS_REVIEW: "Needs review", NEEDS_APPROVAL: "Needs approval",
@@ -23,10 +24,22 @@ const FILTERS: { value: InboxState; label: string }[] = [
export function Inbox() { export function Inbox() {
const [filter, setFilter] = useState<InboxState>("OPEN"); const [filter, setFilter] = useState<InboxState>("OPEN");
const inbox = useInboxData(filter); const inbox = useInboxData(filter);
const toast = useToast();
const [selectedId, setSelectedId] = useState<string | null>(null);
const [newOpen, setNewOpen] = useState(false);
useEffect(() => {
if ((!selectedId || !inbox.items.some((i) => i.id === selectedId)) && inbox.items[0]) setSelectedId(inbox.items[0].id);
}, [inbox.items, selectedId]);
const selected = inbox.items.find((i) => i.id === selectedId) ?? null;
return ( return (
<div className="view"> <div className="view">
<PageHead eyebrow="Communication" title="Inbox" subtitle="Mentions, replies and updates that need your attention" icon="bell" /> <PageHead
eyebrow="Communication" title="Inbox" subtitle="Mentions, messages, system alerts and mail — all in one place" icon="bell"
actions={<Btn icon="plus" onClick={() => setNewOpen(true)}>New mail</Btn>}
/>
{!inbox.live && ( {!inbox.live && (
<div style={{ margin: "0 0 14px", padding: "8px 14px", borderRadius: 10, background: "var(--panel-2)", color: "var(--muted)", fontSize: 13, border: "1px solid var(--border)" }}> <div style={{ margin: "0 0 14px", padding: "8px 14px", borderRadius: 10, background: "var(--panel-2)", color: "var(--muted)", fontSize: 13, border: "1px solid var(--border)" }}>
Demo mode running on mock data. It goes live once the Shell + be-crm are connected. Demo mode running on mock data. It goes live once the Shell + be-crm are connected.
@@ -39,47 +52,97 @@ export function Inbox() {
))} ))}
</div> </div>
<div className="card" style={{ padding: 0, overflow: "hidden" }}> <div className="card" style={{ display: "flex", height: 620, padding: 0, overflow: "hidden" }}>
{inbox.loading && <div style={{ padding: 20, color: "var(--muted)" }}>Loading</div>} {/* Left — the unified item list */}
{!inbox.loading && inbox.items.length === 0 && ( <aside style={{ width: 360, borderRight: "1px solid var(--border)", overflowY: "auto", background: "var(--panel)" }}>
<div style={{ padding: 28, color: "var(--muted)", textAlign: "center" }}>Nothing here you&apos;re all caught up 🎉</div> {inbox.loading && <div style={{ padding: 20, color: "var(--muted)" }}>Loading</div>}
)} {!inbox.loading && inbox.items.length === 0 && (
{inbox.items.map((it) => ( <div style={{ padding: 28, color: "var(--muted)", textAlign: "center" }}>Nothing here you&apos;re all caught up 🎉</div>
<InboxRow )}
key={it.id} it={it} {inbox.items.map((it) => (
onDone={() => inbox.transition(it.id, "DONE")} <ItemRow key={it.id} it={it} active={it.id === selectedId} onClick={() => setSelectedId(it.id)} />
onSnooze={() => inbox.transition(it.id, "SNOOZED")} ))}
onArchive={() => inbox.transition(it.id, "ARCHIVED")} </aside>
/>
))} {/* Right — read the mail behind the item, or the item detail */}
<section style={{ flex: 1, display: "flex", flexDirection: "column", minWidth: 0, background: "var(--bg)" }}>
{selected ? (
<Detail
it={selected}
onError={(m) => toast.push({ tone: "error", title: "Failed", desc: m })}
onDone={() => inbox.transition(selected.id, "DONE")}
onSnooze={() => inbox.transition(selected.id, "SNOOZED")}
onArchive={() => inbox.transition(selected.id, "ARCHIVED")}
/>
) : (
<div style={{ margin: "auto", color: "var(--muted)", textAlign: "center" }}>
<Icon name="bell" size={38} /><p>Select an item to read</p>
</div>
)}
</section>
</div> </div>
<NewMailModal
open={newOpen} onClose={() => setNewOpen(false)}
onSent={() => { setNewOpen(false); inbox.refetch(); toast.push({ tone: "success", title: "Sent" }); }}
onError={(m) => toast.push({ tone: "error", title: "Couldn't send", desc: m })}
/>
</div> </div>
); );
} }
function InboxRow({ it, onDone, onSnooze, onArchive }: { it: UiInboxItem; onDone: () => void; onSnooze: () => void; onArchive: () => void }) { function ItemRow({ it, active, onClick }: { it: UiInboxItem; active: boolean; onClick: () => void }) {
const isMention = it.kind === "MENTION"; const isMention = it.kind === "MENTION";
return ( return (
<div style={{ display: "flex", gap: 12, alignItems: "flex-start", padding: "14px 18px", borderBottom: "1px solid var(--border)" }}> <button
<span style={{ marginTop: 2, color: isMention ? "var(--orange)" : "var(--text-2)" }}> onClick={onClick}
<Icon name={isMention ? "chat" : "bell"} size={18} /> style={{
display: "flex", gap: 10, alignItems: "flex-start", width: "100%", textAlign: "left",
padding: "13px 16px", border: "none", borderBottom: "1px solid var(--border)", cursor: "pointer",
background: active ? "var(--panel-2)" : "transparent", color: "var(--text)",
}}
>
<span style={{ marginTop: 2, color: isMention ? "var(--orange)" : "var(--text-2)", flexShrink: 0 }}>
<Icon name={it.threadId ? "chat" : isMention ? "chat" : "bell"} size={18} />
</span> </span>
<div style={{ flex: 1, minWidth: 0 }}> <div style={{ flex: 1, minWidth: 0 }}>
<div style={{ display: "flex", gap: 8, alignItems: "center", flexWrap: "wrap" }}> <div style={{ display: "flex", gap: 6, alignItems: "center", flexWrap: "wrap" }}>
<Pill tone={isMention ? "warn" : "muted"}>{KIND_LABEL[it.kind] ?? it.kind}</Pill> <Pill tone={isMention ? "warn" : "muted"}>{KIND_LABEL[it.kind] ?? it.kind}</Pill>
<span style={{ fontWeight: 600 }}>{it.title}</span> <span style={{ fontWeight: 600, whiteSpace: "nowrap", overflow: "hidden", textOverflow: "ellipsis" }}>{it.title}</span>
</div> </div>
{it.summary && <div style={{ color: "var(--muted)", fontSize: 13, marginTop: 3 }}>{it.summary}</div>} {it.summary && <div style={{ color: "var(--muted)", fontSize: 12.5, marginTop: 3, whiteSpace: "nowrap", overflow: "hidden", textOverflow: "ellipsis" }}>{it.summary}</div>}
</div> </div>
{it.state === "OPEN" ? ( {it.state !== "OPEN" && <Pill tone="muted">{it.state.toLowerCase()}</Pill>}
<div style={{ display: "flex", gap: 6, flexShrink: 0 }}> </button>
);
}
function Detail({ it, onError, onDone, onSnooze, onArchive }: {
it: UiInboxItem; onError: (m: string) => void; onDone: () => void; onSnooze: () => void; onArchive: () => void;
}) {
return (
<>
{/* Item actions bar (works for every item, threaded or not) */}
{it.state === "OPEN" && (
<div style={{ display: "flex", gap: 6, padding: "10px 16px", borderBottom: "1px solid var(--border)", justifyContent: "flex-end" }}>
<Btn variant="ghost" icon="clock" onClick={onSnooze}>Snooze</Btn> <Btn variant="ghost" icon="clock" onClick={onSnooze}>Snooze</Btn>
<Btn variant="outline" icon="check" onClick={onDone}>Done</Btn> <Btn variant="outline" icon="check" onClick={onDone}>Done</Btn>
<Btn variant="ghost" icon="x" onClick={onArchive}>Archive</Btn> <Btn variant="ghost" icon="x" onClick={onArchive}>Archive</Btn>
</div> </div>
) : (
<Pill tone="muted">{it.state.toLowerCase()}</Pill>
)} )}
</div>
{it.threadId ? (
// A message/mail item → open the conversation to read + reply.
<div style={{ flex: 1, minHeight: 0 }}>
<MailReader threadId={it.threadId} subject={it.title} onError={onError} />
</div>
) : (
// A non-threaded item (e.g. a system alert) → show its detail.
<div style={{ flex: 1, overflowY: "auto", padding: 22 }}>
<div style={{ fontWeight: 700, fontSize: 16, marginBottom: 6 }}>{it.title}</div>
{it.summary && <div style={{ color: "var(--muted)", fontSize: 14, lineHeight: 1.55 }}>{it.summary}</div>}
</div>
)}
</>
); );
} }
+135
View File
@@ -0,0 +1,135 @@
"use client";
// ============================================================
// Mail components used INSIDE the Inbox (not a separate tab).
// The Inbox is the one unified surface — mentions, system messages
// and mail all live there. These render the mail body + reply, and
// compose a new message. HTML bodies render in a sandboxed iframe.
// ============================================================
import { type CSSProperties, useEffect, useState } from "react";
import { Avatar, Btn, Field, Icon, Modal, Pill } from "./ui";
import { useMailThread, useMailCompose, type MailPerson } from "@/lib/mail-api";
const timeOf = (iso?: string) => {
if (!iso) return "";
const d = new Date(iso);
return Number.isNaN(+d) ? "" : d.toLocaleString([], { month: "short", day: "numeric", hour: "2-digit", minute: "2-digit" });
};
const CUSTOMER_GRAD = "linear-gradient(135deg,#10b981,#059669)";
const inputStyle: CSSProperties = {
width: "100%", padding: "9px 12px", borderRadius: 10, border: "1px solid var(--border)",
background: "var(--panel)", color: "var(--text)", fontSize: 14, outline: "none",
};
/** Reader + reply for one mail thread. Used in the Inbox detail pane when an item has a threadId. */
export function MailReader({ threadId, subject, onError }: { threadId: string; subject: string; onError: (m: string) => void }) {
const t = useMailThread(threadId);
const [draft, setDraft] = useState("");
const [sending, setSending] = useState(false);
async function reply() {
const text = draft.trim();
if (!text || sending) return;
setDraft(""); setSending(true);
try { await t.reply(text); }
catch (e) { setDraft(text); onError((e as Error).message); }
finally { setSending(false); }
}
return (
<div style={{ display: "flex", flexDirection: "column", height: "100%", minHeight: 0 }}>
<header style={{ padding: "12px 18px", borderBottom: "1px solid var(--border)" }}>
<div style={{ fontWeight: 700, fontSize: 15 }}>{subject || "(no subject)"}</div>
</header>
<div style={{ flex: 1, overflowY: "auto", padding: 16, display: "flex", flexDirection: "column", gap: 12 }}>
{t.loading && t.messages.length === 0 && <div style={{ margin: "auto", color: "var(--muted)" }}>Loading</div>}
{!t.loading && t.messages.length === 0 && <div style={{ margin: "auto", color: "var(--muted)" }}>No messages.</div>}
{t.messages.map((m) => (
<div key={m.interactionId} style={{ border: "1px solid var(--border)", borderRadius: 12, background: "var(--panel)", overflow: "hidden" }}>
<div style={{ padding: "7px 12px", borderBottom: "1px solid var(--border)", display: "flex", justifyContent: "space-between", fontSize: 12, color: "var(--muted)" }}>
<span>{m.kind === "EMAIL" ? "Email" : "Reply"}{m.actorId ? ` · ${m.actorId.replace(/^(pp_|cust_)/, "").slice(0, 8)}` : ""}</span>
<span>{timeOf(m.occurredAt)}</span>
</div>
{m.html
? <iframe sandbox="" srcDoc={m.html} title="mail body" style={{ width: "100%", height: 200, border: "none", background: "#fff" }} />
: <div style={{ padding: 12, whiteSpace: "pre-wrap", wordBreak: "break-word", fontSize: 14 }}>{m.text}</div>}
</div>
))}
</div>
<footer style={{ display: "flex", gap: 8, padding: 12, borderTop: "1px solid var(--border)" }}>
<input
value={draft} onChange={(e) => setDraft(e.target.value)}
onKeyDown={(e) => { if (e.key === "Enter" && !e.shiftKey) { e.preventDefault(); void reply(); } }}
placeholder="Reply…" style={inputStyle}
/>
<Btn icon="send" onClick={() => void reply()} disabled={sending || !draft.trim()}>Reply</Btn>
</footer>
</div>
);
}
/** Compose a new message — in-app (to a person) or external (to an email). */
export function NewMailModal({ open, onClose, onSent, onError }: { open: boolean; onClose: () => void; onSent: () => void; onError: (m: string) => void }) {
const compose = useMailCompose(onSent);
const [mode, setMode] = useState<"internal" | "external">("internal");
const [recipient, setRecipient] = useState("");
const [subject, setSubject] = useState("");
const [body, setBody] = useState("");
const [q, setQ] = useState("");
const [busy, setBusy] = useState(false);
useEffect(() => { if (!open) { setMode("internal"); setRecipient(""); setSubject(""); setBody(""); setQ(""); setBusy(false); } }, [open]);
const filtered = compose.directory.filter((p) => p.name.toLowerCase().includes(q.trim().toLowerCase()));
const canSend = !!recipient && !!subject.trim() && !!body.trim() && !busy;
async function send() {
if (!canSend) return;
setBusy(true);
try {
if (mode === "internal") await compose.sendInternal(recipient, subject.trim(), body.trim());
else await compose.sendExternal(recipient.trim(), subject.trim(), body.trim());
} catch (e) { onError((e as Error).message); }
finally { setBusy(false); }
}
return (
<Modal
open={open} onClose={onClose} title="New message" subtitle={mode === "internal" ? "To a team member or client (in-app)" : "To an email address"} icon="chat"
footer={<>
<Btn variant="ghost" onClick={onClose}>Cancel</Btn>
<Btn icon="send" onClick={() => void send()} disabled={!canSend}>{busy ? "Sending…" : "Send"}</Btn>
</>}
>
<div style={{ display: "flex", gap: 6, marginBottom: 12 }}>
<Btn variant={mode === "internal" ? "primary" : "outline"} onClick={() => { setMode("internal"); setRecipient(""); }}>In-app</Btn>
<Btn variant={mode === "external" ? "primary" : "outline"} onClick={() => { setMode("external"); setRecipient(""); }}>Email</Btn>
</div>
{mode === "internal" ? (
<Field label="To (person)">
<input value={q} onChange={(e) => setQ(e.target.value)} placeholder="Search people…" style={{ ...inputStyle, marginBottom: 8 }} />
<div style={{ maxHeight: 180, overflowY: "auto", display: "flex", flexDirection: "column", gap: 2 }}>
{filtered.length === 0 && <div style={{ color: "var(--muted)", padding: 8 }}>No people found.</div>}
{filtered.map((p: MailPerson) => (
<label key={p.id} style={{ display: "flex", alignItems: "center", gap: 10, padding: "7px 10px", borderRadius: 10, cursor: "pointer", background: recipient === p.id ? "var(--panel-2)" : "transparent" }}>
<input type="radio" checked={recipient === p.id} onChange={() => setRecipient(p.id)} />
<Avatar initials={(p.name.split(/\s+/).map((s) => s[0]).join("").slice(0, 2) || "?").toUpperCase()} size={26} gradient={p.kind === "customer" ? CUSTOMER_GRAD : undefined} />
<span style={{ flex: 1 }}>{p.name}</span>
<Pill tone="muted">{p.kind}</Pill>
</label>
))}
</div>
</Field>
) : (
<Field label="To (email)">
<input value={recipient} onChange={(e) => setRecipient(e.target.value)} placeholder="name@company.com" style={inputStyle} />
</Field>
)}
<Field label="Subject"><input value={subject} onChange={(e) => setSubject(e.target.value)} placeholder="Subject" style={inputStyle} /></Field>
<Field label="Message"><textarea value={body} onChange={(e) => setBody(e.target.value)} placeholder="Write your message…" rows={6} style={{ ...inputStyle, resize: "vertical" }} /></Field>
</Modal>
);
}
+1 -1
View File
@@ -33,7 +33,7 @@ export const NAV_GROUPS: NavGroup[] = [
title: "Communication", title: "Communication",
items: [ items: [
{ key: "messenger", label: "Messenger", icon: "send", subtitle: "Chat with your team and clients" }, { key: "messenger", label: "Messenger", icon: "send", subtitle: "Chat with your team and clients" },
{ key: "inbox", label: "Inbox", icon: "bell", subtitle: "Mentions, replies and updates for you" }, { key: "inbox", label: "Inbox", icon: "bell", subtitle: "Mentions, messages, alerts and mail — all in one" },
], ],
}, },
{ {
+117
View File
@@ -0,0 +1,117 @@
"use client";
// Mail data layer. A dedicated Mail reader over the be-crm data door (crm.mail.*), distinct from
// the Messenger chat and from the work-item Inbox. Live via the AppShell SDK; a small mock keeps the
// demo working before the Shell + be-crm are connected.
//
// Live contract (be-crm):
// query crm.mail.list {} -> MailThread[]
// query crm.mail.history { threadId } -> MailMessage[]
// cmd crm.mail.reply { threadId, content } -> { interactionId, threadId }
// cmd crm.mail.internal { recipientUserId, subject?, text?, html? } -> { threadId }
// cmd crm.mail.send { target, subject?, text?, html?, mirrorToUserId? } -> { commandId }
// query crm.messenger.directory { kind, limit } -> people to compose to (reused)
import { useCallback, useMemo, useState } from "react";
import { useAppShell, useQuery } from "@abe-kap/appshell-sdk/react";
import { isShellConfigured } from "./appshell";
export interface MailThread {
threadId: string; subject: string | null; participants: string[]; unread: number; lastMessage?: string; lastAt?: string;
}
export interface MailMessage {
interactionId: string; actorId: string | null; kind: string; occurredAt: string; html: string | null; text: string | null;
}
export interface MailPerson { id: string; name: string; kind: "staff" | "customer" }
const SHELL = isShellConfigured();
/* ============================ Thread list ============================ */
export interface MailListData {
live: boolean; loading: boolean; error: string | null; threads: MailThread[]; refetch: () => void;
}
export function useMailThreads(): MailListData {
if (SHELL) {
const q = useQuery<MailThread[]>("crm.mail.list", {});
return { live: true, loading: q.loading, error: q.error?.message ?? null, threads: q.data ?? [], refetch: q.refetch };
}
return { live: false, loading: false, error: null, threads: MOCK_THREADS, refetch: () => {} };
}
/* ============================ One thread ============================ */
export interface MailThreadData {
loading: boolean; error: string | null; messages: MailMessage[]; reply: (content: string) => Promise<void>; refetch: () => void;
}
export function useMailThread(threadId: string | null): MailThreadData {
if (SHELL) return useLiveThread(threadId);
return useMockThread(threadId);
}
function useLiveThread(threadId: string | null): MailThreadData {
const { sdk } = useAppShell();
const q = useQuery<MailMessage[]>("crm.mail.history", threadId ? { threadId } : { threadId: "" });
const reply = useCallback(async (content: string) => {
if (!threadId) return;
await sdk.command("crm.mail.reply", { threadId, content });
q.refetch();
}, [sdk, threadId, q]);
return { loading: q.loading, error: q.error?.message ?? null, messages: threadId ? (q.data ?? []) : [], reply, refetch: q.refetch };
}
/* ============================ Compose ============================ */
export interface ComposeData {
directory: MailPerson[];
sendInternal: (recipientUserId: string, subject: string, text: string) => Promise<void>;
sendExternal: (target: string, subject: string, text: string, mirrorToUserId?: string) => Promise<void>;
}
export function useMailCompose(onSent: () => void): ComposeData {
if (SHELL) {
const { sdk } = useAppShell();
const dirQ = useQuery<MailPerson[]>("crm.messenger.directory", { kind: "all", limit: 100 });
const directory = useMemo(() => (dirQ.data ?? []).map((d) => ({ id: (d as unknown as { id: string }).id, name: (d as unknown as { displayName?: string; name?: string }).displayName ?? (d as unknown as { name?: string }).name ?? "", kind: (d as MailPerson).kind })), [dirQ.data]);
const sendInternal = useCallback(async (recipientUserId: string, subject: string, text: string) => {
await sdk.command("crm.mail.internal", { recipientUserId, subject, text, html: `<p>${escapeHtml(text)}</p>` });
onSent();
}, [sdk, onSent]);
const sendExternal = useCallback(async (target: string, subject: string, text: string, mirrorToUserId?: string) => {
await sdk.command("crm.mail.send", { target, subject, text, html: `<p>${escapeHtml(text)}</p>`, ...(mirrorToUserId ? { mirrorToUserId } : {}) });
onSent();
}, [sdk, onSent]);
return { directory, sendInternal, sendExternal };
}
return { directory: MOCK_PEOPLE, sendInternal: async () => onSent(), sendExternal: async () => onSent() };
}
function escapeHtml(s: string): string {
return s.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
}
/* ============================ Mock (demo mode) ============================ */
const now = () => new Date().toISOString();
const MOCK_PEOPLE: MailPerson[] = [
{ id: "pp_sofia", name: "Sofia Ramirez", kind: "staff" },
{ id: "cust_acme", name: "Acme Roofing (Client)", kind: "customer" },
];
const MOCK_THREADS: MailThread[] = [
{ threadId: "mt_1", subject: "Welcome to the Founders Club", participants: ["you", "system"], unread: 1, lastMessage: "Thanks for joining…", lastAt: now() },
{ threadId: "mt_2", subject: "Storm response — East side", participants: ["you", "pp_sofia"], unread: 0, lastMessage: "Crew rolling out at 7", lastAt: now() },
];
function useMockThread(threadId: string | null): MailThreadData {
const [extra, setExtra] = useState<MailMessage[]>([]);
const base: MailMessage[] = threadId === "mt_1"
? [{ interactionId: "m1", actorId: "system", kind: "EMAIL", occurredAt: now(), html: "<p>Thanks for joining the <b>Founders Club</b>. Set up your account to get started.</p>", text: "Thanks for joining the Founders Club." }]
: threadId === "mt_2"
? [{ interactionId: "m2", actorId: "pp_sofia", kind: "EMAIL", occurredAt: now(), html: "<p>Crew is rolling out at 7. Confirm the Henderson scope?</p>", text: "Crew rolling out at 7." }]
: [];
const reply = useCallback(async (content: string) => {
setExtra((l) => [...l, { interactionId: `r_${l.length}`, actorId: "you", kind: "MESSAGE", occurredAt: now(), html: null, text: content }]);
}, []);
return { loading: false, error: null, messages: threadId ? [...base, ...extra] : [], reply, refetch: () => {} };
}