Files
hats-app/app/performance/[id]/page.tsx
T
2025-12-23 18:49:34 +07:00

58 lines
2.6 KiB
TypeScript

import { FC, Suspense, lazy } from 'react';
import LazyLoading from '@/components/loader/LazyLoading';
import DateRangePicker from './components/DateRangePicker';
import { Metadata } from 'next';
import { getServerSession } from 'next-auth';
import { authOptions } from '@/pages/api/auth/[...nextauth]';
import dayjs from 'dayjs';
const Header = lazy(() => import('@/app/(dashboard)/components/Header'))
const PerformanceComponent = lazy(() => import('./components'))
type Props = {
params: Promise<{ id: string | undefined }>
searchParams: Promise<{ [key: string]: string | string[] | undefined }>
};
export async function generateMetadata({ searchParams }: any): Promise<Metadata> {
const session = await getServerSession(authOptions)
const start_date = (await searchParams)!.start_date
const end_date = (await searchParams)!.end_date
const date = start_date && end_date ? `from ${dayjs(start_date).format('MMM DD, YYYY')} to ${dayjs(end_date).format('MMM DD, YYYY')}` : 'the last 30 days'
return {
title: `${session?.user?.detail.fullname || 'User'}'s Performance in ${date} - HIS Attendance Task System (H.A.T.s)`,
}
}
const PerformancePage: FC<Props> = async ({ params, searchParams }) => {
const id = (await params).id
const start_date = (await searchParams)!.start_date
const end_date = (await searchParams)!.end_date
return (
<>
<div className='h-screen overflow-y-auto overflow-x-hidden'>
<Suspense fallback={<LazyLoading />}>
<Header />
</Suspense>
<div className='p-6 2xl:w-[1400px] mx-auto space-y-8'>
<div className="flex flex-col sm:flex-row items-start justify-between space-y-2 sm:space-y-0">
<div>
<h1 className="text-lg sm:text-3xl font-medium tracking-tight capitalize">Employee Perfomance</h1>
<p className="text-xs md:text-base text-muted-foreground w-1/2 mt-2 hidden md:block">Here is your store performance, we hope this helps you unlock insights and empower your decision for continues growth.</p>
</div>
<DateRangePicker />
</div>
<Suspense key={`${start_date}${end_date}`} fallback={<LazyLoading />}>
<PerformanceComponent id={id} start_date={start_date as string} end_date={end_date as string} />
</Suspense>
</div>
</div>
</>
);
}
export default PerformancePage;