mirror of
https://github.com/ichsankurnia/hats-app.git
synced 2026-12-05 11:06:29 +00:00
279b642a7a
Enforce page access and action-level permissions across admin and task views, including exports and record actions. Move user creation to a client component behind server-side permission checks, standardize data fetching, and remove the deprecated user-role route.
83 lines
3.6 KiB
TypeScript
83 lines
3.6 KiB
TypeScript
import { lazy, Suspense } from 'react';
|
|
import type { Metadata } from 'next';
|
|
import { getFilteredClients } from './data';
|
|
import { getClients } from './utils/queries';
|
|
import { Loader2 } from 'lucide-react';
|
|
import { getNonAdminAccessPagePermission } from '@/lib/get-access-data';
|
|
|
|
const HomeTask = lazy(() => import('./component/HomeTask'));
|
|
const Client = lazy(() => import('./component/client/Client'));
|
|
|
|
type Props = {
|
|
searchParams: Promise<{ view?: string; q?: string; status?: string; sort?: string; layout?: string }>
|
|
};
|
|
|
|
export async function generateMetadata(): Promise<Metadata> {
|
|
try {
|
|
const allClients = await getClients();
|
|
const clientCount = Array.isArray(allClients) ? allClients.length : 0;
|
|
const description = clientCount > 0
|
|
? `Manage ${clientCount} clients, project assignments, work orders, internal memos, and team task assignments.`
|
|
: 'Manage client project assignments, work orders, internal memos, and team task assignments.';
|
|
|
|
return {
|
|
title: 'Task Management (Client Overview) - HIS Attendance Task System (H.A.T.s)',
|
|
description,
|
|
openGraph: {
|
|
title: 'Task Management (Client Overview) - HIS Attendance Task System (H.A.T.s)',
|
|
description,
|
|
},
|
|
twitter: {
|
|
title: 'Task Management (Client Overview) - HIS Attendance Task System (H.A.T.s)',
|
|
description,
|
|
},
|
|
};
|
|
} catch {
|
|
return {
|
|
title: 'Task Management - HIS Attendance Task System (H.A.T.s)',
|
|
description: 'Manage client project assignments, work orders, internal memos, and team task assignments.',
|
|
};
|
|
}
|
|
}
|
|
|
|
export default async function ClientsPage({ searchParams }: Props) {
|
|
const actions = await getNonAdminAccessPagePermission('/task', 'VIEW')
|
|
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 === 'grid' ? 'grid' : 'list';
|
|
|
|
// const queryString = getQueryStringFilteredAssignments(searchParams_)
|
|
|
|
const allClients = await getClients();
|
|
// 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-4 sm:p-8 pt-4 sm:pt-6">
|
|
|
|
<Suspense fallback={<div className='flex justify-center items-center h-48 gap-2'><Loader2 className="animate-spin" />Loading...</div>}>
|
|
<HomeTask clients={allClients} />
|
|
</Suspense>
|
|
|
|
<Suspense fallback={<div className="animate-pulse h-96 bg-accent rounded-xl" />}>
|
|
<Client clients={filteredClients} initialLayout={layout} actions={actions} />
|
|
</Suspense>
|
|
{/* <Suspense fallback={<div className="animate-pulse h-96 bg-accent rounded-xl" />}>
|
|
{view === 'clients' ?
|
|
<Client clients={filteredClients} initialLayout={layout} />
|
|
:
|
|
<ProjectAssignment data={filterAssignments} layout={layout} />
|
|
}
|
|
</Suspense> */}
|
|
</div>
|
|
);
|
|
}
|