Files
hats-app/app/admin/administration/user/page.tsx
T
Ichsan Kurniawan 5cbded392a Add server API helper, logging & misc updates
Introduce a reusable serverApiCall helper and file-based logger (lib/server-api.ts, lib/logger.ts) to centralize backend requests, attach session auth, and capture request/response/error logs. Update server actions to use the new helper (updateProfileAction, changeAvatarAction) and ensure profile revalidation. Add client-side avatar upload size limit (5MB) and normalize avatar base64 payload. Add new OpenGraph/Twitter images, bump app version to v1.1.1, and add a v1.1.1 entry in release notes. Update default API/IMG env URLs and metadataBase fallback, fix minor release-notes link capitalization, and adjust a debug console.log in admin user page.
2026-02-09 14:48:03 +07:00

71 lines
2.3 KiB
TypeScript

import { type Metadata } from 'next';
import { Suspense, lazy } from 'react';
import { getServerSession } from 'next-auth';
import { authOptions } from '@/pages/api/auth/[...nextauth]';
import { type ResponseData } from '@/types/types';
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card';
import LazyLoading from '@/components/loader/LazyLoading';
import ExportComponent from './component/Export';
const ComponentPage = lazy(() => import('./component'));
export const metadata: Metadata = {
title: "Admin | User",
}
async function getData() {
const { BASE_URL_API } = process.env
const session = await getServerSession(authOptions)
console.log("SESSION ADMIN USER PAGE :", session)
const res = await fetch(BASE_URL_API + '/user', {
headers: {
"Content-Type": "application/json",
Authorization: `Bearer ${session?.user.access_token}`,
},
cache: 'no-cache',
next: {
tags: ['user']
}
})
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 UserPage() {
const data = await getData()
console.log("DATA USER LENGTH :", data?.user)
return (
<>
<div className="flex flex-col">
<Card>
<CardHeader className='flex flex-col md:flex-row items-center justify-between space-y-5 sm:space-y-0'>
<div>
<CardTitle>User</CardTitle>
<CardDescription className='mt-1'>Here&apos;s a list of employees that have been registered!</CardDescription>
</div>
<ExportComponent data={data.user} />
</CardHeader>
<CardContent>
<Suspense fallback={<LazyLoading />}>
<ComponentPage
data={data.user}
/>
</Suspense>
</CardContent>
</Card>
</div>
</>
);
}