45 lines
1.2 KiB
TypeScript
45 lines
1.2 KiB
TypeScript
import { redirect } from 'next/navigation';
|
|
import { DriverProfilePageQuery } from '@/lib/page-queries/page-queries/DriverProfilePageQuery';
|
|
import { DriverProfilePageClient } from './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('/404');
|
|
case 'redirect':
|
|
redirect(result.to);
|
|
case 'error':
|
|
// Pass error to client component
|
|
return (
|
|
<DriverProfilePageClient
|
|
pageDto={null}
|
|
error={result.errorId}
|
|
/>
|
|
);
|
|
case 'ok':
|
|
const pageDto = result.dto;
|
|
const hasData = !!pageDto.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={pageDto}
|
|
/>
|
|
);
|
|
}
|
|
} |