seubert-claims/ondeck/src/app/(dashboard)/admin/settings/page.tsx
lorentz 191698088b Manager overdue window: configurable via Admin > Settings
- Default 7 days: overdue tasks shown only within last N days
- New /api/admin/manager-settings endpoint (GET/PUT, AppSetting key)
- Workload API reads setting and applies to both summary count and per-user table
- Overdue card now shows 'past due within Nd' context label
- Admin > System Settings: new Manager Dashboard card with day input
2026-04-14 00:17:31 +00:00

108 lines
4.3 KiB
TypeScript

import { getServerSession } from 'next-auth'
import { authOptions } from '@/lib/auth'
import { redirect } from 'next/navigation'
import { prisma } from '@/lib/db'
import Link from 'next/link'
import { ArrowLeft, ArrowRight, CalendarRange, Database, Shield } from 'lucide-react'
import { Card, CardContent, CardHeader, CardTitle, CardDescription } from '@/components/ui/card'
import { Badge } from '@/components/ui/badge'
import { SystemSettingsForm } from './system-settings-form'
export const dynamic = 'force-dynamic'
export default async function SystemSettingsPage() {
const session = await getServerSession(authOptions)
if (!session?.user) redirect('/auth/signin')
const userRoles = (session.user as any).roles || []
if (!userRoles.includes('Admin')) redirect('/dashboard')
const [syncConfigs, appSettings] = await Promise.all([
prisma.syncConfig.findMany(),
prisma.appSetting.findMany(),
])
const syncEnabled = syncConfigs.find((c) => c.key === 'sync_enabled')?.value ?? 'false'
const syncSchedule = syncConfigs.find((c) => c.key === 'sync_schedule_cron')?.value ?? '0 2 * * *'
const settingsMap = Object.fromEntries(appSettings.map((s) => [s.key, s.value]))
const windowDays = settingsMap['renewal_group_window_days'] ?? '90'
const dateRule = settingsMap['renewal_group_date_rule'] ?? 'nearest-to-year-start'
const overdueWindowDays = parseInt(settingsMap['overdue_window_days'] ?? '7', 10)
const relatedPages = [
{
title: 'Renewal Groups',
description: 'Default grouping window and renewal date rules for the client setup wizard',
href: '/admin/renewal-settings',
icon: CalendarRange,
values: [`${windowDays}-day window`, dateRule],
},
{
title: 'Data Sync',
description: 'AFW synchronisation schedule and manual trigger',
href: '/admin/sync',
icon: Database,
values: [syncEnabled === 'true' ? 'Enabled' : 'Disabled', syncSchedule],
},
]
return (
<div className="container mx-auto py-8 max-w-3xl space-y-8">
<div className="flex items-center gap-2 text-sm text-muted-foreground">
<Link href="/admin" className="hover:text-foreground flex items-center gap-1">
<ArrowLeft className="h-3.5 w-3.5" /> Admin
</Link>
<span>/</span>
<span className="text-foreground font-medium">System Settings</span>
</div>
<div>
<h1 className="text-2xl font-bold flex items-center gap-2">
<Shield className="h-6 w-6" /> System Settings
</h1>
<p className="text-muted-foreground mt-1 text-sm">
System-wide configuration. Changes take effect immediately.
</p>
</div>
{/* Sync config inline editor */}
<SystemSettingsForm syncEnabled={syncEnabled === 'true'} syncSchedule={syncSchedule} overdueWindowDays={overdueWindowDays} />
{/* Links to subsection settings pages */}
<div>
<h2 className="text-base font-semibold mb-3">Feature Settings</h2>
<div className="space-y-3">
{relatedPages.map((page) => {
const Icon = page.icon
return (
<Link key={page.href} href={page.href}>
<Card className="hover:shadow-md transition-shadow cursor-pointer">
<CardHeader className="py-4">
<div className="flex items-center justify-between">
<div className="flex items-center gap-3">
<Icon className="h-5 w-5 text-muted-foreground" />
<div>
<CardTitle className="text-sm font-semibold">{page.title}</CardTitle>
<CardDescription className="text-xs mt-0.5">{page.description}</CardDescription>
</div>
</div>
<div className="flex items-center gap-2 shrink-0">
{page.values.map((v, i) => (
<Badge key={i} variant="secondary" className="text-xs font-normal">
{v}
</Badge>
))}
<ArrowRight className="h-4 w-4 text-muted-foreground ml-1" />
</div>
</div>
</CardHeader>
</Card>
</Link>
)
})}
</div>
</div>
</div>
)
}