feat(platform): residential module + admin UI + reliability fixes
Residential platform - New schema: residentialClients, residentialInterests (separate from marina/yacht clients) with migration 0010 - Service layer with CRUD + audit + sockets + per-port portal toggle - v1 + public API routes (/api/v1/residential/*, /api/public/residential-inquiries) - List + detail pages with inline editing for clients and interests - Per-user residentialAccess toggle on userPortRoles (migration 0011) - Permission keys: residential_clients, residential_interests - Sidebar nav + role form integration - Smoke spec covering page loads, UI create flow, public endpoint Admin & shared UI - Admin → Forms (form templates CRUD) with validators + service - Notification preferences page (in-app + email per type) - Email composition + accounts list + threads view - Branded auth shell shared across CRM + portal auth surfaces - Inline editing extended to yacht/company/interest detail pages - InlineTagEditor + per-entity tags endpoints (yachts, companies) - Notes service polymorphic across clients/interests/yachts/companies - Client list columns: yachtCount + companyCount badges - Reservation file-download via presigned URL (replaces stale <a href>) Route handler refactor - Extracted yachts/companies/berths reservation handlers to sibling handlers.ts files (Next.js 15 route.ts only allows specific exports) Reliability fixes - apiFetch double-stringify bug fixed across 13 components (apiFetch already JSON.stringifies its body; passing a stringified body produced double-encoded JSON which failed zod validation) - SocketProvider gated behind useSyncExternalStore-based mount check to avoid useSession() SSR crashes under React 19 + Next 15 - apiFetch falls back to URL-pathname → port-id resolution when the Zustand store hasn't hydrated yet (fresh contexts, e2e tests) - CRM invite flow (schema, service, route, email, dev script) - Dashboard route → [portSlug]/dashboard/page.tsx + redirect - Document the dev-server restart-after-migration gotcha in CLAUDE.md Tests - 5-case residential smoke spec - Integration test updates for new service signatures Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
131
src/components/notifications/notification-preferences-form.tsx
Normal file
131
src/components/notifications/notification-preferences-form.tsx
Normal file
@@ -0,0 +1,131 @@
|
||||
'use client';
|
||||
|
||||
import { useEffect, useState } from 'react';
|
||||
import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query';
|
||||
import { toast } from 'sonner';
|
||||
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { Switch } from '@/components/ui/switch';
|
||||
import { apiFetch } from '@/lib/api/client';
|
||||
|
||||
interface Pref {
|
||||
notificationType: string;
|
||||
inApp: boolean;
|
||||
email: boolean;
|
||||
}
|
||||
|
||||
const KNOWN_TYPES: Array<{ key: string; label: string; description: string }> = [
|
||||
{
|
||||
key: 'mention',
|
||||
label: 'Mentions',
|
||||
description: 'When someone @-mentions you in a note.',
|
||||
},
|
||||
{
|
||||
key: 'reminder_overdue',
|
||||
label: 'Overdue Reminders',
|
||||
description: 'When an interest reminder you own becomes overdue.',
|
||||
},
|
||||
{
|
||||
key: 'interest_stage_changed',
|
||||
label: 'Interest Stage Changes',
|
||||
description: 'When a pipeline stage changes on an interest assigned to you.',
|
||||
},
|
||||
{
|
||||
key: 'system_alert',
|
||||
label: 'System Alerts',
|
||||
description: 'Background job failures and maintenance notices.',
|
||||
},
|
||||
];
|
||||
|
||||
export function NotificationPreferencesForm() {
|
||||
const qc = useQueryClient();
|
||||
const { data, isLoading } = useQuery<Pref[]>({
|
||||
queryKey: ['notifications', 'preferences'],
|
||||
queryFn: () =>
|
||||
apiFetch<{ data: Pref[] }>('/api/v1/notifications/preferences').then((r) => r.data),
|
||||
});
|
||||
|
||||
const [prefs, setPrefs] = useState<Map<string, Pref>>(new Map());
|
||||
|
||||
useEffect(() => {
|
||||
const map = new Map<string, Pref>();
|
||||
for (const t of KNOWN_TYPES) {
|
||||
map.set(t.key, { notificationType: t.key, inApp: true, email: true });
|
||||
}
|
||||
if (data) {
|
||||
for (const p of data) {
|
||||
map.set(p.notificationType, p);
|
||||
}
|
||||
}
|
||||
setPrefs(map);
|
||||
}, [data]);
|
||||
|
||||
const mutation = useMutation({
|
||||
mutationFn: async () => {
|
||||
const payload = { preferences: Array.from(prefs.values()) };
|
||||
return apiFetch('/api/v1/notifications/preferences', {
|
||||
method: 'PUT',
|
||||
body: payload,
|
||||
});
|
||||
},
|
||||
onSuccess: () => {
|
||||
toast.success('Preferences saved');
|
||||
qc.invalidateQueries({ queryKey: ['notifications', 'preferences'] });
|
||||
},
|
||||
onError: (err) => toast.error(err instanceof Error ? err.message : 'Save failed'),
|
||||
});
|
||||
|
||||
function update(type: string, field: 'inApp' | 'email', value: boolean) {
|
||||
setPrefs((prev) => {
|
||||
const next = new Map(prev);
|
||||
const existing = next.get(type) ?? { notificationType: type, inApp: true, email: true };
|
||||
next.set(type, { ...existing, [field]: value });
|
||||
return next;
|
||||
});
|
||||
}
|
||||
|
||||
if (isLoading) {
|
||||
return <div className="text-sm text-muted-foreground">Loading preferences…</div>;
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="space-y-4">
|
||||
<div className="rounded-lg border divide-y">
|
||||
<div className="grid grid-cols-[1fr_auto_auto] gap-4 px-4 py-2 text-xs font-medium uppercase text-muted-foreground">
|
||||
<div>Type</div>
|
||||
<div className="w-16 text-center">In-app</div>
|
||||
<div className="w-16 text-center">Email</div>
|
||||
</div>
|
||||
{KNOWN_TYPES.map((t) => {
|
||||
const pref = prefs.get(t.key) ?? {
|
||||
notificationType: t.key,
|
||||
inApp: true,
|
||||
email: true,
|
||||
};
|
||||
return (
|
||||
<div
|
||||
key={t.key}
|
||||
className="grid grid-cols-[1fr_auto_auto] gap-4 px-4 py-3 items-center"
|
||||
>
|
||||
<div>
|
||||
<div className="text-sm font-medium">{t.label}</div>
|
||||
<div className="text-xs text-muted-foreground">{t.description}</div>
|
||||
</div>
|
||||
<div className="w-16 flex justify-center">
|
||||
<Switch checked={pref.inApp} onCheckedChange={(v) => update(t.key, 'inApp', v)} />
|
||||
</div>
|
||||
<div className="w-16 flex justify-center">
|
||||
<Switch checked={pref.email} onCheckedChange={(v) => update(t.key, 'email', v)} />
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
<div className="flex justify-end">
|
||||
<Button onClick={() => mutation.mutate()} disabled={mutation.isPending}>
|
||||
{mutation.isPending ? 'Saving…' : 'Save preferences'}
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user