website refactor
This commit is contained in:
@@ -1,23 +0,0 @@
|
||||
'use client';
|
||||
|
||||
import React from 'react';
|
||||
import type { DashboardViewData } from '@/templates/view-data/DashboardViewData';
|
||||
import type { DashboardPageDto } from '@/lib/page-queries/page-dtos/DashboardPageDto';
|
||||
import { DashboardPresenter } from '@/lib/presenters/DashboardPresenter';
|
||||
import { DashboardTemplate } from '@/templates/DashboardTemplate';
|
||||
|
||||
interface DashboardPageClientProps {
|
||||
pageDto: DashboardPageDto;
|
||||
}
|
||||
|
||||
/**
|
||||
* Dashboard Page Client Component
|
||||
*
|
||||
* Uses Presenter to transform Page DTO into ViewData
|
||||
* Presenter is deterministic and side-effect free
|
||||
*/
|
||||
export function DashboardPageClient({ pageDto }: DashboardPageClientProps) {
|
||||
const viewData: DashboardViewData = DashboardPresenter.createViewData(pageDto);
|
||||
|
||||
return <DashboardTemplate data={viewData} />;
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
import { headers } from 'next/headers';
|
||||
import { redirect } from 'next/navigation';
|
||||
import { createRouteGuard } from '@/lib/auth/createRouteGuard';
|
||||
|
||||
interface DashboardLayoutProps {
|
||||
@@ -16,11 +17,14 @@ export default async function DashboardLayout({ children }: DashboardLayoutProps
|
||||
const pathname = headerStore.get('x-pathname') || '/';
|
||||
|
||||
const guard = createRouteGuard();
|
||||
await guard.enforce({ pathname });
|
||||
const result = await guard.enforce({ pathname });
|
||||
if (result.type === 'redirect') {
|
||||
redirect(result.to);
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="min-h-screen bg-deep-graphite">
|
||||
{children}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,25 +1,26 @@
|
||||
import { notFound, redirect } from 'next/navigation';
|
||||
import { DashboardPageQuery } from '@/lib/page-queries/page-queries/DashboardPageQuery';
|
||||
import { DashboardPageClient } from './DashboardPageClient';
|
||||
import { DashboardTemplate } from '@/templates/DashboardTemplate';
|
||||
|
||||
export default async function DashboardPage() {
|
||||
const result = await DashboardPageQuery.execute();
|
||||
const result = await DashboardPageQuery.execute();
|
||||
|
||||
// Handle result based on status
|
||||
switch (result.status) {
|
||||
case 'ok':
|
||||
// Pass Page DTO to client component
|
||||
return <DashboardPageClient pageDto={result.dto} />;
|
||||
|
||||
case 'notFound':
|
||||
notFound();
|
||||
|
||||
case 'redirect':
|
||||
redirect(result.to);
|
||||
|
||||
case 'error':
|
||||
// For now, treat as notFound. Could also show error page
|
||||
console.error('Dashboard error:', result.errorId);
|
||||
notFound();
|
||||
if (result.isErr()) {
|
||||
const error = result.getError();
|
||||
|
||||
// Handle different error types
|
||||
if (error === 'notFound') {
|
||||
notFound();
|
||||
} else if (error === 'redirect') {
|
||||
redirect('/');
|
||||
} else {
|
||||
// DASHBOARD_FETCH_FAILED or UNKNOWN_ERROR
|
||||
console.error('Dashboard error:', error);
|
||||
notFound();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Success
|
||||
const viewData = result.unwrap();
|
||||
return <DashboardTemplate viewData={viewData} />;
|
||||
}
|
||||
Reference in New Issue
Block a user