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.
47 lines
1.8 KiB
TypeScript
47 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 ILeaveSickPermit } 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 LeavePermitHistory({ 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('/application-form/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: ILeaveSickPermit) => (
|
|
item.category_name?.toLowerCase() === text ||
|
|
item.contact_street?.toLowerCase() === text ||
|
|
item.contact_city?.toLowerCase() === text ||
|
|
item.note?.toLowerCase() === text ||
|
|
item.approved_by?.toLowerCase().includes(text) ||
|
|
item.rejected_by?.toLowerCase().includes(text)
|
|
))
|
|
}
|
|
return data.history
|
|
}
|
|
return []
|
|
}
|
|
|
|
|
|
return (
|
|
<Suspense fallback={<LazyLoading />}>
|
|
<DataTable data={getFilterData()} />
|
|
</Suspense>
|
|
);
|
|
} |