mirror of
https://github.com/ichsankurnia/hats-app.git
synced 2026-12-05 10:46:29 +00:00
7f8e6637e4
Extract NextAuth configuration into a shared library, load admin sidebar items from role permissions, and update related RBAC types and UI.
46 lines
1.8 KiB
TypeScript
46 lines
1.8 KiB
TypeScript
import { Suspense, lazy } from 'react';
|
|
import { getServerSession } from 'next-auth';
|
|
import dayjs from 'dayjs';
|
|
import { fetchDataWithPost } from '@/lib/fetchData';
|
|
import LazyLoading from '@/components/loader/LazyLoading';
|
|
import { type IHistory } from '../components/type';
|
|
import { authOptions } from '@/lib/auth';
|
|
|
|
const DataTable = lazy(() => import('./DataTable'));
|
|
|
|
type Props = {
|
|
searchParams: Promise<{ [key: string]: string | string[] | undefined }>
|
|
};
|
|
|
|
export default async function AttendanceHistory({ searchParams }: Props) {
|
|
const start_date = (await searchParams)!.start_date
|
|
const end_date = (await searchParams)!.end_date
|
|
const search = (await searchParams)!.search
|
|
|
|
const session = await getServerSession(authOptions)
|
|
const data = await fetchDataWithPost('/presence/history', { nik: session?.user.detail.nik, start_date: start_date || dayjs().subtract(1, 'month'), end_date: end_date || dayjs().add(1, 'month').format('YYYY-MM-DD') })
|
|
|
|
const getFilterData = () => {
|
|
if (data.history && data.history.length > 0) {
|
|
if (search) {
|
|
const text = search.toString().toLowerCase()
|
|
return data.history.filter((item: IHistory) => (
|
|
item.working_status?.toLowerCase() === text ||
|
|
item.location_name?.toLowerCase().includes(text) ||
|
|
item.device?.name?.toLowerCase().includes(text) ||
|
|
item.area?.name?.toLowerCase().includes(text) ||
|
|
item.note?.toLowerCase().includes(text)
|
|
))
|
|
}
|
|
return data.history
|
|
}
|
|
return []
|
|
}
|
|
|
|
|
|
return (
|
|
<Suspense fallback={<LazyLoading />}>
|
|
<DataTable data={getFilterData()} />
|
|
</Suspense>
|
|
);
|
|
} |