Files
gridpilot.gg/apps/website/app/drivers/[id]/page.tsx
2026-01-14 10:51:05 +01:00

46 lines
1.3 KiB
TypeScript

import { redirect } from 'next/navigation';
import { routes } from '@/lib/routing/RouteConfig';
import { DriverProfilePageQuery } from '@/lib/page-queries/page-queries/DriverProfilePageQuery';
import { DriverProfilePageClient } from '@/components/drivers/DriverProfilePageClient';
export default async function DriverProfilePage({ params }: { params: { id: string } }) {
// Execute the page query
const result = await DriverProfilePageQuery.execute(params.id);
// Handle different result statuses
switch (result.status) {
case 'notFound':
redirect(routes.error.notFound);
case 'redirect':
redirect(result.to);
case 'error':
// Pass error to client component
return (
<DriverProfilePageClient
pageDto={null}
error={result.errorId}
/>
);
case 'ok':
const viewModel = result.dto;
const hasData = !!viewModel.currentDriver;
if (!hasData) {
return (
<DriverProfilePageClient
pageDto={null}
empty={{
title: 'Driver not found',
description: 'The driver profile may not exist or you may not have access',
}}
/>
);
}
return (
<DriverProfilePageClient
pageDto={viewModel}
/>
);
}
}