mirror of
https://github.com/ichsankurnia/hats-app.git
synced 2026-12-05 11:06:29 +00:00
ffcf3c6e58
This commit reorganizes client and project-assignment screens into dedicated grid/list components, adds a shared layout toggle via the URL query string, and updates task pages to render the selected view consistently. It also moves shared client form logic into a client folder, improves status badge formatting, extends LazyImage with custom image classes, and updates the illustration assets and Lucide dependency used in the task UI.
50 lines
2.2 KiB
TypeScript
50 lines
2.2 KiB
TypeScript
import { lazy, Suspense } from 'react';
|
|
import fetchData, { getQueryStringFilteredAssignments } from '@/lib/fetchData';
|
|
import { getFilteredAssignments, getFilteredClients } from './data';
|
|
import { Loader2 } from 'lucide-react';
|
|
|
|
const HomeTask = lazy(() => import('./component/HomeTask'));
|
|
const ProjectAssignment = lazy(() => import('./component/project-assignment/ProjectAssignment'));
|
|
const Client = lazy(() => import('./component/client/Client'));
|
|
|
|
type Props = {
|
|
searchParams: Promise<{ view?: string; q?: string; status?: string; sort?: string; layout?: string }>
|
|
};
|
|
|
|
export default async function ClientsPage({ searchParams }: Props) {
|
|
const searchParams_ = await searchParams;
|
|
|
|
const view = searchParams_.view === 'assignments' ? 'assignments' : 'clients';
|
|
const query = (searchParams_.q || '').toLowerCase();
|
|
const sort = (searchParams_.sort || '').toLowerCase();
|
|
const sortBy = sort || 'default';
|
|
const layout = searchParams_.layout === 'list' ? 'list' : 'grid';
|
|
|
|
const queryString = getQueryStringFilteredAssignments(searchParams_)
|
|
|
|
const getClient = fetchData('/client')
|
|
const getAssignment = fetchData(queryString ? `/project-assignment?${queryString}` : '/project-assignment')
|
|
|
|
const [allClients, allAssignments] = await Promise.all([getClient, getAssignment]);
|
|
|
|
const filteredClients = getFilteredClients(allClients, query, sortBy)
|
|
const filterAssignments = getFilteredAssignments(allAssignments, query, sortBy)
|
|
|
|
return (
|
|
<div className="flex-1 space-y-8 p-6 sm:p-8 pt-6">
|
|
|
|
<Suspense fallback={<div className='flex justify-center items-center h-48 gap-2'><Loader2 className="animate-spin" />Loading...</div>}>
|
|
<HomeTask currentView={view} />
|
|
</Suspense>
|
|
|
|
{/* Render the correct view based on the URL */}
|
|
<Suspense fallback={<div className="animate-pulse h-96 bg-accent rounded-xl" />}>
|
|
{view === 'clients' ?
|
|
<Client clients={filteredClients} initialLayout={layout} />
|
|
:
|
|
<ProjectAssignment data={filterAssignments} />
|
|
}
|
|
</Suspense>
|
|
</div>
|
|
);
|
|
} |