seubert-claims/ondeck/src/app/(dashboard)/clients/page.tsx
lorentz b036a93da2 Initial commit: OnDeck project
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-18 13:20:52 +00:00

81 lines
2 KiB
TypeScript

import { getServerSession } from 'next-auth'
import { authOptions } from '@/lib/auth'
import { redirect } from 'next/navigation'
import { prisma } from '@/lib/db'
import { ClientList } from '@/components/clients/client-list'
export default async function ClientsPage() {
const session = await getServerSession(authOptions)
if (!session?.user) {
redirect('/auth/signin')
}
// Fetch designations for filter
const designations = await prisma.designation.findMany({
where: { isActive: true },
orderBy: { displayOrder: 'asc' },
})
// Fetch initial clients
const clientsRaw = await prisma.client.findMany({
take: 20,
orderBy: { name: 'asc' },
include: {
designation: true,
designation2: true,
policies: {
where: {
expirationDate: {
gte: new Date(),
},
},
orderBy: {
expirationDate: 'asc',
},
take: 1,
select: {
id: true,
policyNumber: true,
expirationDate: true,
policyType: true,
carrierName: true,
writingCompanyName: true,
department: true,
executiveName: true,
csrName: true,
status: true,
premiumAmount: true,
},
},
_count: {
select: {
policies: true,
tasks: true,
},
},
},
})
// Convert Decimal types to numbers for client components
const clients = clientsRaw.map(client => ({
...client,
policies: client.policies.map(policy => ({
...policy,
premiumAmount: policy.premiumAmount ? Number(policy.premiumAmount) : null,
})),
}))
return (
<div className="container mx-auto py-8">
<div className="mb-8">
<h1 className="text-3xl font-bold">Clients</h1>
<p className="text-muted-foreground mt-2">
Manage your client portfolio and policy renewals
</p>
</div>
<ClientList initialClients={clients} designations={designations} />
</div>
)
}