@actuate-media/cms-admin 0.43.0 → 0.44.0

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.
@@ -0,0 +1,225 @@
1
+ // @vitest-environment happy-dom
2
+ import { beforeEach, describe, expect, it, vi } from 'vitest'
3
+ import { fireEvent, render, screen, waitFor } from '@testing-library/react'
4
+
5
+ /**
6
+ * Settings > Email: provider picker + per-provider credential fields backed by
7
+ * GET/PUT /email/settings and POST /email/settings/test. Secrets are
8
+ * write-only — the API returns only `hasApiKey` / `apiKeyLast4`, never the key.
9
+ */
10
+
11
+ interface EmailSettingsData {
12
+ settings: Record<string, unknown>
13
+ envProvider: string | null
14
+ factoryAvailable: boolean
15
+ envSenderActive: boolean
16
+ platformAdapter: boolean
17
+ }
18
+
19
+ const EMPTY_RESPONSE: EmailSettingsData = {
20
+ settings: { provider: null, hasApiKey: false, hasSmtpPass: false },
21
+ envProvider: null,
22
+ factoryAvailable: true,
23
+ envSenderActive: false,
24
+ platformAdapter: false,
25
+ }
26
+
27
+ let getResponse: EmailSettingsData = EMPTY_RESPONSE
28
+ let putResponse: { settings: Record<string, unknown> } | null = null
29
+ let testResponse: { data?: unknown; error?: string; status: number } = {
30
+ data: { success: true, sentTo: 'admin@example.com' },
31
+ status: 200,
32
+ }
33
+
34
+ const cmsApi = vi.fn(async (endpoint: string, options?: { method?: string; body?: string }) => {
35
+ const method = options?.method ?? 'GET'
36
+ if (endpoint === '/email/settings' && method === 'GET') {
37
+ return { data: getResponse, status: 200 }
38
+ }
39
+ if (endpoint === '/email/settings' && method === 'PUT') {
40
+ return putResponse
41
+ ? { data: putResponse, status: 200 }
42
+ : { error: 'unexpected PUT', status: 500 }
43
+ }
44
+ if (endpoint === '/email/settings/test' && method === 'POST') {
45
+ return testResponse
46
+ }
47
+ return { data: {}, status: 200 }
48
+ })
49
+
50
+ vi.mock('../../lib/api.js', () => ({
51
+ cmsApi: (e: string, o?: unknown) => cmsApi(e, o as any),
52
+ ensureCsrfToken: vi.fn(async () => {}),
53
+ }))
54
+
55
+ const { EmailSettingsTab } = await import('../../views/settings/EmailSettingsTab.js')
56
+
57
+ function deepClone<T>(v: T): T {
58
+ return JSON.parse(JSON.stringify(v))
59
+ }
60
+
61
+ beforeEach(() => {
62
+ cmsApi.mockClear()
63
+ getResponse = deepClone(EMPTY_RESPONSE)
64
+ putResponse = null
65
+ testResponse = { data: { success: true, sentTo: 'admin@example.com' }, status: 200 }
66
+ })
67
+
68
+ describe('EmailSettingsTab', () => {
69
+ it('renders the provider picker with the unconfigured state', async () => {
70
+ render(<EmailSettingsTab role="ADMIN" />)
71
+ expect(await screen.findByRole('radio', { name: 'None' })).toBeTruthy()
72
+ expect(screen.getByRole('radio', { name: 'Resend' })).toBeTruthy()
73
+ expect(screen.getByRole('radio', { name: 'SMTP.com' })).toBeTruthy()
74
+ expect(screen.getByRole('radio', { name: 'Amazon SES' })).toBeTruthy()
75
+ expect(screen.getByRole('radio', { name: 'SMTP server' })).toBeTruthy()
76
+ expect(screen.getByText(/No email provider configured/)).toBeTruthy()
77
+ })
78
+
79
+ it('saves an SMTP.com configuration with the entered key (PUT payload contract)', async () => {
80
+ putResponse = {
81
+ settings: {
82
+ provider: 'smtpcom',
83
+ from: 'noreply@example.com',
84
+ channel: 'transactional',
85
+ hasApiKey: true,
86
+ apiKeyLast4: '-key',
87
+ hasSmtpPass: false,
88
+ },
89
+ }
90
+ render(<EmailSettingsTab role="ADMIN" />)
91
+ fireEvent.click(await screen.findByRole('radio', { name: 'SMTP.com' }))
92
+
93
+ fireEvent.change(screen.getByLabelText('Sender address'), {
94
+ target: { value: 'noreply@example.com' },
95
+ })
96
+ fireEvent.change(screen.getByLabelText('API key'), {
97
+ target: { value: 'smtpcom-secret-key' },
98
+ })
99
+ fireEvent.change(screen.getByLabelText('Sender channel'), {
100
+ target: { value: 'transactional' },
101
+ })
102
+
103
+ fireEvent.click(screen.getByRole('button', { name: 'Save Changes' }))
104
+
105
+ await waitFor(() => {
106
+ const put = cmsApi.mock.calls.find(
107
+ ([e, o]) => e === '/email/settings' && (o as any)?.method === 'PUT',
108
+ )
109
+ expect(put).toBeTruthy()
110
+ expect(JSON.parse((put![1] as any).body)).toEqual({
111
+ provider: 'smtpcom',
112
+ from: 'noreply@example.com',
113
+ apiKey: 'smtpcom-secret-key',
114
+ channel: 'transactional',
115
+ })
116
+ })
117
+
118
+ // After save the key input is cleared and the masked hint appears.
119
+ expect((screen.getByLabelText('API key') as HTMLInputElement).value).toBe('')
120
+ expect(await screen.findByText(/ends in -key/)).toBeTruthy()
121
+ })
122
+
123
+ it('omits the apiKey from the payload when a stored key is kept', async () => {
124
+ getResponse = {
125
+ ...deepClone(EMPTY_RESPONSE),
126
+ settings: {
127
+ provider: 'resend',
128
+ from: 'old@example.com',
129
+ hasApiKey: true,
130
+ apiKeyLast4: 'k3y9',
131
+ hasSmtpPass: false,
132
+ },
133
+ }
134
+ putResponse = {
135
+ settings: {
136
+ provider: 'resend',
137
+ from: 'new@example.com',
138
+ hasApiKey: true,
139
+ apiKeyLast4: 'k3y9',
140
+ hasSmtpPass: false,
141
+ },
142
+ }
143
+ render(<EmailSettingsTab role="ADMIN" />)
144
+ const from = await screen.findByLabelText('Sender address')
145
+ expect(await screen.findByText(/ends in k3y9/)).toBeTruthy()
146
+
147
+ fireEvent.change(from, { target: { value: 'new@example.com' } })
148
+ fireEvent.click(screen.getByRole('button', { name: 'Save Changes' }))
149
+
150
+ await waitFor(() => {
151
+ const put = cmsApi.mock.calls.find(
152
+ ([e, o]) => e === '/email/settings' && (o as any)?.method === 'PUT',
153
+ )
154
+ expect(put).toBeTruthy()
155
+ const body = JSON.parse((put![1] as any).body)
156
+ expect(body).toEqual({ provider: 'resend', from: 'new@example.com' })
157
+ expect(body).not.toHaveProperty('apiKey')
158
+ })
159
+ })
160
+
161
+ it('sends a test email and shows the result', async () => {
162
+ getResponse = {
163
+ ...deepClone(EMPTY_RESPONSE),
164
+ settings: {
165
+ provider: 'resend',
166
+ from: 'a@b.co',
167
+ hasApiKey: true,
168
+ apiKeyLast4: 'k3y9',
169
+ hasSmtpPass: false,
170
+ },
171
+ }
172
+ render(<EmailSettingsTab role="ADMIN" />)
173
+ fireEvent.click(await screen.findByRole('button', { name: /Send test email/ }))
174
+ await waitFor(() =>
175
+ expect(cmsApi).toHaveBeenCalledWith(
176
+ '/email/settings/test',
177
+ expect.objectContaining({ method: 'POST' }),
178
+ ),
179
+ )
180
+ expect(await screen.findByText(/Test email sent to admin@example.com/)).toBeTruthy()
181
+ })
182
+
183
+ it('surfaces a failed test send', async () => {
184
+ getResponse = {
185
+ ...deepClone(EMPTY_RESPONSE),
186
+ settings: {
187
+ provider: 'resend',
188
+ from: 'a@b.co',
189
+ hasApiKey: true,
190
+ hasSmtpPass: false,
191
+ },
192
+ }
193
+ testResponse = { error: 'SMTP.com API error (401): bad key', status: 502 }
194
+ render(<EmailSettingsTab role="ADMIN" />)
195
+ fireEvent.click(await screen.findByRole('button', { name: /Send test email/ }))
196
+ expect(await screen.findByText(/SMTP\.com API error \(401\)/)).toBeTruthy()
197
+ })
198
+
199
+ it('shows the env-managed notice and disables editing for non-admins', async () => {
200
+ getResponse = {
201
+ ...deepClone(EMPTY_RESPONSE),
202
+ envProvider: 'resend',
203
+ envSenderActive: true,
204
+ }
205
+ render(<EmailSettingsTab role="EDITOR" />)
206
+ expect(await screen.findByText(/read-only access/)).toBeTruthy()
207
+ expect(screen.getByText(/Environment variables currently configure/)).toBeTruthy()
208
+ expect((screen.getByRole('radio', { name: 'Resend' }) as HTMLButtonElement).disabled).toBe(true)
209
+ })
210
+
211
+ it('warns when the email plugin is missing for a configured provider', async () => {
212
+ getResponse = {
213
+ ...deepClone(EMPTY_RESPONSE),
214
+ factoryAvailable: false,
215
+ settings: {
216
+ provider: 'resend',
217
+ from: 'a@b.co',
218
+ hasApiKey: true,
219
+ hasSmtpPass: false,
220
+ },
221
+ }
222
+ render(<EmailSettingsTab role="ADMIN" />)
223
+ expect(await screen.findByText(/requires the email plugin/)).toBeTruthy()
224
+ })
225
+ })
@@ -7,6 +7,7 @@ import {
7
7
  AlertTriangle,
8
8
  Download,
9
9
  Layers,
10
+ Mail,
10
11
  Users as UsersIcon,
11
12
  KeyRound,
12
13
  } from 'lucide-react'
