@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
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import { Code, Field, Input, Textarea, Guide, Modal, Switch, timeAgo, Badge, Button, Select, Alert, confirmDialog, FormError, useTranslation, roleSatisfies, useCurrentRole } from "@octarq/plugin-sdk";
|
|
2
|
+
import { useEffect, useState } from "react";
|
|
3
|
+
import { useSearchParams } from "react-router-dom";
|
|
4
|
+
import { mailApi, Attachment, Email, Mailbox } from "../api";
|
|
5
|
+
import { Inbox, Send, Plus, CheckCircle, Mail as MailIcon, Paperclip, Settings, Trash2, Reply, Download, X, AlertTriangle } from "lucide-react";
|
|
6
|
+
import { MailSettings } from "./MailSettings";
|
|
7
|
+
import { SMTPSenders } from "./SMTPSenders";
|
|
8
|
+
|
|
9
|
+
export function MailboxEditor({
|
|
10
|
+
box,
|
|
11
|
+
hosts,
|
|
12
|
+
onClose,
|
|
13
|
+
onSaved,
|
|
14
|
+
}: {
|
|
15
|
+
box: Mailbox | null;
|
|
16
|
+
hosts: string[];
|
|
17
|
+
onClose: () => void;
|
|
18
|
+
onSaved: () => void;
|
|
19
|
+
}) {
|
|
20
|
+
const { t } = useTranslation();
|
|
21
|
+
const { role, isInstanceAdmin } = useCurrentRole();
|
|
22
|
+
const canDeleteBox = roleSatisfies("admin", role, isInstanceAdmin);
|
|
23
|
+
const [prefix, setPrefix] = useState("");
|
|
24
|
+
const [domain, setDomain] = useState(hosts[0] ?? "");
|
|
25
|
+
const [note, setNote] = useState(box?.note ?? "");
|
|
26
|
+
const [enabled, setEnabled] = useState(box?.enabled ?? true);
|
|
27
|
+
const [err, setErr] = useState<string | { message?: string; status?: number; requestId?: string }>("");
|
|
28
|
+
|
|
29
|
+
useEffect(() => {
|
|
30
|
+
if (hosts.length > 0 && !domain) setDomain(hosts[0]);
|
|
31
|
+
}, [hosts]);
|
|
32
|
+
|
|
33
|
+
async function save() {
|
|
34
|
+
setErr("");
|
|
35
|
+
try {
|
|
36
|
+
if (box) {
|
|
37
|
+
await mailApi.updateMailbox(box.id, { note, enabled });
|
|
38
|
+
} else {
|
|
39
|
+
if (!prefix.trim() || !domain) return setErr(t("mail.prefixDomainRequired"));
|
|
40
|
+
await mailApi.createMailbox({ address: `${prefix.trim()}@${domain}`, note, enabled });
|
|
41
|
+
}
|
|
42
|
+
onSaved();
|
|
43
|
+
} catch (e: any) {
|
|
44
|
+
setErr(e);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
return (
|
|
49
|
+
<Modal title={box ? t("mail.editMailbox") : t("mail.createMailbox")} onClose={onClose}>
|
|
50
|
+
<div className="space-y-4">
|
|
51
|
+
{box ? (
|
|
52
|
+
<Field label={t("mail.mailboxAddress")}>
|
|
53
|
+
<Input className="font-mono text-sm" value={box.address} disabled />
|
|
54
|
+
</Field>
|
|
55
|
+
) : hosts.length === 0 ? (
|
|
56
|
+
<Alert variant="warning" className="p-3 text-xs flex items-center gap-1.5 font-normal">
|
|
57
|
+
<AlertTriangle className="h-4 w-4" />
|
|
58
|
+
{t("mail.noHosts")}
|
|
59
|
+
</Alert>
|
|
60
|
+
) : (
|
|
61
|
+
<Field label={t("mail.mailboxPrefix")} hint={t("mail.prefixHint")}>
|
|
62
|
+
<div className="flex items-center gap-2">
|
|
63
|
+
<Input
|
|
64
|
+
className="font-mono text-sm"
|
|
65
|
+
value={prefix}
|
|
66
|
+
onChange={(e) => setPrefix(e.target.value)}
|
|
67
|
+
placeholder={t("mail.prefixPlaceholder")}
|
|
68
|
+
autoFocus
|
|
69
|
+
/>
|
|
70
|
+
<span className="text-muted-foreground">@</span>
|
|
71
|
+
<div className="min-w-0 flex-1">
|
|
72
|
+
<Select
|
|
73
|
+
className="text-sm"
|
|
74
|
+
value={domain}
|
|
75
|
+
onValueChange={setDomain}
|
|
76
|
+
options={hosts.map((h) => ({ value: h, label: h }))}
|
|
77
|
+
/>
|
|
78
|
+
</div>
|
|
79
|
+
</div>
|
|
80
|
+
</Field>
|
|
81
|
+
)}
|
|
82
|
+
<Field label={t("mail.noteMemo")}>
|
|
83
|
+
<Textarea className="text-sm" rows={2} value={note} onChange={(e) => setNote(e.target.value)} placeholder={t("mail.noteMemoPlaceholder")} />
|
|
84
|
+
</Field>
|
|
85
|
+
<div className="flex items-center gap-3 py-1">
|
|
86
|
+
<Switch checked={enabled} onCheckedChange={setEnabled} aria-label={t("mail.mailReceivingEnabled")} />
|
|
87
|
+
<span className="text-sm text-muted-foreground select-none">{t("mail.mailReceivingEnabled")}</span>
|
|
88
|
+
</div>
|
|
89
|
+
{canDeleteBox && box && (
|
|
90
|
+
<Button
|
|
91
|
+
variant="danger"
|
|
92
|
+
onClick={async () => {
|
|
93
|
+
if (await confirmDialog(t("mail.deleteMailboxConfirm", { address: box.address }))) {
|
|
94
|
+
await mailApi.deleteMailbox(box.id);
|
|
95
|
+
onSaved();
|
|
96
|
+
}
|
|
97
|
+
}}
|
|
98
|
+
className="text-xs py-1.5 border-0 mt-2"
|
|
99
|
+
>
|
|
100
|
+
{t("mail.deleteMailboxCompletely")}
|
|
101
|
+
</Button>
|
|
102
|
+
)}
|
|
103
|
+
{err && <FormError err={err} />}
|
|
104
|
+
<div className="flex justify-end gap-2.5 pt-4 border-t border-border">
|
|
105
|
+
<Button variant="ghost" onClick={onClose}>
|
|
106
|
+
{t("mail.cancel")}
|
|
107
|
+
</Button>
|
|
108
|
+
<Button variant="primary" onClick={save}>
|
|
109
|
+
{t("mail.saveConfiguration")}
|
|
110
|
+
</Button>
|
|
111
|
+
</div>
|
|
112
|
+
</div>
|
|
113
|
+
</Modal>
|
|
114
|
+
);
|
|
115
|
+
}
|
|
116
|
+
|
|
@@ -0,0 +1,323 @@
|
|
|
1
|
+
import { Empty, Field, Input, Modal, Badge, StatusBadge, Button, PageSection, PageRows, Separator, Skeleton, toast, confirmDialog, FormError, useTranslation, roleSatisfies, useCurrentRole } from "@octarq/plugin-sdk";
|
|
2
|
+
import { Fragment, useEffect, useState } from "react";
|
|
3
|
+
import { NavLink } from "react-router-dom";
|
|
4
|
+
import { mailApi, SMTPSender } from "../api";
|
|
5
|
+
import { KeyRound, Send, Blocks } from "lucide-react";
|
|
6
|
+
|
|
7
|
+
// Which registry owns the sender rows. An instance with Core Vault
|
|
8
|
+
// mounted uses vault items; a standalone instance without vault uses
|
|
9
|
+
// the local mail_smtp_senders table. The two registries number rows
|
|
10
|
+
// independently, so a page must read exactly one of them.
|
|
11
|
+
type SenderMode = "integration" | "local" | null;
|
|
12
|
+
|
|
13
|
+
function formatIntegrationSenderSummary(s: any): string {
|
|
14
|
+
const fromEmail = s.metadata?.fromEmail || s.fromEmail;
|
|
15
|
+
const host = s.metadata?.smtpHost || s.host;
|
|
16
|
+
const port = s.metadata?.smtpPort || s.port || 587;
|
|
17
|
+
if (fromEmail && host) return `${fromEmail} via ${host}:${port}`;
|
|
18
|
+
if (s.summary) return s.summary;
|
|
19
|
+
if (fromEmail) return fromEmail;
|
|
20
|
+
if (host) return `${host}:${port}`;
|
|
21
|
+
return s.metadata?.fromName || s.provider || s.name || "";
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export function SMTPSenders() {
|
|
25
|
+
const { t } = useTranslation();
|
|
26
|
+
const { role, isInstanceAdmin } = useCurrentRole();
|
|
27
|
+
const canManageSMTP = roleSatisfies("admin", role, isInstanceAdmin);
|
|
28
|
+
const [mode, setMode] = useState<SenderMode>(null);
|
|
29
|
+
const [senders, setSenders] = useState<any[]>([]);
|
|
30
|
+
const [loading, setLoading] = useState(true);
|
|
31
|
+
const [creating, setCreating] = useState(false);
|
|
32
|
+
const [editing, setEditing] = useState<any | null>(null);
|
|
33
|
+
const [testingId, setTestingId] = useState<number | null>(null);
|
|
34
|
+
|
|
35
|
+
async function load() {
|
|
36
|
+
setLoading(true);
|
|
37
|
+
try {
|
|
38
|
+
const res = await fetch("/api/vault/items?provider_type=communication", {
|
|
39
|
+
credentials: "same-origin",
|
|
40
|
+
});
|
|
41
|
+
if (res.status === 404) {
|
|
42
|
+
setMode("local");
|
|
43
|
+
setSenders(await mailApi.smtpSenders());
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
if (!res.ok) {
|
|
47
|
+
setMode(null);
|
|
48
|
+
setSenders([]);
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
const data = await res.json();
|
|
52
|
+
const raw = Array.isArray(data) ? data : (data?.body ?? []);
|
|
53
|
+
setMode("integration");
|
|
54
|
+
setSenders(
|
|
55
|
+
(Array.isArray(raw) ? raw : []).filter(
|
|
56
|
+
(item: any) => item.provider === "smtp" || item.provider === "resend"
|
|
57
|
+
)
|
|
58
|
+
);
|
|
59
|
+
} catch {
|
|
60
|
+
setMode(null);
|
|
61
|
+
setSenders([]);
|
|
62
|
+
} finally {
|
|
63
|
+
setLoading(false);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
useEffect(() => { load(); }, []);
|
|
67
|
+
|
|
68
|
+
async function remove(id: number) {
|
|
69
|
+
if (!(await confirmDialog(t("settings.confirmRemoveSmtp")))) return;
|
|
70
|
+
try {
|
|
71
|
+
await mailApi.deleteSMTPSender(id);
|
|
72
|
+
load();
|
|
73
|
+
} catch (e: any) {
|
|
74
|
+
toast.error(e.message || t("settings.failedRemove"));
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
async function test(sender: any) {
|
|
79
|
+
setTestingId(sender.id);
|
|
80
|
+
try {
|
|
81
|
+
if (mode === "local") {
|
|
82
|
+
await mailApi.testSMTPSender(sender.id);
|
|
83
|
+
toast.success(t("settings.smtpTestSent", { to: sender.fromEmail }));
|
|
84
|
+
} else {
|
|
85
|
+
const res = await fetch(`/api/vault/items/${sender.id}/test`, {
|
|
86
|
+
method: "POST",
|
|
87
|
+
credentials: "same-origin",
|
|
88
|
+
});
|
|
89
|
+
const data = await res.json().catch(() => ({}));
|
|
90
|
+
if (!res.ok || data.ok === false) {
|
|
91
|
+
throw new Error(data.detail || data.message || "Connection test failed");
|
|
92
|
+
}
|
|
93
|
+
toast.success(data.message || t("settings.smtpTestSent", { to: sender.name }));
|
|
94
|
+
}
|
|
95
|
+
} catch (e: any) {
|
|
96
|
+
toast.error(t("settings.testFailed", { msg: e?.message || "unknown error" }));
|
|
97
|
+
} finally {
|
|
98
|
+
setTestingId(null);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
return (
|
|
103
|
+
<PageSection
|
|
104
|
+
className="mt-0"
|
|
105
|
+
title={t("settings.smtpOutgoingGateways")}
|
|
106
|
+
description={t("settings.smtpOutgoingGatewaysDesc")}
|
|
107
|
+
action={
|
|
108
|
+
canManageSMTP && mode === "local" ? (
|
|
109
|
+
<Button variant="primary" className="text-xs py-1 px-2.5" onClick={() => setCreating(true)}>
|
|
110
|
+
{t("settings.addSmtp")}
|
|
111
|
+
</Button>
|
|
112
|
+
) : canManageSMTP && mode === "integration" ? (
|
|
113
|
+
<NavLink to="/settings/integrations?category=communication">
|
|
114
|
+
<Button variant="primary" className="text-xs py-1 px-2.5">
|
|
115
|
+
{t("settings.openIntegrationsHub")}
|
|
116
|
+
</Button>
|
|
117
|
+
</NavLink>
|
|
118
|
+
) : null
|
|
119
|
+
}
|
|
120
|
+
>
|
|
121
|
+
|
|
122
|
+
{mode === "integration" && (
|
|
123
|
+
<div className="mt-3 flex items-center justify-between p-3 rounded-lg border border-primary/20 bg-accent-soft text-xs text-foreground">
|
|
124
|
+
<div className="flex items-center gap-2">
|
|
125
|
+
<Blocks className="h-4 w-4 text-accent-fg shrink-0" />
|
|
126
|
+
<span>{t("settings.integrationsHubBanner")}</span>
|
|
127
|
+
</div>
|
|
128
|
+
<NavLink
|
|
129
|
+
to="/settings/integrations?category=communication"
|
|
130
|
+
className="ml-3 inline-flex min-h-8 items-center whitespace-nowrap text-xs font-medium text-accent-fg hover:underline"
|
|
131
|
+
>
|
|
132
|
+
{t("settings.openIntegrationsHub")} →
|
|
133
|
+
</NavLink>
|
|
134
|
+
</div>
|
|
135
|
+
)}
|
|
136
|
+
|
|
137
|
+
{loading ? (
|
|
138
|
+
<div role="status" aria-busy="true" aria-label={t("settings.loadingLower")}>
|
|
139
|
+
<PageRows>
|
|
140
|
+
{Array.from({ length: 3 }).map((_, i) => (
|
|
141
|
+
<Fragment key={i}>
|
|
142
|
+
{i > 0 && <Separator />}
|
|
143
|
+
<div
|
|
144
|
+
data-slot="page-row"
|
|
145
|
+
className="flex min-h-[var(--row-height,3.5rem)] items-center justify-between gap-4 px-4 py-3"
|
|
146
|
+
>
|
|
147
|
+
<div className="flex-1 space-y-1.5">
|
|
148
|
+
<div className="flex items-center gap-2">
|
|
149
|
+
<Skeleton className="h-4 w-36" />
|
|
150
|
+
<Skeleton className="h-4 w-16 rounded-full" />
|
|
151
|
+
</div>
|
|
152
|
+
<Skeleton className="h-3 w-56" />
|
|
153
|
+
</div>
|
|
154
|
+
<div className="flex shrink-0 items-center gap-2">
|
|
155
|
+
<Skeleton className="h-7 w-14 rounded-lg" />
|
|
156
|
+
<Skeleton className="h-7 w-20 rounded-lg" />
|
|
157
|
+
</div>
|
|
158
|
+
</div>
|
|
159
|
+
</Fragment>
|
|
160
|
+
))}
|
|
161
|
+
</PageRows>
|
|
162
|
+
</div>
|
|
163
|
+
) : senders.length === 0 ? (
|
|
164
|
+
// The heading carries the add/open control, so the empty state states
|
|
165
|
+
// the fact and adds no second button.
|
|
166
|
+
<Empty reason={t("settings.noSmtpSenders")} className="mt-3">
|
|
167
|
+
<Send />
|
|
168
|
+
</Empty>
|
|
169
|
+
) : (
|
|
170
|
+
<PageRows>
|
|
171
|
+
{senders.map((s, idx) => (
|
|
172
|
+
<Fragment key={s.id}>
|
|
173
|
+
{idx > 0 && <Separator />}
|
|
174
|
+
<div
|
|
175
|
+
data-slot="page-row"
|
|
176
|
+
className="flex min-h-[var(--row-height,3.5rem)] items-center justify-between gap-4 px-4 py-3 group"
|
|
177
|
+
>
|
|
178
|
+
<div className="min-w-0">
|
|
179
|
+
<div className="font-semibold text-sm text-foreground flex flex-wrap items-center gap-1.5">
|
|
180
|
+
{s.name}
|
|
181
|
+
{mode === "integration" ? (
|
|
182
|
+
<>
|
|
183
|
+
<Badge tone={s.provider === "resend" ? "secondary" : "info"} className="uppercase tracking-wider text-[10px]">
|
|
184
|
+
{s.provider}
|
|
185
|
+
</Badge>
|
|
186
|
+
{s.configured ?? true
|
|
187
|
+
? <StatusBadge tone="success" className="text-[10px]"><KeyRound className="h-2.5 w-2.5 mr-0.5 inline" />{t("settings.smtpPasswordSet")}</StatusBadge>
|
|
188
|
+
: <StatusBadge tone="warning" className="text-[10px]">{t("settings.smtpNoPassword")}</StatusBadge>}
|
|
189
|
+
</>
|
|
190
|
+
) : (
|
|
191
|
+
s.passSet
|
|
192
|
+
? <StatusBadge tone="success" className="text-[10px]"><KeyRound className="h-2.5 w-2.5 mr-0.5 inline" />{t("settings.smtpPasswordSet")}</StatusBadge>
|
|
193
|
+
: <StatusBadge tone="warning" className="text-[10px]">{t("settings.smtpNoPassword")}</StatusBadge>
|
|
194
|
+
)}
|
|
195
|
+
</div>
|
|
196
|
+
<div className="text-xs text-muted-foreground mt-1 font-mono">
|
|
197
|
+
{mode === "integration"
|
|
198
|
+
? formatIntegrationSenderSummary(s)
|
|
199
|
+
: `${s.fromEmail} via ${s.host}:${s.port}`}
|
|
200
|
+
</div>
|
|
201
|
+
</div>
|
|
202
|
+
{canManageSMTP && (
|
|
203
|
+
<div className="flex shrink-0 items-center gap-2">
|
|
204
|
+
<Button
|
|
205
|
+
variant="subtle"
|
|
206
|
+
onClick={() => test(s)}
|
|
207
|
+
disabled={testingId === s.id}
|
|
208
|
+
className="text-xs py-1 px-2.5"
|
|
209
|
+
>
|
|
210
|
+
{testingId === s.id ? t("settings.testing") : t("settings.test")}
|
|
211
|
+
</Button>
|
|
212
|
+
{mode === "integration" ? (
|
|
213
|
+
<NavLink to="/settings/integrations?category=communication">
|
|
214
|
+
<Button variant="subtle" className="text-xs py-1 px-2.5">
|
|
215
|
+
{t("settings.openIntegrationsHub")}
|
|
216
|
+
</Button>
|
|
217
|
+
</NavLink>
|
|
218
|
+
) : (
|
|
219
|
+
<>
|
|
220
|
+
<Button variant="subtle" onClick={() => setEditing(s)} className="text-xs py-1 px-2.5">
|
|
221
|
+
{t("settings.editSmtp")}
|
|
222
|
+
</Button>
|
|
223
|
+
<Button
|
|
224
|
+
variant="danger"
|
|
225
|
+
onClick={() => remove(s.id)}
|
|
226
|
+
className="text-xs py-1 px-2.5 border-0"
|
|
227
|
+
>
|
|
228
|
+
{t("settings.remove")}
|
|
229
|
+
</Button>
|
|
230
|
+
</>
|
|
231
|
+
)}
|
|
232
|
+
</div>
|
|
233
|
+
)}
|
|
234
|
+
</div>
|
|
235
|
+
</Fragment>
|
|
236
|
+
))}
|
|
237
|
+
</PageRows>
|
|
238
|
+
)}
|
|
239
|
+
{(creating || editing) && (
|
|
240
|
+
<SMTPSenderModal
|
|
241
|
+
sender={editing}
|
|
242
|
+
onClose={() => { setCreating(false); setEditing(null); }}
|
|
243
|
+
onSaved={() => { setCreating(false); setEditing(null); load(); }}
|
|
244
|
+
/>
|
|
245
|
+
)}
|
|
246
|
+
</PageSection>
|
|
247
|
+
);
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
function SMTPSenderModal({ sender, onClose, onSaved }: { sender: any; onClose: () => void; onSaved: () => void }) {
|
|
251
|
+
const { t } = useTranslation();
|
|
252
|
+
const [name, setName] = useState(sender?.name || "");
|
|
253
|
+
const [host, setHost] = useState(sender?.host || "");
|
|
254
|
+
const [port, setPort] = useState(sender?.port?.toString() || "");
|
|
255
|
+
const [user, setUser] = useState(sender?.user || "");
|
|
256
|
+
const [pass, setPass] = useState("");
|
|
257
|
+
const [fromEmail, setFromEmail] = useState(sender?.fromEmail || "");
|
|
258
|
+
const [err, setErr] = useState<string | { message?: string; status?: number; requestId?: string }>("");
|
|
259
|
+
const [busy, setBusy] = useState(false);
|
|
260
|
+
|
|
261
|
+
async function submit(e: React.FormEvent) {
|
|
262
|
+
e.preventDefault();
|
|
263
|
+
setBusy(true); setErr("");
|
|
264
|
+
try {
|
|
265
|
+
const payload = { name, host, port: parseInt(port, 10), user, pass, fromEmail };
|
|
266
|
+
if (sender) {
|
|
267
|
+
await mailApi.updateSMTPSender(sender.id, payload);
|
|
268
|
+
} else {
|
|
269
|
+
await mailApi.createSMTPSender(payload);
|
|
270
|
+
}
|
|
271
|
+
toast.success(t("settings.saved"));
|
|
272
|
+
onSaved();
|
|
273
|
+
} catch (e: any) {
|
|
274
|
+
setErr(e);
|
|
275
|
+
toast.error(e?.message || t("settings.saveFailed", "Failed to save settings"));
|
|
276
|
+
} finally {
|
|
277
|
+
setBusy(false);
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
return (
|
|
282
|
+
<Modal title={sender ? t("settings.modifySmtpRelay") : t("settings.configureSmtpRelay")} onClose={onClose}>
|
|
283
|
+
<form onSubmit={submit} className="space-y-4">
|
|
284
|
+
<Field label={t("settings.senderConnectionName")}>
|
|
285
|
+
<Input value={name} onChange={(e: any) => setName(e.target.value)} placeholder={t("settings.senderConnectionPlaceholder")} required autoFocus />
|
|
286
|
+
</Field>
|
|
287
|
+
|
|
288
|
+
<div className="flex gap-4">
|
|
289
|
+
<div className="flex-[3]">
|
|
290
|
+
<Field label={t("settings.smtpHostLabel")}>
|
|
291
|
+
<Input className="font-mono text-xs" value={host} onChange={(e: any) => setHost(e.target.value)} placeholder="smtp.mailgun.org" required />
|
|
292
|
+
</Field>
|
|
293
|
+
</div>
|
|
294
|
+
<div className="flex-1">
|
|
295
|
+
<Field label={t("settings.smtpPortLabel")}>
|
|
296
|
+
<Input type="number" className="font-mono text-xs" value={port} onChange={(e: any) => setPort(e.target.value)} placeholder="587" required />
|
|
297
|
+
</Field>
|
|
298
|
+
</div>
|
|
299
|
+
</div>
|
|
300
|
+
|
|
301
|
+
<Field label={t("settings.smtpUsernameLabel")}>
|
|
302
|
+
<Input className="font-mono text-xs" value={user} onChange={(e: any) => setUser(e.target.value)} placeholder={t("settings.smtpUsernamePlaceholder")} required />
|
|
303
|
+
</Field>
|
|
304
|
+
|
|
305
|
+
<Field label={t("settings.smtpPasswordLabel")} hint={sender ? t("settings.smtpPasswordHint") : ""}>
|
|
306
|
+
<Input type="password" className="font-mono text-xs" value={pass} onChange={(e: any) => setPass(e.target.value)} placeholder="••••••••" required={!sender} />
|
|
307
|
+
</Field>
|
|
308
|
+
|
|
309
|
+
<Field label={t("settings.defaultFromAddress")} hint={t("settings.defaultFromHint")}>
|
|
310
|
+
<Input className="font-mono text-xs" value={fromEmail} onChange={(e: any) => setFromEmail(e.target.value)} placeholder="noreply@domain.com" required />
|
|
311
|
+
</Field>
|
|
312
|
+
|
|
313
|
+
{err && <FormError err={err} />}
|
|
314
|
+
<div className="flex justify-end gap-2.5 pt-4 border-t border-border">
|
|
315
|
+
<Button type="button" variant="ghost" onClick={onClose}>{t("settings.cancel")}</Button>
|
|
316
|
+
<Button type="submit" variant="primary" disabled={busy || !name.trim() || !host.trim() || !port || !user.trim()}>
|
|
317
|
+
{busy ? t("settings.savingDots") : t("settings.saveRelay")}
|
|
318
|
+
</Button>
|
|
319
|
+
</div>
|
|
320
|
+
</form>
|
|
321
|
+
</Modal>
|
|
322
|
+
);
|
|
323
|
+
}
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
import { Button, Modal, Field, Input, Badge, Empty, Panel, confirmDialog, timeAgo, Table, THead, TBody, TR, TH, TD, TableSkeleton, FormError, useTranslation } from "@octarq/plugin-sdk";
|
|
2
|
+
import { useEffect, useState } from "react";
|
|
3
|
+
import { mailApi, MailSuppression } from "../api";
|
|
4
|
+
import { Plus, Trash2, ShieldAlert } from "lucide-react";
|
|
5
|
+
|
|
6
|
+
export function SuppressionList() {
|
|
7
|
+
const { t } = useTranslation();
|
|
8
|
+
const [items, setItems] = useState<MailSuppression[]>([]);
|
|
9
|
+
const [loading, setLoading] = useState(false);
|
|
10
|
+
const [showAdd, setShowAdd] = useState(false);
|
|
11
|
+
const [address, setAddress] = useState("");
|
|
12
|
+
const [err, setErr] = useState<string | { message?: string; status?: number; requestId?: string }>("");
|
|
13
|
+
const [saving, setSaving] = useState(false);
|
|
14
|
+
|
|
15
|
+
async function load() {
|
|
16
|
+
setLoading(true);
|
|
17
|
+
try {
|
|
18
|
+
setItems(await mailApi.suppressions());
|
|
19
|
+
} finally {
|
|
20
|
+
setLoading(false);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
useEffect(() => {
|
|
25
|
+
load();
|
|
26
|
+
}, []);
|
|
27
|
+
|
|
28
|
+
async function handleAdd() {
|
|
29
|
+
setErr("");
|
|
30
|
+
if (!address.trim() || !address.includes("@")) {
|
|
31
|
+
setErr(t("mail.prefixDomainRequired"));
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
setSaving(true);
|
|
35
|
+
try {
|
|
36
|
+
await mailApi.createSuppression(address.trim());
|
|
37
|
+
setShowAdd(false);
|
|
38
|
+
setAddress("");
|
|
39
|
+
load();
|
|
40
|
+
} catch (e: any) {
|
|
41
|
+
setErr(e);
|
|
42
|
+
} finally {
|
|
43
|
+
setSaving(false);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
async function handleRemove(item: MailSuppression) {
|
|
48
|
+
if (await confirmDialog(t("mail.deleteSuppressionConfirm", { address: item.address }))) {
|
|
49
|
+
await mailApi.deleteSuppression(item.id);
|
|
50
|
+
load();
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function renderReasonBadge(reason: string) {
|
|
55
|
+
switch (reason) {
|
|
56
|
+
case "hard_bounce":
|
|
57
|
+
return <Badge variant="danger">{t("mail.reasonHardBounce")}</Badge>;
|
|
58
|
+
case "complaint":
|
|
59
|
+
return <Badge variant="warning">{t("mail.reasonComplaint")}</Badge>;
|
|
60
|
+
case "manual":
|
|
61
|
+
default:
|
|
62
|
+
return <Badge variant="info">{t("mail.reasonManual")}</Badge>;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
return (
|
|
67
|
+
<Panel
|
|
68
|
+
title={t("mail.suppressionList")}
|
|
69
|
+
description={t("mail.suppressionListDesc")}
|
|
70
|
+
action={
|
|
71
|
+
<Button variant="primary" onClick={() => setShowAdd(true)} className="gap-1.5 py-1 text-xs">
|
|
72
|
+
<Plus className="h-3.5 w-3.5" />
|
|
73
|
+
{t("mail.addSuppression")}
|
|
74
|
+
</Button>
|
|
75
|
+
}
|
|
76
|
+
>
|
|
77
|
+
|
|
78
|
+
{loading && items.length === 0 ? (
|
|
79
|
+
<div className="overflow-x-auto border border-border rounded-lg">
|
|
80
|
+
<TableSkeleton columnsCount={5} rowsCount={5} ariaLabel={t("mail.loading")} />
|
|
81
|
+
</div>
|
|
82
|
+
) : items.length === 0 ? (
|
|
83
|
+
<Empty reason={t("mail.noSuppressions")}>
|
|
84
|
+
<ShieldAlert />
|
|
85
|
+
</Empty>
|
|
86
|
+
) : (
|
|
87
|
+
<div className="overflow-x-auto border border-border rounded-lg">
|
|
88
|
+
<Table>
|
|
89
|
+
<THead>
|
|
90
|
+
<TR>
|
|
91
|
+
<TH>{t("mail.addressHeader")}</TH>
|
|
92
|
+
<TH>{t("mail.reasonHeader")}</TH>
|
|
93
|
+
<TH>{t("mail.countHeader")}</TH>
|
|
94
|
+
<TH>{t("mail.dateHeader")}</TH>
|
|
95
|
+
<TH className="text-right">{t("mail.actionsHeader")}</TH>
|
|
96
|
+
</TR>
|
|
97
|
+
</THead>
|
|
98
|
+
<TBody>
|
|
99
|
+
{items.map((item) => (
|
|
100
|
+
<TR key={item.id}>
|
|
101
|
+
<TD className="font-mono font-medium text-foreground">{item.address}</TD>
|
|
102
|
+
<TD>{renderReasonBadge(item.reason)}</TD>
|
|
103
|
+
<TD className="font-mono tnum text-muted-foreground">{item.count}</TD>
|
|
104
|
+
<TD className="font-mono tnum text-muted-foreground">{timeAgo(item.createdAt)}</TD>
|
|
105
|
+
<TD className="text-right">
|
|
106
|
+
<Button
|
|
107
|
+
variant="ghost"
|
|
108
|
+
onClick={() => handleRemove(item)}
|
|
109
|
+
title={t("mail.removeSuppression")}
|
|
110
|
+
className="p-1 text-muted-foreground hover:text-danger-fg"
|
|
111
|
+
>
|
|
112
|
+
<Trash2 className="h-3.5 w-3.5" />
|
|
113
|
+
</Button>
|
|
114
|
+
</TD>
|
|
115
|
+
</TR>
|
|
116
|
+
))}
|
|
117
|
+
</TBody>
|
|
118
|
+
</Table>
|
|
119
|
+
</div>
|
|
120
|
+
)}
|
|
121
|
+
|
|
122
|
+
{showAdd && (
|
|
123
|
+
<Modal title={t("mail.addSuppressionTitle")} onClose={() => setShowAdd(false)}>
|
|
124
|
+
<div className="space-y-4">
|
|
125
|
+
<Field label={t("mail.enterAddress")}>
|
|
126
|
+
<Input
|
|
127
|
+
className="font-mono text-sm"
|
|
128
|
+
value={address}
|
|
129
|
+
onChange={(e) => setAddress(e.target.value)}
|
|
130
|
+
placeholder={t("mail.addressPlaceholder")}
|
|
131
|
+
autoFocus
|
|
132
|
+
/>
|
|
133
|
+
</Field>
|
|
134
|
+
{err && <FormError err={err} />}
|
|
135
|
+
<div className="flex justify-end gap-2.5 pt-4 border-t border-border">
|
|
136
|
+
<Button variant="ghost" onClick={() => setShowAdd(false)}>
|
|
137
|
+
{t("mail.cancel")}
|
|
138
|
+
</Button>
|
|
139
|
+
<Button variant="primary" onClick={handleAdd} disabled={saving}>
|
|
140
|
+
{t("mail.saveConfiguration")}
|
|
141
|
+
</Button>
|
|
142
|
+
</div>
|
|
143
|
+
</div>
|
|
144
|
+
</Modal>
|
|
145
|
+
)}
|
|
146
|
+
</Panel>
|
|
147
|
+
);
|
|
148
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
// @vitest-environment happy-dom
|
|
2
|
+
import { describe, it, expect, vi, beforeEach } from "vitest";
|
|
3
|
+
import { render, screen, waitFor } from "@testing-library/react";
|
|
4
|
+
import { MemoryRouter } from "react-router-dom";
|
|
5
|
+
import { I18nProvider } from "@octarq/plugin-sdk";
|
|
6
|
+
|
|
7
|
+
// See links/pages/emptyState.test.tsx — same contract: the page's empty state
|
|
8
|
+
// must render through the shared Empty primitive (tagged with a testid here),
|
|
9
|
+
// never a handwritten copy.
|
|
10
|
+
vi.mock("@octarq/plugin-sdk", async (importOriginal) => {
|
|
11
|
+
const ui = await importOriginal<typeof import("@octarq/plugin-sdk")>();
|
|
12
|
+
return {
|
|
13
|
+
...ui,
|
|
14
|
+
Empty: (props: { children?: React.ReactNode; reason?: React.ReactNode; detail?: React.ReactNode; action?: React.ReactNode }) => (
|
|
15
|
+
<div data-testid="shared-empty">
|
|
16
|
+
{props.children}
|
|
17
|
+
{props.reason}
|
|
18
|
+
{props.detail}
|
|
19
|
+
{props.action}
|
|
20
|
+
</div>
|
|
21
|
+
),
|
|
22
|
+
};
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
vi.mock("../api", async (importOriginal) => {
|
|
26
|
+
const mailApi = await importOriginal<typeof import("../api")>();
|
|
27
|
+
return {
|
|
28
|
+
...mailApi,
|
|
29
|
+
mailApi: {
|
|
30
|
+
...mailApi.mailApi,
|
|
31
|
+
domains: vi.fn().mockResolvedValue([]),
|
|
32
|
+
mailboxes: vi.fn().mockResolvedValue([]),
|
|
33
|
+
emails: vi.fn().mockResolvedValue([]),
|
|
34
|
+
},
|
|
35
|
+
};
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
import MailPage from "./index";
|
|
39
|
+
|
|
40
|
+
beforeEach(() => {
|
|
41
|
+
vi.clearAllMocks();
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
describe("MailPage empty state", () => {
|
|
45
|
+
it("renders the shared Empty when there are no mailboxes (not a handwritten copy)", async () => {
|
|
46
|
+
render(
|
|
47
|
+
<MemoryRouter initialEntries={["/mail"]}>
|
|
48
|
+
<I18nProvider>
|
|
49
|
+
<MailPage />
|
|
50
|
+
</I18nProvider>
|
|
51
|
+
</MemoryRouter>
|
|
52
|
+
);
|
|
53
|
+
|
|
54
|
+
await waitFor(() => {
|
|
55
|
+
expect(screen.getAllByTestId("shared-empty").length).toBeGreaterThan(0);
|
|
56
|
+
});
|
|
57
|
+
});
|
|
58
|
+
});
|