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>
48 lines
1.4 KiB
TypeScript
48 lines
1.4 KiB
TypeScript
import { eq } from 'drizzle-orm';
|
|
import { NextResponse } from 'next/server';
|
|
|
|
import { withAuth } from '@/lib/api/helpers';
|
|
import { parseBody } from '@/lib/api/route-helpers';
|
|
import { db } from '@/lib/db';
|
|
import { userProfiles, type UserPreferences } from '@/lib/db/schema/users';
|
|
import { errorResponse } from '@/lib/errors';
|
|
import { updateUserPreferencesSchema } from '@/lib/validators/user-preferences';
|
|
|
|
export const GET = withAuth(async (_req, ctx) => {
|
|
try {
|
|
const profile = await db.query.userProfiles.findFirst({
|
|
where: eq(userProfiles.userId, ctx.userId),
|
|
});
|
|
return NextResponse.json({ data: profile?.preferences ?? {} });
|
|
} catch (error) {
|
|
return errorResponse(error);
|
|
}
|
|
});
|
|
|
|
export const PATCH = withAuth(async (req, ctx) => {
|
|
try {
|
|
const patch = await parseBody(req, updateUserPreferencesSchema);
|
|
|
|
const profile = await db.query.userProfiles.findFirst({
|
|
where: eq(userProfiles.userId, ctx.userId),
|
|
});
|
|
if (!profile) {
|
|
return NextResponse.json({ error: 'Profile not found' }, { status: 404 });
|
|
}
|
|
|
|
const next: UserPreferences = {
|
|
...(profile.preferences ?? {}),
|
|
...patch,
|
|
};
|
|
|
|
await db
|
|
.update(userProfiles)
|
|
.set({ preferences: next })
|
|
.where(eq(userProfiles.userId, ctx.userId));
|
|
|
|
return NextResponse.json({ data: next });
|
|
} catch (error) {
|
|
return errorResponse(error);
|
|
}
|
|
});
|