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.
287 lines
18 KiB
TypeScript
287 lines
18 KiB
TypeScript
import { Suspense, lazy } from 'react';
|
|
import { type Metadata } from 'next';
|
|
import Link from 'next/link';
|
|
import dayjs from 'dayjs';
|
|
import { fetchDataWithPost } from '@/lib/fetchData';
|
|
import { Card, Card900, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card';
|
|
import Logout from './components/Logout';
|
|
import LazyLoading from '@/components/loader/LazyLoading';
|
|
|
|
import { type IProfile } from './components/type';
|
|
import { type IUser } from '@/app/admin/administration/user/component/type';
|
|
import { getServerSession } from 'next-auth';
|
|
import { authOptions } from '@/lib/auth';
|
|
|
|
const ForgotPassword = lazy(() => import('./components/ForgotPassword'));
|
|
const ChangeTheme = lazy(() => import("./components/ChangeTheme"))
|
|
const ChangePassword = lazy(() => import("./components/ChangePassword"))
|
|
const EditProfile = lazy(() => import("./components/EditProfile"))
|
|
const ChangeAvatar = lazy(() => import("./components/ChangeAvatar"))
|
|
|
|
export async function generateMetadata(): Promise<Metadata> {
|
|
const session = await getServerSession(authOptions)
|
|
|
|
return {
|
|
title: `${session?.user?.detail.fullname || 'User'}'s Profile - H.A.T.s`,
|
|
}
|
|
}
|
|
|
|
export default async function ProfilePage() {
|
|
const session = await getServerSession(authOptions)
|
|
const data: IProfile = await fetchDataWithPost('/user/profile', {}, 'default', { tags: ['profile-data'] })
|
|
|
|
return (
|
|
<>
|
|
<div className="flex-1 space-y-8 p-6 sm:p-8 pt-6 pb-8">
|
|
<h1 className="text-lg sm:text-3xl font-medium tracking-tight capitalize">Account Settings</h1>
|
|
<Card className=''>
|
|
<CardHeader className='flex flex-row items-center justify-between'>
|
|
<CardTitle>My Profile</CardTitle>
|
|
<Suspense fallback={<LazyLoading />}>
|
|
<EditProfile data={data} />
|
|
</Suspense>
|
|
</CardHeader>
|
|
<CardContent className='space-y-6 text-sm sm:text-base'>
|
|
<Card900 className='sm:px-3'>
|
|
<CardContent>
|
|
<Suspense fallback={<LazyLoading />}>
|
|
<ChangeAvatar nik={data.nik as string} existAvatar={data.avatar} />
|
|
</Suspense>
|
|
</CardContent>
|
|
</Card900>
|
|
<Card900 className='sm:px-5'>
|
|
<CardHeader>
|
|
<CardTitle className='text-base'>Personal Information</CardTitle>
|
|
<CardDescription>This is how others will see you on the site.</CardDescription>
|
|
</CardHeader>
|
|
<CardContent>
|
|
<div className='grid grid-cols-1 sm:grid-cols-2 font-medium gap-y-3'>
|
|
<div className='flex flex-col'>
|
|
<span className='text-muted-foreground'>Fullname</span>
|
|
<span>{data.fullname}</span>
|
|
</div>
|
|
<div className='flex flex-col'>
|
|
<span className='text-muted-foreground'>Nickname</span>
|
|
<span>{data.nickname}</span>
|
|
</div>
|
|
<div className='flex flex-col'>
|
|
<span className='text-muted-foreground'>Email Address</span>
|
|
<span className='lowercase'>{data.email}</span>
|
|
</div>
|
|
<div className='flex flex-col'>
|
|
<span className='text-muted-foreground'>Phone</span>
|
|
<span>{data.phone_number || '-'}</span>
|
|
</div>
|
|
<div className='flex flex-col'>
|
|
<span className='text-muted-foreground'>NIK</span>
|
|
<span>{data.nik || '-'}</span>
|
|
</div>
|
|
<div className='flex flex-col'>
|
|
<span className='text-muted-foreground'>NIKTG</span>
|
|
<span>{data.niktg || '-'}</span>
|
|
</div>
|
|
<div className='flex flex-col'>
|
|
<span className='text-muted-foreground'>Office Email</span>
|
|
<span className='lowercase'>{data.email_office || '-'}</span>
|
|
</div>
|
|
<div className='flex flex-col'>
|
|
<span className='text-muted-foreground'>Personal Email</span>
|
|
<span className='lowercase'>{data.email_personal || '-'}</span>
|
|
</div>
|
|
<div className='flex flex-col'>
|
|
<span className='text-muted-foreground'>Sex</span>
|
|
<span>{data.gender || 'Male'}</span>
|
|
</div>
|
|
<div className='flex flex-col'>
|
|
<span className='text-muted-foreground'>Birthday</span>
|
|
<span>{data.birthday ? dayjs(data.birthday).format('MMM DD, YYYY') : '-'}</span>
|
|
</div>
|
|
<div className='flex flex-col'>
|
|
<span className='text-muted-foreground'>Last Education</span>
|
|
<span>{data.last_education} {data.major}</span>
|
|
</div>
|
|
</div>
|
|
</CardContent>
|
|
</Card900>
|
|
<Card900 className='sm:px-5'>
|
|
<CardHeader>
|
|
<CardTitle className='text-base'>Address Information</CardTitle>
|
|
<CardDescription>Your address information, this is how others will see you on the site.</CardDescription>
|
|
</CardHeader>
|
|
<CardContent>
|
|
<div className='grid grid-cols-1 sm:grid-cols-2 font-medium gap-y-3'>
|
|
<div className='flex flex-col'>
|
|
<span className='text-muted-foreground'>Address</span>
|
|
<span>-</span>
|
|
</div>
|
|
<div className='flex flex-col'>
|
|
<span className='text-muted-foreground'>Village</span>
|
|
<span>-</span>
|
|
</div>
|
|
<div className='flex flex-col'>
|
|
<span className='text-muted-foreground'>District</span>
|
|
<span>-</span>
|
|
</div>
|
|
<div className='flex flex-col'>
|
|
<span className='text-muted-foreground'>City</span>
|
|
<span>-</span>
|
|
</div>
|
|
<div className='flex flex-col'>
|
|
<span className='text-muted-foreground'>Province</span>
|
|
<span>-</span>
|
|
</div>
|
|
<div className='flex flex-col'>
|
|
<span className='text-muted-foreground'>Zip code</span>
|
|
<span>-</span>
|
|
</div>
|
|
</div>
|
|
</CardContent>
|
|
</Card900>
|
|
<Card900 className='sm:px-5'>
|
|
<CardHeader>
|
|
<CardTitle className='text-base'>Work Information</CardTitle>
|
|
<CardDescription>Your work information, this is how others will see you on the site.</CardDescription>
|
|
</CardHeader>
|
|
<CardContent>
|
|
<div className='grid grid-cols-1 sm:grid-cols-2 font-medium gap-y-3'>
|
|
<div className='flex flex-col'>
|
|
<span className='text-muted-foreground'>Role</span>
|
|
<span>{data.role?.name}</span>
|
|
</div>
|
|
<div className='flex flex-col'>
|
|
<span className='text-muted-foreground'>Company</span>
|
|
<span>{data.company?.name}</span>
|
|
</div>
|
|
<div className='flex flex-col'>
|
|
<span className='text-muted-foreground'>Department</span>
|
|
<span>{data.division?.name} ({data.division?.code})</span>
|
|
</div>
|
|
<div className='flex flex-col'>
|
|
<span className='text-muted-foreground'>Area</span>
|
|
<span>-</span>
|
|
</div>
|
|
<div className='flex flex-col'>
|
|
<span className='text-muted-foreground'>Position</span>
|
|
<span>{data.position?.name || '-'}</span>
|
|
</div>
|
|
<div className='flex flex-col'>
|
|
<span className='text-muted-foreground'>Employee Type</span>
|
|
<span>{data.employee_type?.name || '-'}</span>
|
|
</div>
|
|
<div className='flex flex-col'>
|
|
<span className='text-muted-foreground'>Hire Date</span>
|
|
<span>{data.hire_date ? dayjs(data.hire_date).format('MMM DD, YYYY') : '-'}</span>
|
|
</div>
|
|
<div className='flex flex-col'>
|
|
<span className='text-muted-foreground'>Contract Expiration Date</span>
|
|
<span>{data.contract_expiration_date ? dayjs(data.contract_expiration_date).format('MMM DD, YYYY') : '-'}</span>
|
|
</div>
|
|
<div className='flex flex-col'>
|
|
<span className='text-muted-foreground'>Contract Count</span>
|
|
<span>{data.contract_count || '-'}</span>
|
|
</div>
|
|
<div className='flex flex-col'>
|
|
<span className='text-muted-foreground'>Status</span>
|
|
{data.status.code === 'A' ?
|
|
<div className="px-2 py-1.5 rounded-full bg-green-500 w-24 text-center text-white shadow">{data.status.name}</div>
|
|
:
|
|
<div className="px-2 py-1.5 rounded-full bg-zinc-500 w-24 text-center text-white shadow">{data.status.name}</div>
|
|
}
|
|
</div>
|
|
</div>
|
|
</CardContent>
|
|
</Card900>
|
|
<Card900 className='sm:px-5'>
|
|
<CardHeader>
|
|
<CardTitle className='text-base'>Password and Authentication</CardTitle>
|
|
<CardDescription>Make sure your account is secure by update your password.</CardDescription>
|
|
</CardHeader>
|
|
<CardContent>
|
|
<div className='flex flex-col sm:flex-row space-y-2 sm:space-y-0 sm sm:space-x-2'>
|
|
<Suspense fallback={<LazyLoading />}>
|
|
<ChangePassword data={{ nik: data.nik } as IUser} />
|
|
</Suspense>
|
|
<Suspense fallback={<LazyLoading />}>
|
|
<ForgotPassword />
|
|
</Suspense>
|
|
</div>
|
|
</CardContent>
|
|
</Card900>
|
|
<Card900 className='sm:px-5'>
|
|
<CardHeader>
|
|
<CardTitle className='text-base'>Theme Preferences</CardTitle>
|
|
<CardDescription>Choose how Super Apps looks to you. Select a single theme, or sync with your system and automatically switch between day and night themes.</CardDescription>
|
|
</CardHeader>
|
|
<CardContent>
|
|
<Suspense fallback={<LazyLoading />}>
|
|
<ChangeTheme />
|
|
</Suspense>
|
|
</CardContent>
|
|
</Card900>
|
|
|
|
<div className='space-y-4 block sm:hidden pt-3'>
|
|
{session?.user.detail.role.allow_admin_panel &&
|
|
<Link href='/admin' className='sm:hidden flex' prefetch>
|
|
<i className="ti ti-spy text-lg mr-3"></i>
|
|
<div className='w-full pb-3 flex items-center justify-between border-b border-border'>
|
|
<p>Admin Panel</p>
|
|
<i className="ti ti-chevron-right text-muted-foreground"></i>
|
|
</div>
|
|
</Link>
|
|
}
|
|
<Link href='/leave' className='sm:hidden flex' prefetch>
|
|
<i className="ti ti-speedboat text-lg mr-3"></i>
|
|
<div className='w-full pb-3 flex items-center justify-between border-b border-border'>
|
|
<p>Apply for Leave</p>
|
|
<i className="ti ti-chevron-right text-muted-foreground"></i>
|
|
</div>
|
|
</Link>
|
|
<Link href='/work-permit' className='sm:hidden flex' prefetch>
|
|
<i className="ti ti-stethoscope text-lg mr-3"></i>
|
|
<div className='w-full pb-3 flex items-center justify-between border-b border-border'>
|
|
<p>Permit & Sick</p>
|
|
<i className="ti ti-chevron-right text-muted-foreground"></i>
|
|
</div>
|
|
</Link>
|
|
<Link href={`/performance/${session?.user.detail.id}`} className='sm:hidden flex' prefetch>
|
|
<i className="ti ti-chart-area-line text-lg mr-3"></i>
|
|
<div className='w-full pb-3 flex items-center justify-between border-b border-border'>
|
|
<p>My Performance</p>
|
|
<i className="ti ti-chevron-right text-muted-foreground"></i>
|
|
</div>
|
|
</Link>
|
|
<Link href='/calendar' className='sm:hidden flex' prefetch>
|
|
<i className="ti ti-calendar text-lg mr-3"></i>
|
|
<div className='w-full pb-3 flex items-center justify-between border-b border-border'>
|
|
<p>H.A.T.s Calendar</p>
|
|
<i className="ti ti-chevron-right text-muted-foreground"></i>
|
|
</div>
|
|
</Link>
|
|
<Link href='/release-notes' className='sm:hidden flex' prefetch>
|
|
<i className="ti ti-notebook text-lg mr-3"></i>
|
|
<div className='w-full pb-3 flex items-center justify-between border-b border-border'>
|
|
<p>Release Notes</p>
|
|
<i className="ti ti-chevron-right text-muted-foreground"></i>
|
|
</div>
|
|
</Link>
|
|
</div>
|
|
<div className='text-center text-sm text-muted-foreground space-y-2'>
|
|
<div className="text-center pt-2 sm:pt-3">
|
|
<Link href="/terms" className="underline underline-offset-4 hover:text-primary">
|
|
{/* <Link href="/performance/1" className="underline underline-offset-4 hover:text-primary"> */}
|
|
Terms of Service
|
|
</Link>{" "}
|
|
and{" "}
|
|
<Link href="/privacy-policy" className="underline underline-offset-4 hover:text-primary">
|
|
Privacy Policy
|
|
</Link>
|
|
</div>
|
|
</div>
|
|
<Logout />
|
|
</CardContent>
|
|
</Card>
|
|
<p className='text-xs md:text-sm text-muted-foreground text-center'>App version <Link href={`/release-notes#${process.env.NEXT_PUBLIC_APP_VERSION}`} className="underline hover:text-blue-500 duration-200">{process.env.NEXT_PUBLIC_APP_VERSION}</Link> </p>
|
|
</div>
|
|
</>
|
|
);
|
|
} |