Files
hats-app/app/admin/administration/company/page.tsx
T
Ichsan Kurniawan 7f8e6637e4 Move auth config and build admin menus
Extract NextAuth configuration into a shared library, load admin sidebar items from role permissions, and update related RBAC types and UI.
2026-11-06 18:25:54 +07:00

72 lines
2.4 KiB
TypeScript

import { type Metadata } from 'next';
import { Suspense, lazy } from 'react';
import { getServerSession } from 'next-auth';
import { Download } from 'lucide-react'
import { Button } from '@/components/ui/button';
import { type ResponseData } from '@/types/types';
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card';
import LazyLoading from '@/components/loader/LazyLoading';
import { authOptions } from '@/lib/auth';
const ComponentPage = lazy(() => import('./component'));
export const metadata: Metadata = {
title: "Admin | Company",
}
async function getData() {
const { BASE_URL_API } = process.env
const session = await getServerSession(authOptions)
const res = await fetch(BASE_URL_API + '/company', {
headers: {
"Content-Type": "application/json",
Authorization: `Bearer ${session?.user.access_token}`,
},
cache: 'no-cache',
next: {
tags: ['company']
}
})
const data: ResponseData = await res.json()
// Recommendation: handle errors
if (!res.ok) {
// This will activate the closest `error.js` Error Boundary
throw new Error(`Failed to fetch data, ${data.code || res.status} ${data.message || res.statusText}`)
}
return data.data
}
export default async function CompanyPage() {
const data = await getData()
return (
<>
<div className="flex flex-col">
<Card>
<CardHeader className='flex flex-row items-center justify-between space-y-2 sm:space-y-0'>
<div>
<CardTitle>Company</CardTitle>
<CardDescription>Here&apos;s a list of companies that have been registered!</CardDescription>
</div>
<div className="flex items-center space-x-2">
<Button className="sm:hidden" size={'icon'}><Download size={20} /></Button>
</div>
</CardHeader>
<CardContent>
<Suspense fallback={<LazyLoading />}>
<ComponentPage
data={data.company}
/>
</Suspense>
</CardContent>
</Card>
</div>
</>
);
}