forked from Goutam/lynkeduppro-crm
fix(inbox): show sent mail in the unified inbox + fix compose attach button
- inbox merges crm.mail.list threads (kind MAIL) into crm.inbox.list items so sent/received mail actually appears in the one surface; mail shows in the Open view (it has no inbox work-item state) and opens in MailReader on click. Mail rows are read/reply only — no Done/Snooze/Archive (crm.inbox.transition doesn't apply to a mail thread). - compose Attachments block was wrapped in <Field> (a <label>), so the label hijacked the Attach button's click via label→file-input association and the picker misfired. Use a plain div with the same field styling. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
+34
-1
@@ -11,6 +11,7 @@
|
||||
import { useCallback, useMemo, useState } from "react";
|
||||
import { useAppShell, useQuery } from "@abe-kap/appshell-sdk/react";
|
||||
import { isShellConfigured } from "./appshell";
|
||||
import type { MailThread } from "./mail-api";
|
||||
|
||||
export type InboxState = "OPEN" | "SNOOZED" | "DONE" | "ARCHIVED" | "CANCELLED" | "STALE";
|
||||
export interface UiInboxItem {
|
||||
@@ -34,11 +35,43 @@ export function useInboxData(state?: InboxState): InboxData {
|
||||
function useLiveInbox(state?: InboxState): InboxData {
|
||||
const { sdk } = useAppShell();
|
||||
const q = useQuery<UiInboxItem[]>("crm.inbox.list", state ? { state } : {});
|
||||
// Mail lives in crm-mail threads, NOT the inbox projection — fold it into the one unified
|
||||
// surface. Mail has no inbox work-item state, so it only shows in the Open (or unfiltered) view.
|
||||
const showMail = !state || state === "OPEN";
|
||||
const mq = useQuery<MailThread[]>("crm.mail.list", {});
|
||||
|
||||
const items = useMemo<UiInboxItem[]>(() => {
|
||||
const inboxItems = q.data ?? [];
|
||||
const mailItems: UiInboxItem[] = showMail
|
||||
? (mq.data ?? []).map((t) => ({
|
||||
id: `mail:${t.threadId}`,
|
||||
kind: "MAIL",
|
||||
state: "OPEN" as InboxState,
|
||||
title: t.subject || "(no subject)",
|
||||
...(t.lastMessage ? { summary: t.lastMessage } : {}),
|
||||
priority: t.unread > 0 ? "HIGH" : "LOW",
|
||||
threadId: t.threadId,
|
||||
createdAt: t.lastAt ?? "",
|
||||
}))
|
||||
: [];
|
||||
// Newest first; mail and inbox items interleave by time.
|
||||
return [...mailItems, ...inboxItems].sort((a, b) => (b.createdAt ?? "").localeCompare(a.createdAt ?? ""));
|
||||
}, [q.data, mq.data, showMail]);
|
||||
|
||||
const transition = useCallback(async (id: string, next: InboxState) => {
|
||||
await sdk.command("crm.inbox.transition", { id, state: next });
|
||||
q.refetch();
|
||||
}, [sdk, q]);
|
||||
return { live: true, loading: q.loading, error: q.error?.message ?? null, items: q.data ?? [], transition, refetch: q.refetch };
|
||||
|
||||
return {
|
||||
live: true,
|
||||
loading: q.loading || (showMail && mq.loading),
|
||||
// Don't let a mail-list hiccup blank the whole inbox — surface only the inbox error.
|
||||
error: q.error?.message ?? null,
|
||||
items,
|
||||
transition,
|
||||
refetch: () => { q.refetch(); mq.refetch(); },
|
||||
};
|
||||
}
|
||||
|
||||
const MOCK_ITEMS: UiInboxItem[] = [
|
||||
|
||||
Reference in New Issue
Block a user