feat(admin): per-port email/Documenso/branding/reminder settings + invitations
Centralizes everything operators need to configure into the admin panel,
each setting per-port with env fallback.
New admin pages
- /admin landing page linking to every admin section as a card
- /admin/email FROM name+address, reply-to, signature/footer HTML,
optional SMTP host/port/user/pass override
- /admin/documenso API URL+key override, EOI Documenso template ID,
default EOI pathway (documenso-template vs inapp),
"Test connection" button
- /admin/branding logo URL, primary color, app name, email
header/footer HTML
- /admin/reminders port-level defaults for new interests +
port-wide daily-digest delivery window
- /admin/invitations send / list / resend / revoke CRM invitations
Per-user reminder digest
- /notifications/preferences gains a Reminder digest card:
immediate / daily / weekly / off, with HH:MM, day-of-week,
IANA timezone fields. Stored in user_profiles.preferences.reminders.
Plumbing
- port-config.ts typed accessors (getPortEmailConfig, getPortDocumensoConfig,
getPortBrandingConfig, getPortReminderConfig) — settings → env fallback.
- sendEmail accepts optional portId; resolves From/SMTP from settings
when supplied.
- documensoFetch + downloadSignedPdf accept optional portId; each public
function takes it through. checkDocumensoHealth() backs the test button.
- crm-invite.service gains listCrmInvites / revokeCrmInvite / resendCrmInvite
with audit-log entries (revoke_invite, resend_invite added to AuditAction).
- AdminLandingPage card grid + shared SettingsFormCard component to remove
per-page form boilerplate.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-27 23:21:54 +02:00
|
|
|
'use client';
|
|
|
|
|
|
|
|
|
|
import { useEffect, useState } from 'react';
|
|
|
|
|
import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query';
|
|
|
|
|
import { Loader2 } from 'lucide-react';
|
|
|
|
|
import { toast } from 'sonner';
|
|
|
|
|
|
|
|
|
|
import { Button } from '@/components/ui/button';
|
|
|
|
|
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card';
|
|
|
|
|
import { Input } from '@/components/ui/input';
|
|
|
|
|
import { Label } from '@/components/ui/label';
|
|
|
|
|
import {
|
|
|
|
|
Select,
|
|
|
|
|
SelectContent,
|
|
|
|
|
SelectItem,
|
|
|
|
|
SelectTrigger,
|
|
|
|
|
SelectValue,
|
|
|
|
|
} from '@/components/ui/select';
|
|
|
|
|
import { apiFetch } from '@/lib/api/client';
|
fix(audit-tier-2): error-surface hygiene — toastError + CodedError sweep
Two mechanical sweeps closing the audit's HIGH §16 + MED §11 findings:
* 38 client components / 56 toast.error sites converted to
toastError(err) so the new admin error inspector becomes usable from
user-reported issues — every failed inline-edit, save, send, archive,
upload, etc. now carries the request-id + error-code (Copy ID action).
* 26 service files / 62 bare-Error throws converted to CodedError or
the existing AppError subclasses. Adds new error codes:
DOCUMENSO_UPSTREAM_ERROR (502), DOCUMENSO_AUTH_FAILURE (502),
DOCUMENSO_TIMEOUT (504), OCR_UPSTREAM_ERROR (502),
IMAP_UPSTREAM_ERROR (502), UMAMI_UPSTREAM_ERROR (502),
UMAMI_NOT_CONFIGURED (409), and INSERT_RETURNING_EMPTY (500) for
post-insert returning-empty guards.
* Five vitest assertions updated to match the new user-facing wording
(client-merge "already been merged", expense/interest "couldn't find
that …", documenso "signing service didn't respond").
Test status: 1168/1168 vitest, tsc clean.
Refs: docs/audit-comprehensive-2026-05-05.md HIGH §16 (auditor-H Issue 1)
+ MED §11 (auditor-G Issue 1).
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-05 20:18:05 +02:00
|
|
|
import { toastError } from '@/lib/api/toast-error';
|
feat(admin): per-port email/Documenso/branding/reminder settings + invitations
Centralizes everything operators need to configure into the admin panel,
each setting per-port with env fallback.
New admin pages
- /admin landing page linking to every admin section as a card
- /admin/email FROM name+address, reply-to, signature/footer HTML,
optional SMTP host/port/user/pass override
- /admin/documenso API URL+key override, EOI Documenso template ID,
default EOI pathway (documenso-template vs inapp),
"Test connection" button
- /admin/branding logo URL, primary color, app name, email
header/footer HTML
- /admin/reminders port-level defaults for new interests +
port-wide daily-digest delivery window
- /admin/invitations send / list / resend / revoke CRM invitations
Per-user reminder digest
- /notifications/preferences gains a Reminder digest card:
immediate / daily / weekly / off, with HH:MM, day-of-week,
IANA timezone fields. Stored in user_profiles.preferences.reminders.
Plumbing
- port-config.ts typed accessors (getPortEmailConfig, getPortDocumensoConfig,
getPortBrandingConfig, getPortReminderConfig) — settings → env fallback.
- sendEmail accepts optional portId; resolves From/SMTP from settings
when supplied.
- documensoFetch + downloadSignedPdf accept optional portId; each public
function takes it through. checkDocumensoHealth() backs the test button.
- crm-invite.service gains listCrmInvites / revokeCrmInvite / resendCrmInvite
with audit-log entries (revoke_invite, resend_invite added to AuditAction).
- AdminLandingPage card grid + shared SettingsFormCard component to remove
per-page form boilerplate.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-27 23:21:54 +02:00
|
|
|
|
|
|
|
|
interface ReminderPrefs {
|
|
|
|
|
delivery: 'immediate' | 'daily' | 'weekly' | 'off';
|
|
|
|
|
digestTime?: string;
|
|
|
|
|
digestDayOfWeek?: number;
|
|
|
|
|
timezone?: string;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
interface UserPrefsResponse {
|
|
|
|
|
reminders?: ReminderPrefs;
|
|
|
|
|
timezone?: string;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const DAYS = [
|
|
|
|
|
{ value: '0', label: 'Sunday' },
|
|
|
|
|
{ value: '1', label: 'Monday' },
|
|
|
|
|
{ value: '2', label: 'Tuesday' },
|
|
|
|
|
{ value: '3', label: 'Wednesday' },
|
|
|
|
|
{ value: '4', label: 'Thursday' },
|
|
|
|
|
{ value: '5', label: 'Friday' },
|
|
|
|
|
{ value: '6', label: 'Saturday' },
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
export function ReminderDigestForm() {
|
|
|
|
|
const qc = useQueryClient();
|
|
|
|
|
const { data, isLoading } = useQuery<UserPrefsResponse>({
|
|
|
|
|
queryKey: ['user', 'preferences'],
|
|
|
|
|
queryFn: () =>
|
|
|
|
|
apiFetch<{ data: UserPrefsResponse }>('/api/v1/users/me/preferences').then((r) => r.data),
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const [delivery, setDelivery] = useState<ReminderPrefs['delivery']>('immediate');
|
|
|
|
|
const [digestTime, setDigestTime] = useState('09:00');
|
|
|
|
|
const [digestDay, setDigestDay] = useState('1');
|
|
|
|
|
const [timezone, setTimezone] = useState('Europe/Warsaw');
|
|
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
const r = data?.reminders;
|
|
|
|
|
if (r) {
|
|
|
|
|
setDelivery(r.delivery ?? 'immediate');
|
|
|
|
|
setDigestTime(r.digestTime ?? '09:00');
|
|
|
|
|
setDigestDay(String(r.digestDayOfWeek ?? 1));
|
|
|
|
|
setTimezone(r.timezone ?? data?.timezone ?? 'Europe/Warsaw');
|
|
|
|
|
} else if (data?.timezone) {
|
|
|
|
|
setTimezone(data.timezone);
|
|
|
|
|
}
|
|
|
|
|
}, [data]);
|
|
|
|
|
|
|
|
|
|
const mutation = useMutation({
|
|
|
|
|
mutationFn: () =>
|
|
|
|
|
apiFetch('/api/v1/users/me/preferences', {
|
|
|
|
|
method: 'PATCH',
|
|
|
|
|
body: {
|
|
|
|
|
reminders: {
|
|
|
|
|
delivery,
|
|
|
|
|
...(delivery !== 'immediate' && delivery !== 'off' ? { digestTime, timezone } : {}),
|
|
|
|
|
...(delivery === 'weekly' ? { digestDayOfWeek: Number(digestDay) } : {}),
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
}),
|
|
|
|
|
onSuccess: () => {
|
|
|
|
|
toast.success('Reminder preferences saved');
|
|
|
|
|
qc.invalidateQueries({ queryKey: ['user', 'preferences'] });
|
|
|
|
|
},
|
fix(audit-tier-2): error-surface hygiene — toastError + CodedError sweep
Two mechanical sweeps closing the audit's HIGH §16 + MED §11 findings:
* 38 client components / 56 toast.error sites converted to
toastError(err) so the new admin error inspector becomes usable from
user-reported issues — every failed inline-edit, save, send, archive,
upload, etc. now carries the request-id + error-code (Copy ID action).
* 26 service files / 62 bare-Error throws converted to CodedError or
the existing AppError subclasses. Adds new error codes:
DOCUMENSO_UPSTREAM_ERROR (502), DOCUMENSO_AUTH_FAILURE (502),
DOCUMENSO_TIMEOUT (504), OCR_UPSTREAM_ERROR (502),
IMAP_UPSTREAM_ERROR (502), UMAMI_UPSTREAM_ERROR (502),
UMAMI_NOT_CONFIGURED (409), and INSERT_RETURNING_EMPTY (500) for
post-insert returning-empty guards.
* Five vitest assertions updated to match the new user-facing wording
(client-merge "already been merged", expense/interest "couldn't find
that …", documenso "signing service didn't respond").
Test status: 1168/1168 vitest, tsc clean.
Refs: docs/audit-comprehensive-2026-05-05.md HIGH §16 (auditor-H Issue 1)
+ MED §11 (auditor-G Issue 1).
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-05 20:18:05 +02:00
|
|
|
onError: (err) => toastError(err),
|
feat(admin): per-port email/Documenso/branding/reminder settings + invitations
Centralizes everything operators need to configure into the admin panel,
each setting per-port with env fallback.
New admin pages
- /admin landing page linking to every admin section as a card
- /admin/email FROM name+address, reply-to, signature/footer HTML,
optional SMTP host/port/user/pass override
- /admin/documenso API URL+key override, EOI Documenso template ID,
default EOI pathway (documenso-template vs inapp),
"Test connection" button
- /admin/branding logo URL, primary color, app name, email
header/footer HTML
- /admin/reminders port-level defaults for new interests +
port-wide daily-digest delivery window
- /admin/invitations send / list / resend / revoke CRM invitations
Per-user reminder digest
- /notifications/preferences gains a Reminder digest card:
immediate / daily / weekly / off, with HH:MM, day-of-week,
IANA timezone fields. Stored in user_profiles.preferences.reminders.
Plumbing
- port-config.ts typed accessors (getPortEmailConfig, getPortDocumensoConfig,
getPortBrandingConfig, getPortReminderConfig) — settings → env fallback.
- sendEmail accepts optional portId; resolves From/SMTP from settings
when supplied.
- documensoFetch + downloadSignedPdf accept optional portId; each public
function takes it through. checkDocumensoHealth() backs the test button.
- crm-invite.service gains listCrmInvites / revokeCrmInvite / resendCrmInvite
with audit-log entries (revoke_invite, resend_invite added to AuditAction).
- AdminLandingPage card grid + shared SettingsFormCard component to remove
per-page form boilerplate.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-27 23:21:54 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
if (isLoading) {
|
|
|
|
|
return (
|
|
|
|
|
<Card>
|
|
|
|
|
<CardContent className="py-6 text-sm text-muted-foreground">
|
|
|
|
|
<Loader2 className="mr-2 inline h-4 w-4 animate-spin" />
|
|
|
|
|
Loading…
|
|
|
|
|
</CardContent>
|
|
|
|
|
</Card>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<Card>
|
|
|
|
|
<CardHeader>
|
|
|
|
|
<CardTitle>Reminder digest</CardTitle>
|
|
|
|
|
<CardDescription>
|
|
|
|
|
Choose how reminder notifications are delivered to you. Immediate fires as soon as a
|
|
|
|
|
reminder triggers; daily/weekly batch them into a digest at the time you pick.
|
|
|
|
|
</CardDescription>
|
|
|
|
|
</CardHeader>
|
|
|
|
|
<CardContent className="space-y-4">
|
|
|
|
|
<div className="space-y-1">
|
|
|
|
|
<Label>Delivery</Label>
|
|
|
|
|
<Select
|
|
|
|
|
value={delivery}
|
|
|
|
|
onValueChange={(v) => setDelivery(v as ReminderPrefs['delivery'])}
|
|
|
|
|
>
|
|
|
|
|
<SelectTrigger>
|
|
|
|
|
<SelectValue />
|
|
|
|
|
</SelectTrigger>
|
|
|
|
|
<SelectContent>
|
|
|
|
|
<SelectItem value="immediate">Immediate (default)</SelectItem>
|
|
|
|
|
<SelectItem value="daily">Daily digest</SelectItem>
|
|
|
|
|
<SelectItem value="weekly">Weekly digest</SelectItem>
|
|
|
|
|
<SelectItem value="off">Off (do not send)</SelectItem>
|
|
|
|
|
</SelectContent>
|
|
|
|
|
</Select>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
{(delivery === 'daily' || delivery === 'weekly') && (
|
|
|
|
|
<div className="grid grid-cols-2 gap-3">
|
|
|
|
|
<div className="space-y-1">
|
|
|
|
|
<Label>Delivery time (HH:MM)</Label>
|
|
|
|
|
<Input
|
|
|
|
|
value={digestTime}
|
|
|
|
|
onChange={(e) => setDigestTime(e.target.value)}
|
|
|
|
|
placeholder="09:00"
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
{delivery === 'weekly' && (
|
|
|
|
|
<div className="space-y-1">
|
|
|
|
|
<Label>Day of week</Label>
|
|
|
|
|
<Select value={digestDay} onValueChange={setDigestDay}>
|
|
|
|
|
<SelectTrigger>
|
|
|
|
|
<SelectValue />
|
|
|
|
|
</SelectTrigger>
|
|
|
|
|
<SelectContent>
|
|
|
|
|
{DAYS.map((d) => (
|
|
|
|
|
<SelectItem key={d.value} value={d.value}>
|
|
|
|
|
{d.label}
|
|
|
|
|
</SelectItem>
|
|
|
|
|
))}
|
|
|
|
|
</SelectContent>
|
|
|
|
|
</Select>
|
|
|
|
|
</div>
|
|
|
|
|
)}
|
|
|
|
|
<div className="space-y-1 col-span-2">
|
|
|
|
|
<Label>Timezone (IANA)</Label>
|
|
|
|
|
<Input
|
|
|
|
|
value={timezone}
|
|
|
|
|
onChange={(e) => setTimezone(e.target.value)}
|
|
|
|
|
placeholder="Europe/Warsaw"
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
)}
|
|
|
|
|
|
|
|
|
|
<div className="flex justify-end">
|
|
|
|
|
<Button onClick={() => mutation.mutate()} disabled={mutation.isPending}>
|
|
|
|
|
{mutation.isPending && <Loader2 className="mr-2 h-4 w-4 animate-spin" />}
|
|
|
|
|
Save digest preferences
|
|
|
|
|
</Button>
|
|
|
|
|
</div>
|
|
|
|
|
</CardContent>
|
|
|
|
|
</Card>
|
|
|
|
|
);
|
|
|
|
|
}
|