@octarq/plugin-mail 0.0.0-stage → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/api.ts +223 -0
- package/i18n.ts +699 -0
- package/index.ts +17 -0
- package/package.json +26 -3
- package/pages/AuthBadges.tsx +33 -0
- package/pages/Compose.tsx +291 -0
- package/pages/EmailListItem.tsx +85 -0
- package/pages/EmailListPane.tsx +152 -0
- package/pages/EmailView.tsx +283 -0
- package/pages/FolderNav.tsx +30 -0
- package/pages/MailGuide.tsx +36 -0
- package/pages/MailSettings.tsx +174 -0
- package/pages/MailTabs.tsx +26 -0
- package/pages/MailboxBar.tsx +59 -0
- package/pages/MailboxEditor.tsx +116 -0
- package/pages/SMTPSenders.tsx +323 -0
- package/pages/SuppressionList.tsx +148 -0
- package/pages/emptyState.test.tsx +58 -0
- package/pages/forms.test.tsx +694 -0
- package/pages/index.tsx +213 -0
- package/pages/mailEnhancements.test.tsx +254 -0
- package/pages/types.ts +10 -0
- package/tsconfig.json +15 -0
- package/widgets/MailSetupStepWidget.tsx +55 -0
- package/widgets/MailStatCardWidget.tsx +22 -0
- package/widgets/RecentMailPanelWidget.tsx +37 -0
- package/README.md +0 -3
package/pages/index.tsx
ADDED
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
import { PageShell, Button, useTranslation } from "@octarq/plugin-sdk";
|
|
2
|
+
import { useEffect, useState, useMemo } from "react";
|
|
3
|
+
import { useSearchParams } from "react-router-dom";
|
|
4
|
+
import { mailApi, Domain, effectiveMailHosts, Email, Mailbox } from "../api";
|
|
5
|
+
import { Inbox, Send, Plus } from "lucide-react";
|
|
6
|
+
import { MailSettings } from "./MailSettings";
|
|
7
|
+
import { SMTPSenders } from "./SMTPSenders";
|
|
8
|
+
import { SuppressionList } from "./SuppressionList";
|
|
9
|
+
import { ReplyDraft, MailFolder } from "./types";
|
|
10
|
+
import { EmailViewForm } from "./EmailView";
|
|
11
|
+
import { MailboxEditor } from "./MailboxEditor";
|
|
12
|
+
import { Compose } from "./Compose";
|
|
13
|
+
import { FolderNav } from "./FolderNav";
|
|
14
|
+
import { MailboxBar } from "./MailboxBar";
|
|
15
|
+
import { MailGuide } from "./MailGuide";
|
|
16
|
+
import { EmailListPane } from "./EmailListPane";
|
|
17
|
+
import { MailTabs, MailTab } from "./MailTabs";
|
|
18
|
+
|
|
19
|
+
export default function MailPage() {
|
|
20
|
+
const [boxes, setBoxes] = useState<Mailbox[]>([]);
|
|
21
|
+
const [domains, setDomains] = useState<Domain[]>([]);
|
|
22
|
+
const [active, setActive] = useState<number | undefined>(undefined);
|
|
23
|
+
const [folder, setFolder] = useState<MailFolder>("inbox");
|
|
24
|
+
const [emails, setEmails] = useState<Email[]>([]);
|
|
25
|
+
const [open, setOpen] = useState<Email | null>(null);
|
|
26
|
+
const [newBox, setNewBox] = useState(false);
|
|
27
|
+
const [editBox, setEditBox] = useState<Mailbox | null>(null);
|
|
28
|
+
const [compose, setCompose] = useState<ReplyDraft | true | null>(null);
|
|
29
|
+
|
|
30
|
+
const [q, setQ] = useState("");
|
|
31
|
+
const [page, setPage] = useState(0);
|
|
32
|
+
const [hasMore, setHasMore] = useState(true);
|
|
33
|
+
const [loading, setLoading] = useState(false);
|
|
34
|
+
|
|
35
|
+
const [searchParams, setSearchParams] = useSearchParams();
|
|
36
|
+
const { t } = useTranslation();
|
|
37
|
+
|
|
38
|
+
useEffect(() => {
|
|
39
|
+
if (searchParams.get("create") === "1") {
|
|
40
|
+
setNewBox(true);
|
|
41
|
+
setSearchParams(prev => {
|
|
42
|
+
const next = new URLSearchParams(prev);
|
|
43
|
+
next.delete("create");
|
|
44
|
+
return next;
|
|
45
|
+
}, { replace: true });
|
|
46
|
+
}
|
|
47
|
+
}, [searchParams, setSearchParams]);
|
|
48
|
+
|
|
49
|
+
const tabParam = searchParams.get("tab");
|
|
50
|
+
const tab: MailTab = useMemo(() => {
|
|
51
|
+
if (tabParam === "settings" || tabParam === "inbound") return "inbound";
|
|
52
|
+
if (tabParam === "smtp") return "smtp";
|
|
53
|
+
if (tabParam === "suppressions") return "suppressions";
|
|
54
|
+
return "mail";
|
|
55
|
+
}, [tabParam]);
|
|
56
|
+
|
|
57
|
+
const setTab = (tTab: MailTab) => {
|
|
58
|
+
setSearchParams(prev => {
|
|
59
|
+
if (tTab === "mail") prev.delete("tab");
|
|
60
|
+
else prev.set("tab", tTab);
|
|
61
|
+
return prev;
|
|
62
|
+
}, { replace: true });
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
const mailHostOptions = Array.from(new Set(domains.flatMap(effectiveMailHosts)));
|
|
66
|
+
|
|
67
|
+
async function loadBoxes() {
|
|
68
|
+
setBoxes(await mailApi.mailboxes());
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
async function loadEmails(reset = false) {
|
|
72
|
+
if (loading || (!hasMore && !reset)) return;
|
|
73
|
+
setLoading(true);
|
|
74
|
+
try {
|
|
75
|
+
const limit = 50;
|
|
76
|
+
const offset = reset ? 0 : page * limit;
|
|
77
|
+
const res = await mailApi.emails(active, { q, folder, limit, offset });
|
|
78
|
+
setHasMore(res.length >= limit);
|
|
79
|
+
setEmails(prev => (reset ? res : [...prev, ...res]));
|
|
80
|
+
setPage(reset ? 1 : page + 1);
|
|
81
|
+
} finally {
|
|
82
|
+
setLoading(false);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
useEffect(() => {
|
|
87
|
+
loadBoxes();
|
|
88
|
+
mailApi.domains().then(setDomains).catch(() => {});
|
|
89
|
+
}, []);
|
|
90
|
+
|
|
91
|
+
useEffect(() => {
|
|
92
|
+
const timer = setTimeout(() => {
|
|
93
|
+
loadEmails(true);
|
|
94
|
+
}, 150);
|
|
95
|
+
return () => clearTimeout(timer);
|
|
96
|
+
}, [active, folder, q]);
|
|
97
|
+
|
|
98
|
+
const handleScroll = (e: React.UIEvent<HTMLDivElement>) => {
|
|
99
|
+
const bottom = e.currentTarget.scrollHeight - e.currentTarget.scrollTop <= e.currentTarget.clientHeight + 100;
|
|
100
|
+
if (bottom) loadEmails();
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
async function openEmail(e: Email) {
|
|
104
|
+
if (folder === "drafts") {
|
|
105
|
+
setCompose({ id: e.id, to: e.to, subject: e.subject, text: e.text });
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
const full = await mailApi.email(e.id);
|
|
109
|
+
setOpen(full);
|
|
110
|
+
loadEmails(true);
|
|
111
|
+
loadBoxes();
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
async function markAllRead() {
|
|
115
|
+
await mailApi.readAllEmails(active);
|
|
116
|
+
loadEmails(true);
|
|
117
|
+
loadBoxes();
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
const activeBox = useMemo(() => boxes.find(b => b.id === active), [boxes, active]);
|
|
121
|
+
const totalUnread = useMemo(() => boxes.reduce((acc, b) => acc + (b.unread || 0), 0), [boxes]);
|
|
122
|
+
|
|
123
|
+
return (
|
|
124
|
+
<PageShell
|
|
125
|
+
title={t("mail.pageTitle")}
|
|
126
|
+
description={t("mail.pageDesc")}
|
|
127
|
+
action={
|
|
128
|
+
<div className="flex items-center gap-2">
|
|
129
|
+
<Button variant="ghost" size="sm" onClick={markAllRead}>
|
|
130
|
+
{t("mail.markRead")}
|
|
131
|
+
</Button>
|
|
132
|
+
<Button variant="outline" size="sm" onClick={() => setCompose(true)}>
|
|
133
|
+
<Send className="h-3.5 w-3.5" />
|
|
134
|
+
{t("mail.compose")}
|
|
135
|
+
</Button>
|
|
136
|
+
<Button variant="primary" size="sm" onClick={() => setNewBox(true)}>
|
|
137
|
+
<Plus className="h-3.5 w-3.5" />
|
|
138
|
+
{t("mail.newMailbox")}
|
|
139
|
+
</Button>
|
|
140
|
+
</div>
|
|
141
|
+
}
|
|
142
|
+
>
|
|
143
|
+
|
|
144
|
+
<MailTabs tab={tab} onTabChange={setTab} />
|
|
145
|
+
|
|
146
|
+
{tab === "mail" && (
|
|
147
|
+
<div className="space-y-4">
|
|
148
|
+
{boxes.length === 0 && <MailGuide />}
|
|
149
|
+
|
|
150
|
+
<MailboxBar
|
|
151
|
+
boxes={boxes}
|
|
152
|
+
active={active}
|
|
153
|
+
totalUnread={totalUnread}
|
|
154
|
+
activeBox={activeBox}
|
|
155
|
+
onSelect={setActive}
|
|
156
|
+
onEdit={setEditBox}
|
|
157
|
+
/>
|
|
158
|
+
|
|
159
|
+
<FolderNav currentFolder={folder} onSelectFolder={(f) => { setFolder(f); setOpen(null); }} />
|
|
160
|
+
|
|
161
|
+
<div className="grid min-h-0 grid-cols-1 gap-6 lg:grid-cols-[360px_1fr]">
|
|
162
|
+
<EmailListPane
|
|
163
|
+
emails={emails}
|
|
164
|
+
loading={loading}
|
|
165
|
+
folder={folder}
|
|
166
|
+
q={q}
|
|
167
|
+
onSearchChange={setQ}
|
|
168
|
+
openEmailId={open?.id}
|
|
169
|
+
onOpenEmail={openEmail}
|
|
170
|
+
onScroll={handleScroll}
|
|
171
|
+
boxes={boxes}
|
|
172
|
+
activeMailboxId={active}
|
|
173
|
+
onNewBox={() => setNewBox(true)}
|
|
174
|
+
/>
|
|
175
|
+
|
|
176
|
+
<div className="h-full w-full">
|
|
177
|
+
{open ? (
|
|
178
|
+
<EmailViewForm
|
|
179
|
+
email={open}
|
|
180
|
+
onClose={() => setOpen(null)}
|
|
181
|
+
onReply={(d) => { setOpen(null); setCompose(d); }}
|
|
182
|
+
onEditDraft={(d) => { setOpen(null); setCompose(d); }}
|
|
183
|
+
onChanged={() => { loadEmails(true); loadBoxes(); }}
|
|
184
|
+
/>
|
|
185
|
+
) : (
|
|
186
|
+
<div className="flex min-h-[420px] flex-col items-center justify-center gap-3 rounded-lg border border-dashed border-border bg-well px-6 py-16 text-center">
|
|
187
|
+
<div className="flex h-12 w-12 items-center justify-center rounded-lg border border-border bg-card text-accent-fg">
|
|
188
|
+
<Inbox className="h-5 w-5" />
|
|
189
|
+
</div>
|
|
190
|
+
<p className="font-display text-[13px] text-foreground">{t("mail.selectEmail")}</p>
|
|
191
|
+
</div>
|
|
192
|
+
)}
|
|
193
|
+
</div>
|
|
194
|
+
</div>
|
|
195
|
+
</div>
|
|
196
|
+
)}
|
|
197
|
+
|
|
198
|
+
{tab === "inbound" && <MailSettings />}
|
|
199
|
+
{tab === "smtp" && <SMTPSenders />}
|
|
200
|
+
{tab === "suppressions" && <SuppressionList />}
|
|
201
|
+
|
|
202
|
+
{newBox && <MailboxEditor box={null} hosts={mailHostOptions} onClose={() => setNewBox(false)} onSaved={() => { setNewBox(false); loadBoxes(); }} />}
|
|
203
|
+
{editBox && <MailboxEditor box={editBox} hosts={mailHostOptions} onClose={() => setEditBox(null)} onSaved={() => { setEditBox(null); loadBoxes(); loadEmails(true); }} />}
|
|
204
|
+
{compose && (
|
|
205
|
+
<Compose
|
|
206
|
+
draft={compose === true ? undefined : compose}
|
|
207
|
+
onClose={() => setCompose(null)}
|
|
208
|
+
onDraftSaved={() => { loadEmails(true); }}
|
|
209
|
+
/>
|
|
210
|
+
)}
|
|
211
|
+
</PageShell>
|
|
212
|
+
);
|
|
213
|
+
}
|
|
@@ -0,0 +1,254 @@
|
|
|
1
|
+
// @vitest-environment happy-dom
|
|
2
|
+
import { describe, it, expect, vi, beforeEach, afterEach } from "vitest";
|
|
3
|
+
import { cleanup, render, screen, waitFor, fireEvent } from "@testing-library/react";
|
|
4
|
+
import { MemoryRouter } from "react-router-dom";
|
|
5
|
+
import { ConfirmProvider, RoleProvider, I18nProvider, registerUIPlugin, resetRegistry } from "@octarq/plugin-sdk";
|
|
6
|
+
import mailPlugin from "../index";
|
|
7
|
+
import { Compose } from "./Compose";
|
|
8
|
+
import { EmailViewForm } from "./EmailView";
|
|
9
|
+
import { FolderNav } from "./FolderNav";
|
|
10
|
+
import { EmailListItem } from "./EmailListItem";
|
|
11
|
+
import { Email } from "../api";
|
|
12
|
+
|
|
13
|
+
function jsonResponse(body: unknown, status = 200) {
|
|
14
|
+
return {
|
|
15
|
+
ok: status >= 200 && status < 300,
|
|
16
|
+
status,
|
|
17
|
+
json: async () => body,
|
|
18
|
+
headers: { get: (name: string) => (name === "content-type" ? "application/json" : null) },
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function renderWithProviders(ui: React.ReactElement) {
|
|
23
|
+
return render(
|
|
24
|
+
<MemoryRouter>
|
|
25
|
+
<I18nProvider>
|
|
26
|
+
<RoleProvider value={{ role: "admin", isInstanceAdmin: true }}>
|
|
27
|
+
<ConfirmProvider>{ui}</ConfirmProvider>
|
|
28
|
+
</RoleProvider>
|
|
29
|
+
</I18nProvider>
|
|
30
|
+
</MemoryRouter>
|
|
31
|
+
);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
describe("Mail Enhancements", () => {
|
|
35
|
+
let fetchMock: ReturnType<typeof vi.fn>;
|
|
36
|
+
|
|
37
|
+
beforeEach(() => {
|
|
38
|
+
cleanup();
|
|
39
|
+
resetRegistry();
|
|
40
|
+
registerUIPlugin(mailPlugin);
|
|
41
|
+
|
|
42
|
+
fetchMock = vi.fn(async (input: RequestInfo | URL, init?: RequestInit) => {
|
|
43
|
+
const method = (init?.method ?? "GET").toUpperCase();
|
|
44
|
+
const rawUrl = typeof input === "string" ? input : input instanceof URL ? input.toString() : (input as Request).url;
|
|
45
|
+
const urlObj = new URL(rawUrl, "http://localhost");
|
|
46
|
+
const path = urlObj.pathname;
|
|
47
|
+
|
|
48
|
+
if (method === "GET" && path === "/api/smtp-senders") {
|
|
49
|
+
return jsonResponse([]);
|
|
50
|
+
}
|
|
51
|
+
if (method === "GET" && path === "/api/settings") {
|
|
52
|
+
return jsonResponse({});
|
|
53
|
+
}
|
|
54
|
+
if (method === "GET" && path === "/api/mail/contacts") {
|
|
55
|
+
return jsonResponse([
|
|
56
|
+
{ id: 1, address: "contact@example.com", name: "Key Contact", interactionCount: 5, lastSeenAt: "2026-08-31T00:00:00Z" },
|
|
57
|
+
]);
|
|
58
|
+
}
|
|
59
|
+
if (method === "POST" && path === "/api/mail/drafts") {
|
|
60
|
+
return jsonResponse({
|
|
61
|
+
id: 99,
|
|
62
|
+
to: "draft@example.com",
|
|
63
|
+
subject: "Saved Draft Subject",
|
|
64
|
+
text: "Saved body",
|
|
65
|
+
folder: "drafts",
|
|
66
|
+
read: true,
|
|
67
|
+
receivedAt: new Date().toISOString(),
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
if (method === "GET" && path === "/api/ai-assist/status") {
|
|
71
|
+
return jsonResponse({ configured: false });
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
throw new Error(`Unhandled fetch in test: ${method} ${rawUrl}`);
|
|
75
|
+
});
|
|
76
|
+
vi.stubGlobal("fetch", fetchMock);
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
afterEach(() => {
|
|
80
|
+
cleanup();
|
|
81
|
+
vi.restoreAllMocks();
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
it("renders unsubscribe button and handles click in EmailViewForm", async () => {
|
|
85
|
+
const mockEmail: Email = {
|
|
86
|
+
id: 42,
|
|
87
|
+
mailboxId: 1,
|
|
88
|
+
from: "newsletter@promo.com",
|
|
89
|
+
to: "user@example.com",
|
|
90
|
+
subject: "Special Offer",
|
|
91
|
+
text: "Check out this offer!",
|
|
92
|
+
html: "",
|
|
93
|
+
unsubscribeUrl: "https://promo.com/unsub/token123",
|
|
94
|
+
read: true,
|
|
95
|
+
note: "",
|
|
96
|
+
attachments: "[]",
|
|
97
|
+
authSpf: "pass",
|
|
98
|
+
authDkim: "pass",
|
|
99
|
+
authDmarc: "pass",
|
|
100
|
+
receivedAt: "2026-08-31T10:00:00Z",
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
const windowOpenSpy = vi.spyOn(window, "open").mockImplementation(() => null);
|
|
104
|
+
|
|
105
|
+
renderWithProviders(
|
|
106
|
+
<EmailViewForm
|
|
107
|
+
email={mockEmail}
|
|
108
|
+
onClose={vi.fn()}
|
|
109
|
+
onReply={vi.fn()}
|
|
110
|
+
onChanged={vi.fn()}
|
|
111
|
+
/>
|
|
112
|
+
);
|
|
113
|
+
|
|
114
|
+
const unsubButtons = screen.getAllByRole("button", { name: "Unsubscribe" });
|
|
115
|
+
expect(unsubButtons.length).toBeGreaterThan(0);
|
|
116
|
+
fireEvent.click(unsubButtons[0]);
|
|
117
|
+
|
|
118
|
+
expect(windowOpenSpy).toHaveBeenCalledWith("https://promo.com/unsub/token123", "_blank", "noopener,noreferrer");
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
it("saves draft and selects contacts in Compose", async () => {
|
|
122
|
+
const onDraftSaved = vi.fn();
|
|
123
|
+
renderWithProviders(
|
|
124
|
+
<Compose
|
|
125
|
+
onClose={vi.fn()}
|
|
126
|
+
onDraftSaved={onDraftSaved}
|
|
127
|
+
/>
|
|
128
|
+
);
|
|
129
|
+
|
|
130
|
+
// Typing in To should load contact suggestions
|
|
131
|
+
const toInput = screen.getByPlaceholderText("hello@world.com");
|
|
132
|
+
fireEvent.focus(toInput);
|
|
133
|
+
|
|
134
|
+
await waitFor(() => {
|
|
135
|
+
expect(screen.getByText("Key Contact <contact@example.com>")).toBeDefined();
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
fireEvent.mouseDown(screen.getByText("Key Contact <contact@example.com>"));
|
|
139
|
+
expect((toInput as HTMLInputElement).value).toBe("contact@example.com");
|
|
140
|
+
|
|
141
|
+
// Click Save Draft
|
|
142
|
+
const saveDraftBtn = screen.getByRole("button", { name: "Save draft" });
|
|
143
|
+
fireEvent.click(saveDraftBtn);
|
|
144
|
+
|
|
145
|
+
await waitFor(() => {
|
|
146
|
+
expect(onDraftSaved).toHaveBeenCalledTimes(1);
|
|
147
|
+
});
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
it("switches folders in FolderNav", async () => {
|
|
151
|
+
const onSelect = vi.fn();
|
|
152
|
+
renderWithProviders(
|
|
153
|
+
<FolderNav currentFolder="inbox" onSelectFolder={onSelect} />
|
|
154
|
+
);
|
|
155
|
+
|
|
156
|
+
expect(screen.getByText("Inbox")).toBeDefined();
|
|
157
|
+
expect(screen.getByText("Sent")).toBeDefined();
|
|
158
|
+
expect(screen.getByText("Drafts")).toBeDefined();
|
|
159
|
+
expect(screen.getByText("Trash")).toBeDefined();
|
|
160
|
+
expect(screen.getByText("Spam")).toBeDefined();
|
|
161
|
+
|
|
162
|
+
fireEvent.click(screen.getByText("Drafts"));
|
|
163
|
+
expect(onSelect).toHaveBeenCalledWith("drafts");
|
|
164
|
+
});
|
|
165
|
+
|
|
166
|
+
it("renders 1-Click OTP copy bar in EmailViewForm and copies code", async () => {
|
|
167
|
+
const mockEmailWithOtp: Email = {
|
|
168
|
+
id: 99,
|
|
169
|
+
mailboxId: 1,
|
|
170
|
+
from: "security@auth.com",
|
|
171
|
+
to: "user@example.com",
|
|
172
|
+
subject: "Your login code is 849201",
|
|
173
|
+
text: "Use code 849201 to verify.",
|
|
174
|
+
html: "",
|
|
175
|
+
otp: "849201",
|
|
176
|
+
category: "otp",
|
|
177
|
+
summary: "One-time security verification passcode.",
|
|
178
|
+
importance: 5,
|
|
179
|
+
read: true,
|
|
180
|
+
note: "",
|
|
181
|
+
attachments: "[]",
|
|
182
|
+
authSpf: "pass",
|
|
183
|
+
authDkim: "pass",
|
|
184
|
+
authDmarc: "pass",
|
|
185
|
+
receivedAt: "2026-10-24T12:00:00Z",
|
|
186
|
+
};
|
|
187
|
+
|
|
188
|
+
let copiedText = "";
|
|
189
|
+
Object.defineProperty(navigator, "clipboard", {
|
|
190
|
+
value: {
|
|
191
|
+
writeText: vi.fn().mockImplementation(async (text: string) => {
|
|
192
|
+
copiedText = text;
|
|
193
|
+
}),
|
|
194
|
+
},
|
|
195
|
+
configurable: true,
|
|
196
|
+
writable: true,
|
|
197
|
+
});
|
|
198
|
+
|
|
199
|
+
renderWithProviders(
|
|
200
|
+
<EmailViewForm
|
|
201
|
+
email={mockEmailWithOtp}
|
|
202
|
+
onClose={vi.fn()}
|
|
203
|
+
onReply={vi.fn()}
|
|
204
|
+
onChanged={vi.fn()}
|
|
205
|
+
/>
|
|
206
|
+
);
|
|
207
|
+
|
|
208
|
+
const otpBar = screen.getByTestId("otp-copy-bar");
|
|
209
|
+
expect(otpBar).toBeDefined();
|
|
210
|
+
expect(screen.getByText("849201")).toBeDefined();
|
|
211
|
+
|
|
212
|
+
const copyBtn = screen.getByRole("button", { name: "Copy Code" });
|
|
213
|
+
fireEvent.click(copyBtn);
|
|
214
|
+
|
|
215
|
+
expect(copiedText).toBe("849201");
|
|
216
|
+
expect(screen.getByText("One-time security verification passcode.")).toBeDefined();
|
|
217
|
+
});
|
|
218
|
+
|
|
219
|
+
it("renders AI category badge, summary preview, and importance dots in EmailListItem", () => {
|
|
220
|
+
const mockEmailItem: Email = {
|
|
221
|
+
id: 55,
|
|
222
|
+
mailboxId: 1,
|
|
223
|
+
from: "billing@acme.com",
|
|
224
|
+
to: "user@example.com",
|
|
225
|
+
subject: "Monthly Subscription Invoice",
|
|
226
|
+
text: "Your invoice for $49 is ready.",
|
|
227
|
+
html: "",
|
|
228
|
+
category: "bill",
|
|
229
|
+
summary: "Monthly platform subscription invoice for $49.",
|
|
230
|
+
importance: 4,
|
|
231
|
+
read: false,
|
|
232
|
+
note: "",
|
|
233
|
+
attachments: "[]",
|
|
234
|
+
authSpf: "pass",
|
|
235
|
+
authDkim: "pass",
|
|
236
|
+
authDmarc: "pass",
|
|
237
|
+
receivedAt: "2026-10-24T10:00:00Z",
|
|
238
|
+
};
|
|
239
|
+
|
|
240
|
+
renderWithProviders(
|
|
241
|
+
<EmailListItem
|
|
242
|
+
email={mockEmailItem}
|
|
243
|
+
folder="inbox"
|
|
244
|
+
isSelected={false}
|
|
245
|
+
onSelect={vi.fn()}
|
|
246
|
+
/>
|
|
247
|
+
);
|
|
248
|
+
|
|
249
|
+
expect(screen.getByText("Bill")).toBeDefined();
|
|
250
|
+
expect(screen.getByText("Monthly platform subscription invoice for $49.")).toBeDefined();
|
|
251
|
+
expect(screen.getByTestId("importance-dots")).toBeDefined();
|
|
252
|
+
expect(screen.getByTestId("importance-dots").textContent).toBe("●●●●○");
|
|
253
|
+
});
|
|
254
|
+
});
|
package/pages/types.ts
ADDED
package/tsconfig.json
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "ES2020",
|
|
4
|
+
"lib": ["ES2020", "DOM", "DOM.Iterable"],
|
|
5
|
+
"module": "ESNext",
|
|
6
|
+
"moduleResolution": "bundler",
|
|
7
|
+
"jsx": "react-jsx",
|
|
8
|
+
"strict": true,
|
|
9
|
+
"skipLibCheck": true,
|
|
10
|
+
"noEmit": true,
|
|
11
|
+
"allowImportingTsExtensions": true
|
|
12
|
+
},
|
|
13
|
+
"include": ["."],
|
|
14
|
+
"exclude": ["**/*.test.ts", "**/*.test.tsx"]
|
|
15
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { useEffect, useState } from "react";
|
|
2
|
+
import { useNavigate } from "react-router-dom";
|
|
3
|
+
import { SetupStep, useOverviewData, useTranslation } from "@octarq/plugin-sdk";
|
|
4
|
+
import { mailApi } from "../api";
|
|
5
|
+
|
|
6
|
+
export default function MailSetupStepWidget() {
|
|
7
|
+
const o = useOverviewData();
|
|
8
|
+
const [smtpCount, setSmtpCount] = useState<number | null>(null);
|
|
9
|
+
const nav = useNavigate();
|
|
10
|
+
const { t } = useTranslation();
|
|
11
|
+
|
|
12
|
+
useEffect(() => {
|
|
13
|
+
if (!o || o.mailboxes === undefined) return;
|
|
14
|
+
let cancelled = false;
|
|
15
|
+
(async () => {
|
|
16
|
+
try {
|
|
17
|
+
// Core Vault owns mail senders when it is mounted. Count the
|
|
18
|
+
// same registry the mail pages offer, not just the local table.
|
|
19
|
+
const res = await fetch("/api/vault/items?provider_type=communication", {
|
|
20
|
+
credentials: "same-origin",
|
|
21
|
+
});
|
|
22
|
+
if (res.status === 404) {
|
|
23
|
+
const list = await mailApi.smtpSenders();
|
|
24
|
+
if (!cancelled) setSmtpCount(list.length);
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
if (!res.ok) return;
|
|
28
|
+
const data = await res.json();
|
|
29
|
+
const raw = Array.isArray(data) ? data : (data?.body ?? []);
|
|
30
|
+
const list = (Array.isArray(raw) ? raw : []).filter(
|
|
31
|
+
(item: any) => item.provider === "smtp" || item.provider === "resend"
|
|
32
|
+
);
|
|
33
|
+
if (!cancelled) setSmtpCount(list.length);
|
|
34
|
+
} catch {
|
|
35
|
+
// Leave the step in the unknown state instead of reporting zero.
|
|
36
|
+
}
|
|
37
|
+
})();
|
|
38
|
+
return () => {
|
|
39
|
+
cancelled = true;
|
|
40
|
+
};
|
|
41
|
+
}, [o]);
|
|
42
|
+
|
|
43
|
+
if (!o || o.mailboxes === undefined) return null;
|
|
44
|
+
|
|
45
|
+
const completed = smtpCount !== null && smtpCount > 0;
|
|
46
|
+
|
|
47
|
+
return (
|
|
48
|
+
<SetupStep
|
|
49
|
+
title={t("overview.stepSmtpTitle")}
|
|
50
|
+
description={t("overview.stepSmtpDesc")}
|
|
51
|
+
completed={completed}
|
|
52
|
+
onClick={() => nav("/mail?tab=settings")}
|
|
53
|
+
/>
|
|
54
|
+
);
|
|
55
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { StatCard, useOverviewData, useTranslation } from "@octarq/plugin-sdk";
|
|
2
|
+
import { useNavigate } from "react-router-dom";
|
|
3
|
+
import { Mail } from "lucide-react";
|
|
4
|
+
|
|
5
|
+
export default function MailStatCardWidget() {
|
|
6
|
+
const o = useOverviewData();
|
|
7
|
+
const nav = useNavigate();
|
|
8
|
+
const { t } = useTranslation();
|
|
9
|
+
|
|
10
|
+
if (!o || o.mailboxes === undefined) return null;
|
|
11
|
+
|
|
12
|
+
return (
|
|
13
|
+
<StatCard
|
|
14
|
+
label={t("overview.mailboxes")}
|
|
15
|
+
value={(o.mailboxes ?? 0).toLocaleString()}
|
|
16
|
+
delta={t("overview.unread", { count: o.unread ?? 0 })}
|
|
17
|
+
icon={<Mail className="h-4 w-4" />}
|
|
18
|
+
onClick={() => nav("/mail")}
|
|
19
|
+
index={2}
|
|
20
|
+
/>
|
|
21
|
+
);
|
|
22
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { Panel, timeAgo, useOverviewData, useTranslation } from "@octarq/plugin-sdk";
|
|
2
|
+
import { useNavigate } from "react-router-dom";
|
|
3
|
+
|
|
4
|
+
export default function RecentMailPanelWidget() {
|
|
5
|
+
const o = useOverviewData();
|
|
6
|
+
const nav = useNavigate();
|
|
7
|
+
const { t } = useTranslation();
|
|
8
|
+
|
|
9
|
+
if (!o || o.recentEmails === undefined) return null;
|
|
10
|
+
|
|
11
|
+
const recentEmails = o.recentEmails as { id: number; from: string; subject: string; read: boolean; receivedAt: string }[] | null;
|
|
12
|
+
|
|
13
|
+
return (
|
|
14
|
+
<Panel title={t("mail.recentMail")}>
|
|
15
|
+
{!recentEmails || recentEmails.length === 0 ? (
|
|
16
|
+
<p className="text-sm text-muted-foreground">{t("mail.noMail")}</p>
|
|
17
|
+
) : (
|
|
18
|
+
<div className="divide-y divide-border">
|
|
19
|
+
{recentEmails.map((e) => (
|
|
20
|
+
<button
|
|
21
|
+
key={e.id}
|
|
22
|
+
onClick={() => nav("/mail")}
|
|
23
|
+
className="flex w-full items-center gap-3 px-3 py-2.5 text-left hover:bg-surface-hover transition-colors"
|
|
24
|
+
>
|
|
25
|
+
{!e.read && <span className="h-2 w-2 shrink-0 rounded-full bg-primary" />}
|
|
26
|
+
<span className={`w-40 shrink-0 truncate text-sm ${e.read ? "text-muted-foreground" : "font-semibold"}`}>
|
|
27
|
+
{e.from || t("mail.unknownSender")}
|
|
28
|
+
</span>
|
|
29
|
+
<span className="flex-1 truncate text-sm text-muted-foreground">{e.subject || t("mail.noSubject")}</span>
|
|
30
|
+
<span className="shrink-0 text-xs text-muted-foreground">{timeAgo(e.receivedAt)}</span>
|
|
31
|
+
</button>
|
|
32
|
+
))}
|
|
33
|
+
</div>
|
|
34
|
+
)}
|
|
35
|
+
</Panel>
|
|
36
|
+
);
|
|
37
|
+
}
|
package/README.md
DELETED