@@ -18,6 +19,7 @@ import { RelationshipField } from '../fields/RelationshipField.js'
18
19
  import { GeneralSettingsTab } from './settings/GeneralSettingsTab.js'
19
20
  import { SeoSettingsTab } from './settings/SeoSettingsTab.js'
20
21
  import { AISettingsTab } from './settings/AISettingsTab.js'
22
+ import { EmailSettingsTab } from './settings/EmailSettingsTab.js'
21
23
  import { AppearanceTab } from './settings/AppearanceTab.js'
22
24
  import { SecurityTab } from './settings/SecurityTab.js'
23
25
  import { SettingsCard } from './settings/components.js'
@@ -85,6 +87,7 @@ export function Settings({
85
87
  'users',
86
88
  'api-keys',
87
89
  'seo',
90
+ 'email',
88
91
  'ai',
89
92
  'updates',
90
93
  ] as const,
@@ -214,6 +217,12 @@ export function Settings({
214
217
  <Tabs.Trigger value="seo" className={tabTriggerClass}>
215
218
  SEO
216
219
  </Tabs.Trigger>
220
+ <Tabs.Trigger value="email" className={tabTriggerClass}>
221
+ <span className="flex items-center gap-1.5">
222
+ <Mail className="h-4 w-4" />
223
+ Email
224
+ </span>
225
+ </Tabs.Trigger>
217
226
  <Tabs.Trigger value="ai" className={tabTriggerClass}>
218
227
  <span className="flex items-center gap-1.5">
219
228
  <Bot className="h-4 w-4" />
@@ -311,6 +320,10 @@ export function Settings({
311
320
  <SeoSettingsTab onNavigate={onNavigate} role={session?.user?.role} />
312
321
  </Tabs.Content>
313
322
 
323
+ <Tabs.Content value="email" className="space-y-4">
324
+ <EmailSettingsTab role={session?.user?.role} />
325
+ </Tabs.Content>
326
+
314
327
  <Tabs.Content value="ai" className="space-y-4">
315
328
  <AISettingsTab role={session?.user?.role} />
316
329
  </Tabs.Content>
@@ -0,0 +1,436 @@
1
+ 'use client'
2
+
3
+ import { AlertTriangle, CheckCircle2, Info, KeyRound, Loader2, Send } from 'lucide-react'
4
+ import { useId } from 'react'
5
+
6
+ import { SettingsCard, SettingsSaveBar, SettingsToggleRow } from './components.js'
7
+ import {
8
+ EMAIL_PROVIDER_OPTIONS,
9
+ useEmailSettings,
10
+ type EmailProviderKey,
11
+ type UseEmailSettings,
12
+ } from './useEmailSettings.js'
13
+
14
+ const INPUT_CLASS =
15
+ 'w-full max-w-md rounded-md border border-border bg-input-background px-3 py-2 text-base text-foreground focus-visible:ring-2 focus-visible:ring-ring focus-visible:outline-none disabled:cursor-not-allowed disabled:opacity-60'
16
+ const LABEL_CLASS = 'mb-1 block text-sm font-medium text-foreground'
17
+ const HELP_CLASS = 'mt-1 text-sm text-muted-foreground'
18
+
19
+ const PROVIDER_LABEL: Record<EmailProviderKey, string> = {
20
+ resend: 'Resend',
21
+ smtpcom: 'SMTP.com',
22
+ ses: 'Amazon SES',
23
+ smtp: 'SMTP server',
24
+ }
25
+
26
+ function Field({
27
+ id,
28
+ label,
29
+ help,
30
+ children,
31
+ }: {
32
+ id: string
33
+ label: string
34
+ help?: string
35
+ children: React.ReactNode
36
+ }) {
37
+ return (
38
+ <div>
39
+ <label htmlFor={id} className={LABEL_CLASS}>
40
+ {label}
41
+ </label>
42
+ {children}
43
+ {help && <p className={HELP_CLASS}>{help}</p>}
44
+ </div>
45
+ )
46
+ }
47
+
48
+ function SecretField({
49
+ id,
50
+ label,
51
+ value,
52
+ onChange,
53
+ disabled,
54
+ hasStored,
55
+ last4,
56
+ help,
57
+ }: {
58
+ id: string
59
+ label: string
60
+ value: string
61
+ onChange: (v: string) => void
62
+ disabled: boolean
63
+ hasStored: boolean
64
+ last4?: string
65
+ help?: string
66
+ }) {
67
+ return (
68
+ <Field
69
+ id={id}
70
+ label={label}
71
+ help={
72
+ hasStored && !value
73
+ ? `A ${label.toLowerCase()} is saved${last4 ? ` (ends in ${last4})` : ''}. Enter a new value to replace it.`
74
+ : help
75
+ }
76
+ >
77
+ <div className="relative max-w-md">
78
+ <KeyRound
79
+ size={16}
80
+ aria-hidden="true"
81
+ className="text-muted-foreground pointer-events-none absolute top-1/2 left-3 -translate-y-1/2"
82
+ />
83
+ <input
84
+ id={id}
85
+ type="password"
86
+ autoComplete="off"
87
+ value={value}
88
+ disabled={disabled}
89
+ onChange={(e) => onChange(e.target.value)}
90
+ placeholder={hasStored ? `••••••••${last4 ? last4 : ''}` : 'Enter value'}
91
+ className={`${INPUT_CLASS} pl-9`}
92
+ />
93
+ </div>
94
+ </Field>
95
+ )
96
+ }
97
+
98
+ function Notice({
99
+ tone,
100
+ children,
101
+ }: {
102
+ tone: 'info' | 'warning' | 'success' | 'error'
103
+ children: React.ReactNode
104
+ }) {
105
+ const toneClass =
106
+ tone === 'warning'
107
+ ? 'border-warning/30 bg-warning/10 text-warning'
108
+ : tone === 'success'
109
+ ? 'border-success/30 bg-success/10 text-success'
110
+ : tone === 'error'
111
+ ? 'border-destructive/30 bg-destructive/10 text-destructive'
112
+ : 'border-border bg-muted text-muted-foreground'
113
+ const Icon = tone === 'success' ? CheckCircle2 : tone === 'info' ? Info : AlertTriangle
114
+ return (
115
+ <div
116
+ role="status"
117
+ aria-live="polite"
118
+ className={`flex items-start gap-2.5 rounded-lg border p-3 text-sm ${toneClass}`}
119
+ >
120
+ <Icon size={16} className="mt-0.5 shrink-0" aria-hidden="true" />
121
+ <div className="min-w-0">{children}</div>
122
+ </div>
123
+ )
124
+ }
125
+
126
+ function ProviderFields({ s, canEdit }: { s: UseEmailSettings; canEdit: boolean }) {
127
+ const ids = {
128
+ from: useId(),
129
+ apiKey: useId(),
130
+ channel: useId(),
131
+ region: useId(),
132
+ host: useId(),
133
+ port: useId(),
134
+ user: useId(),
135
+ pass: useId(),
136
+ }
137
+ const { form, setField, stored } = s
138
+ const disabled = !canEdit
139
+ if (form.provider === '') return null
140
+
141
+ const sameProvider = stored.sameProvider
142
+
143
+ return (
144
+ <div className="space-y-4">
145
+ <Field
146
+ id={ids.from}
147
+ label="Sender address"
148
+ help="The From address for invitations, password resets, and form notifications. Must be verified with your provider."
149
+ >
150
+ <input
151
+ id={ids.from}
152
+ type="email"
153
+ value={form.from}
154
+ disabled={disabled}
155
+ onChange={(e) => setField('from', e.target.value)}
156
+ placeholder="noreply@yoursite.com"
157
+ className={INPUT_CLASS}
158
+ />
159
+ </Field>
160
+
161
+ {(form.provider === 'resend' || form.provider === 'smtpcom') && (
162
+ <SecretField
163
+ id={ids.apiKey}
164
+ label="API key"
165
+ value={form.apiKey}
166
+ onChange={(v) => setField('apiKey', v)}
167
+ disabled={disabled}
168
+ hasStored={sameProvider && stored.hasApiKey}
169
+ last4={stored.apiKeyLast4}
170
+ help={
171
+ form.provider === 'resend'
172
+ ? 'Your Resend API key (starts with re_). Stored encrypted.'
173
+ : 'Your SMTP.com v4 API key. Stored encrypted.'
174
+ }
175
+ />
176
+ )}
177
+
178
+ {form.provider === 'smtpcom' && (
179
+ <Field
180
+ id={ids.channel}
181
+ label="Sender channel"
182
+ help="Optional. The SMTP.com channel to send through; defaults to your account default."
183
+ >
184
+ <input
185
+ id={ids.channel}
186
+ type="text"
187
+ value={form.channel}
188
+ disabled={disabled}
189
+ onChange={(e) => setField('channel', e.target.value)}
190
+ placeholder="default"
191
+ className={INPUT_CLASS}
192
+ />
193
+ </Field>
194
+ )}
195
+
196
+ {form.provider === 'ses' && (
197
+ <Field
198
+ id={ids.region}
199
+ label="AWS region"
200
+ help="SES sends with your deployment's AWS credentials (env vars or IAM role); only the region is stored here."
201
+ >
202
+ <input
203
+ id={ids.region}
204
+ type="text"
205
+ value={form.region}
206
+ disabled={disabled}
207
+ onChange={(e) => setField('region', e.target.value)}
208
+ placeholder="us-east-1"
209
+ className={INPUT_CLASS}
210
+ />
211
+ </Field>
212
+ )}
213
+
214
+ {form.provider === 'smtp' && (
215
+ <>
216
+ <div className="grid max-w-md grid-cols-1 gap-4 sm:grid-cols-[1fr_8rem]">
217
+ <Field id={ids.host} label="Host">
218
+ <input
219
+ id={ids.host}
220
+ type="text"
221
+ value={form.host}
222
+ disabled={disabled}
223
+ onChange={(e) => setField('host', e.target.value)}
224
+ placeholder="smtp.example.com"
225
+ className={INPUT_CLASS}
226
+ />
227
+ </Field>
228
+ <Field id={ids.port} label="Port">
229
+ <input
230
+ id={ids.port}
231
+ type="text"
232
+ inputMode="numeric"
233
+ value={form.port}
234
+ disabled={disabled}
235
+ onChange={(e) => setField('port', e.target.value.replace(/[^\d]/g, ''))}
236
+ placeholder="587"
237
+ className={INPUT_CLASS}
238
+ />
239
+ </Field>
240
+ </div>
241
+ <div className="max-w-md">
242
+ <SettingsToggleRow
243
+ label="Implicit TLS"
244
+ description="Enable for port 465. Leave off for STARTTLS (port 587, the common default)."
245
+ checked={form.secure}
246
+ disabled={disabled}
247
+ onChange={(v) => setField('secure', v)}
248
+ />
249
+ </div>
250
+ <Field
251
+ id={ids.user}
252
+ label="Username"
253
+ help="Leave blank for relays that authenticate by IP address."
254
+ >
255
+ <input
256
+ id={ids.user}
257
+ type="text"
258
+ autoComplete="off"
259
+ value={form.smtpUser}
260
+ disabled={disabled}
261
+ onChange={(e) => setField('smtpUser', e.target.value)}
262
+ className={INPUT_CLASS}
263
+ />
264
+ </Field>
265
+ <SecretField
266
+ id={ids.pass}
267
+ label="Password"
268
+ value={form.smtpPass}
269
+ onChange={(v) => setField('smtpPass', v)}
270
+ disabled={disabled}
271
+ hasStored={sameProvider && stored.hasSmtpPass}
272
+ help="Stored encrypted."
273
+ />
274
+ </>
275
+ )}
276
+ </div>
277
+ )
278
+ }
279
+
280
+ export function EmailSettingsTab({ role }: { role?: string }) {
281
+ const canEdit = String(role ?? '').toUpperCase() === 'ADMIN'
282
+ const s = useEmailSettings(canEdit)
283
+ const providerGroupId = useId()
284
+
285
+ if (s.loading) {
286
+ return (
287
+ <div className="flex h-48 items-center justify-center" aria-label="Loading email settings">
288
+ <Loader2 className="text-brand h-6 w-6 animate-spin" aria-hidden="true" />
289
+ </div>
290
+ )
291
+ }
292
+
293
+ if (s.loadError) {
294
+ return (
295
+ <div
296
+ role="alert"
297
+ className="border-destructive/30 bg-destructive/10 text-destructive flex items-center gap-3 rounded-lg border p-3 text-sm"
298
+ >
299
+ <AlertTriangle size={20} className="shrink-0" aria-hidden="true" />
300
+ <span className="flex-1">{s.loadError}</span>
301
+ <button
302
+ onClick={s.reload}
303
+ className="border-destructive/40 rounded-md border px-3 py-1 transition-colors hover:opacity-80"
304
+ >
305
+ Retry
306
+ </button>
307
+ </div>
308
+ )
309
+ }
310
+
311
+ const configured = s.form.provider !== ''
312
+
313
+ return (
314
+ <div className="space-y-4">
315
+ {!canEdit && (
316
+ <Notice tone="info">
317
+ You have read-only access to email settings. Ask an administrator to make changes.
318
+ </Notice>
319
+ )}
320
+
321
+ {s.platformAdapter && (
322
+ <Notice tone="info">
323
+ A platform email adapter is configured in code (<code>platform.email</code>); it takes
324
+ precedence over the settings on this page.
325
+ </Notice>
326
+ )}
327
+
328
+ {!s.platformAdapter && s.env.provider && (
329
+ <Notice tone="info">
330
+ Environment variables currently configure{' '}
331
+ <strong>{PROVIDER_LABEL[s.env.provider]}</strong>. Settings saved here take precedence
332
+ over the environment configuration.
333
+ </Notice>
334
+ )}
335
+
336
+ {configured && !s.factoryAvailable && (
337
+ <Notice tone="warning">
338
+ Sending with these settings requires the email plugin. Add <code>emailPlugin()</code> from{' '}
339
+ <code>@actuate-media/plugin-email</code> to your <code>actuate.config.ts</code>.
340
+ </Notice>
341
+ )}
342
+
343
+ <SettingsCard
344
+ title="Email delivery"
345
+ description="Transactional email provider for invitations, password resets, and form notifications. Credentials are encrypted at rest."
346
+ actions={
347
+ <button
348
+ type="button"
349
+ onClick={() => void s.sendTest()}
350
+ disabled={s.testing || s.dirty || (!configured && !s.env.senderActive)}
351
+ title={s.dirty ? 'Save your changes before sending a test.' : undefined}
352
+ className="border-border text-foreground hover:bg-accent inline-flex items-center gap-2 rounded-md border px-3 py-1.5 text-sm transition-colors disabled:cursor-not-allowed disabled:opacity-50"
353
+ >
354
+ {s.testing ? (
355
+ <Loader2 size={14} className="animate-spin" aria-hidden="true" />
356
+ ) : (
357
+ <Send size={14} aria-hidden="true" />
358
+ )}
359
+ Send test email
360
+ </button>
361
+ }
362
+ >
363
+ <div className="space-y-5">
364
+ <div>
365
+ <span id={providerGroupId} className={LABEL_CLASS}>
366
+ Provider
367
+ </span>
368
+ <div
369
+ role="radiogroup"
370
+ aria-labelledby={providerGroupId}
371
+ className="flex flex-wrap gap-2"
372
+ >
373
+ {[{ value: '' as const, label: 'None' }, ...EMAIL_PROVIDER_OPTIONS].map((opt) => {
374
+ const active = s.form.provider === opt.value
375
+ return (
376
+ <button
377
+ key={opt.value || 'none'}
378
+ type="button"
379
+ role="radio"
380
+ aria-checked={active}
381
+ disabled={!canEdit}
382
+ onClick={() => s.setField('provider', opt.value)}
383
+ className={`rounded-md border px-3 py-1.5 text-sm transition-colors disabled:cursor-not-allowed disabled:opacity-50 ${
384
+ active
385
+ ? 'border-brand bg-brand/10 text-brand font-medium'
386
+ : 'border-border text-muted-foreground hover:text-foreground hover:bg-accent'
387
+ }`}
388
+ >
389
+ {opt.label}
390
+ </button>
391
+ )
392
+ })}
393
+ </div>
394
+ {!configured && (
395
+ <p className={HELP_CLASS}>
396
+ {s.env.senderActive
397
+ ? 'No provider is configured here, but an environment-configured sender is active.'
398
+ : 'No email provider configured. Transactional email (invites, password resets, form notifications) is skipped.'}
399
+ </p>
400
+ )}
401
+ </div>
402
+
403
+ <ProviderFields s={s} canEdit={canEdit} />
404
+
405
+ {s.testResult && (
406
+ <Notice tone={s.testResult.success ? 'success' : 'error'}>
407
+ {s.testResult.message}
408
+ </Notice>
409
+ )}
410
+ {!s.testResult && s.lastTest.status && (
411
+ <p className="text-muted-foreground text-sm">
412
+ Last test {s.lastTest.status === 'success' ? 'succeeded' : `failed`}
413
+ {s.lastTest.testedAt ? ` on ${new Date(s.lastTest.testedAt).toLocaleString()}` : ''}
414
+ {s.lastTest.status === 'failed' && s.lastTest.error ? ` — ${s.lastTest.error}` : ''}
415
+ </p>
416
+ )}
417
+ </div>
418
+
419
+ {s.saveError && (
420
+ <p className="text-destructive mt-4 text-sm" role="alert">
421
+ {s.saveError}
422
+ </p>
423
+ )}
424
+ </SettingsCard>
425
+
426
+ <SettingsSaveBar
427
+ dirty={s.dirty}
428
+ canEdit={canEdit}
429
+ hasErrors={false}
430
+ saveState={s.saveState}
431
+ onSave={() => void s.save()}
432
+ onReset={s.reset}
433
+ />
434
+ </div>
435
+ )
436
+ }