72 lines
1.7 KiB
TypeScript
72 lines
1.7 KiB
TypeScript
import { getServerSession } from 'next-auth'
|
|
import { authOptions } from '@/lib/auth'
|
|
import { redirect } from 'next/navigation'
|
|
import { prisma } from '@/lib/db'
|
|
import { ClientDetail } from '@/components/clients/client-detail'
|
|
|
|
// Force dynamic rendering to avoid stale cached data
|
|
export const dynamic = 'force-dynamic'
|
|
|
|
export default async function ClientDetailPage({
|
|
params,
|
|
}: {
|
|
params: Promise<{ id: string }>
|
|
}) {
|
|
const session = await getServerSession(authOptions)
|
|
|
|
if (!session?.user) {
|
|
redirect('/auth/signin')
|
|
}
|
|
|
|
const { id } = await params
|
|
|
|
const client = await prisma.client.findUnique({
|
|
where: { id },
|
|
include: {
|
|
designation: true,
|
|
designation2: true,
|
|
policies: {
|
|
orderBy: { expirationDate: 'desc' },
|
|
},
|
|
tasks: {
|
|
include: {
|
|
assignments: {
|
|
include: {
|
|
user: {
|
|
select: {
|
|
displayName: true,
|
|
email: true,
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
orderBy: { dueDate: 'asc' },
|
|
},
|
|
},
|
|
})
|
|
|
|
if (!client) {
|
|
redirect('/clients')
|
|
}
|
|
|
|
// Convert Decimal types to numbers for client components
|
|
const clientData = {
|
|
...client,
|
|
policies: client.policies.map(policy => ({
|
|
...policy,
|
|
premiumAmount: policy.premiumAmount ? Number(policy.premiumAmount) : null,
|
|
})),
|
|
}
|
|
|
|
const designations = await prisma.designation.findMany({
|
|
where: { isActive: true },
|
|
orderBy: { displayOrder: 'asc' },
|
|
})
|
|
|
|
return (
|
|
<div className="container mx-auto py-8">
|
|
<ClientDetail client={clientData} designations={designations} />
|
|
</div>
|
|
)
|
|
}
|