Files
hats-app/app/(dashboard)/task/page.tsx
T
2026-04-20 17:13:49 +07:00

57 lines
2.1 KiB
TypeScript

// app/clients/page.tsx
import { Suspense } from 'react';
import HomeTask from './component/HomeTask';
import ClientGrid from './component/ClientGrid';
import AssignmentTable from './component/AssignmentTable';
import fetchData from '@/lib/fetchData';
import { IClient } from './types';
import { IProjectAssignment } from './type.assignment';
type Props = {
searchParams: Promise<{ view?: string; q?: string }>
};
export default async function ClientsPage({ searchParams }: Props) {
const params = await searchParams;
const view = params.view === 'table' ? 'table' : 'grid';
const query = (params.q || '').toLowerCase();
const getClient = fetchData('/client')
const getAssignment = fetchData('/project-assignment')
// Wait for the promises to resolve
const [allClients, allAssignments] = await Promise.all([getClient, getAssignment]);
// 3. Process Data for Grid View
const filteredClients = allClients.filter((c: IClient) =>
c.name.toLowerCase().includes(query) ||
c.endUser.toLowerCase().includes(query)
);
const flattenedAssignments = allAssignments.filter((c: IProjectAssignment) =>
c.project?.name?.toLowerCase().includes(query) ||
c.project?.name?.toLowerCase().includes(query) ||
c.im_name?.toLowerCase().includes(query) ||
c.im_code?.toLowerCase().includes(query) ||
c.wo_name?.toLowerCase().includes(query) ||
c.wo_code?.toLowerCase().includes(query)
);
return (
<div className="flex-1 space-y-8 p-6 sm:p-8 pt-6">
{/* The Shell manages the Search Input, Tabs, and "Add Client" Modal */}
<HomeTask currentView={view} currentQuery={query} />
{/* Render the correct view based on the URL */}
<Suspense fallback={<div className="animate-pulse h-96 bg-accent rounded-xl" />}>
{view === 'grid' ?
<ClientGrid clients={filteredClients} assignments={allAssignments} />
:
<AssignmentTable data={flattenedAssignments} />
}
</Suspense>
</div>
);
}