initial commit for new hats app

This commit is contained in:
Ichsan Kurniawan
2025-12-19 13:57:55 +07:00
parent aa949d71ff
commit 7e172f5cf7
314 changed files with 31102 additions and 208 deletions
@@ -0,0 +1,156 @@
'use client'
import { FC } from 'react';
import Chart from 'react-apexcharts';
import { type ApexOptions } from 'apexcharts';
import { useTheme } from 'next-themes';
import useMobileView from '@/hooks/useMobileView';
import { getArrayRandomNumber, getLastNDays } from '@/lib/helper';
type Props = {
data: any
};
const AreaChart: FC<Props> = ({ data }) => {
const { theme, systemTheme } = useTheme()
const { windowWidth } = useMobileView()
const options: ApexOptions = {
chart: {
type: 'area',
fontFamily: 'Inter, Arial, sans-serif',
toolbar: {
show: false
},
offsetX: windowWidth < 400 ? 430 : windowWidth < 600 ? 390 : 0
},
colors: ['#f43f5e', '#22c55e'],
legend: {
position: 'top',
show: true,
fontSize: '16px',
labels: {
colors: theme === 'dark' ? '#fff' : theme === 'system' && systemTheme === 'dark' ? '#fff' : '#000',
useSeriesColors: false
},
},
dataLabels: {
enabled: false,
},
stroke: {
show: true,
curve: 'smooth',
width: 2,
},
xaxis: {
type: 'datetime',
categories: getLastNDays(30),
labels: {
show: true,
rotateAlways: true,
minHeight: 40,
maxHeight: 40,
format: 'dd/MM',
style: {
colors: theme === 'dark' ? '#a1a1aa' : theme === 'system' && systemTheme === 'dark' ? '#a1a1aa' : '#71717a',
fontSize: '14px',
}
}
},
yaxis: {
// tickAmount: 24,
min: 0,
max: 24,
labels: {
formatter: (val) => val.toFixed(0),
style: {
colors: theme === 'dark' ? '#a1a1aa' : theme === 'system' && systemTheme === 'dark' ? '#a1a1aa' : '#71717a',
fontSize: '14px',
}
}
},
grid: {
yaxis: {
lines: { show: false }
},
padding: {
right: 25 // Also you may want to increase this (based on the length of your labels)
},
},
fill: {
type: 'gradient',
gradient: {
shadeIntensity: 1,
inverseColors: false,
opacityFrom: 0.5,
opacityTo: 0.1,
stops: [20, 100, 100, 100]
},
},
tooltip: {
theme: theme === 'dark' ? 'dark' : theme === 'system' && systemTheme === 'dark' ? 'dark' : 'light',
style: { fontSize: '14px' },
x: {
format: 'MMM dd, yyyy'
},
y: {
formatter: (val) => val.toFixed(2)
}
},
responsive: [{
breakpoint: 800,
options: {
legend: { fontSize: '14px' },
yaxis: {
min: 0,
max: 24,
labels: {
formatter: (val: any) => val.toFixed(0),
style: {
colors: theme === 'dark' ? '#a1a1aa' : theme === 'system' && systemTheme === 'dark' ? '#a1a1aa' : '#71717a',
fontSize: '12px',
}
}
},
xaxis: {
labels: {
rotateAlways: true,
minHeight: 35,
maxHeight: 35,
style: {
colors: theme === 'dark' ? '#a1a1aa' : theme === 'system' && systemTheme === 'dark' ? '#a1a1aa' : '#71717a',
fontSize: '12px',
}
}
},
},
}]
}
const series = [
{
name: 'Check-Out',
data: getArrayRandomNumber(30, 17, 24)
},
{
name: 'Check-In',
data: getArrayRandomNumber(30, 8, 11)
}
]
return (
<>
{/* <div className='h-[400px] 2xl:h-[500px] flex items-center justify-center -mt-3 overflow-hidden overflow-x-auto max-w-[300px] sm:max-w-full'> */}
<div className='h-[400px] 2xl:h-[500px] flex items-center justify-center -mt-3 overflow-hidden overflow-x-auto' style={{ maxWidth: windowWidth > 760 ? '100%' : windowWidth > 400 ? 400 : 310 }}>
<Chart
type='area'
options={options}
series={series}
width={windowWidth > 1900 ? '450%' : windowWidth > 1500 ? '420%' : windowWidth > 1280 ? '405%' : windowWidth > 760 ? 640 : '390%'}
height='100%'
/>
</div>
</>
);
}
export default AreaChart;
@@ -0,0 +1,101 @@
'use client'
import { FC } from 'react';
import Chart from 'react-apexcharts';
import { type ApexOptions } from 'apexcharts';
import { useTheme } from 'next-themes';
type Props = {
data: number[]
labels: string[]
colors: string[]
};
const DonutChart: FC<Props> = ({ data, labels, colors }) => {
const { theme, systemTheme } = useTheme()
const options: ApexOptions = {
chart: {
width: 200,
height: 200,
events: {
click(e, chart, options) {
// const { seriesIndex, dataPointIndex } = options
const { selectedDataPoints } = options.globals
// console.log(selectedDataPoints)
if (selectedDataPoints.length > 0) {
}
},
},
},
plotOptions: {
pie: {
expandOnClick: true,
donut: {
size: '55%',
labels: {
show: true,
name: {
show: true,
color: theme === 'dark' ? '#fff' : theme === 'system' && systemTheme === 'dark' ? '#fff' : '#000',
fontSize: '20px',
fontWeight: 'bold'
},
value: {
show: true,
color: theme === 'dark' ? '#fff' : theme === 'system' && systemTheme === 'dark' ? '#fff' : '#000',
fontSize: '32px',
fontWeight: 'bold'
},
total: {
show: false
},
},
},
}
},
legend: {
show: false,
},
stroke: {
width: 0
},
dataLabels: {
enabled: true,
formatter: function (val: any, opts) {
// console.log(opts)
return opts.w.globals.labels[opts.seriesIndex] + ': ' + opts.w.globals.series[opts.seriesIndex]
// return opts.w.globals.series[opts.seriesIndex]
},
},
fill: {
type: 'gradient',
},
labels: labels,
colors: colors,
responsive: [{
breakpoint: 800,
options: {
chart: {
width: 200
}
}
}]
}
const series = data
return (
<>
<div className='flex items-center justify-center'>
<Chart
type='donut'
options={options}
series={series}
width={250}
/>
</div>
</>
);
}
export default DonutChart;
@@ -0,0 +1,293 @@
'use client'
import { ChangeEvent, FC, useEffect, useState } from 'react';
import { Table } from 'antd';
import dayjs from 'dayjs';
import { TableProps, type ColumnsType } from 'antd/es/table';
import { Input } from '@/components/ui/input';
import { IHistory } from '@/app/(dashboard)/history/components/type';
import { Badge } from '@/components/ui/badge';
import { getVariantApproved, getVariantWorkingStatus } from '@/lib/helper';
import useMobileView from '@/hooks/useMobileView';
type Props = {
data: IHistory[]
};
const TableAttendanceHistory: FC<Props> = ({ data }) => {
const [filterData, setFilterData] = useState<IHistory[]>([])
const { isMobile, windowWidth } = useMobileView()
useEffect(() => {
if (data) {
setFilterData(data)
}
}, [data])
const handleSearch = (e: ChangeEvent<HTMLInputElement>) => {
const text = e.target.value
if (text) {
const newData = [...data!].filter(item => (
item.user.fullname?.toLowerCase().includes(text.toLowerCase()) ||
item.working_status?.toLowerCase().includes(text.toLowerCase()) ||
item.device.name?.toLowerCase().includes(text.toLowerCase()) ||
item.location_name?.toLowerCase().includes(text.toLowerCase()) ||
item.note?.toLowerCase().includes(text.toLowerCase()) ||
item.presence_checkout?.location_name?.toLowerCase().includes(text.toLowerCase()) ||
item.presence_checkout?.note?.toLowerCase().includes(text.toLowerCase())
))
setFilterData(newData)
} else {
setFilterData(data)
}
}
const Columns: ColumnsType<IHistory> = [
{
title: 'Date',
dataIndex: 'presence_date',
sorter: ((a, b) => (dayjs(a.presence_date).isAfter(dayjs(b.presence_date)) ? 1 : -1)),
render: (val) => dayjs(val).format('MMM DD, YYYY')
},
{
title: 'Name',
dataIndex: 'fullname',
sorter: (a, b) => a.user.fullname.localeCompare(b.user.fullname),
render: (val, record) => record.user.fullname
},
{
title: 'Working Status',
dataIndex: 'working_status',
filters: [
{
text: 'WFO',
value: 'WFO',
},
{
text: 'WFS',
value: 'WFS',
},
{
text: 'WFH',
value: 'WFH',
},
{
text: 'Sakit',
value: 'SKT',
},
{
text: 'Izin',
value: 'IZ01',
}
],
onFilter: (value, record) => record.working_status!.indexOf(value as string) === 0,
sorter: (a, b) => a.working_status?.localeCompare(b.working_status),
render: (val, record) => <Badge variant={getVariantWorkingStatus(val)}>{val}</Badge>
},
{
title: 'Approval',
dataIndex: 'status',
filters: [
{
text: 'Approved',
value: 'AP',
},
{
text: 'Rejected',
value: 'R',
},
{
text: 'Need to be Appove',
value: 'NA',
}
],
onFilter: (value, record) => record.status.code!.indexOf(value as string) === 0,
render: (val, record) => record.working_status === 'WFH' || record.working_status === 'WFS' ? <Badge variant={getVariantApproved(record.status.code as any)}>{record.status.name}</Badge> : ''
},
{
title: 'Check-in',
dataIndex: 'working_hours_start',
filters: [
{
text: 'Less than 10:00 AM',
value: 'lt_10', // You can use any value you prefer
},
{
text: 'More than or equal to 10:00 AM',
value: 'gte_10', // You can use any value you prefer
},
],
onFilter: (value, record) => {
const time = new Date(record.working_hours_start).getHours();
if (value === 'lt_10') {
return time < 10;
} else if (value === 'gte_10') {
return time >= 10;
}
return false; // If the value doesn't match any filter
},
render: (val) => <span className='text-green-500'>{dayjs(val).format('HH:mm A')}</span>
},
{
title: 'Check-in Device',
dataIndex: 'device',
filters: [
{
text: 'FR Device',
value: '11001',
},
{
text: 'Web App',
value: '40001',
},
{
text: 'Android App',
value: '20001',
},
{
text: 'IOS App',
value: '30001',
}
],
onFilter: (value, record) => record.device.code!.indexOf(value as string) === 0,
render: (val, record) => record.device.name,
},
{
title: 'Check-in Location',
dataIndex: 'location_name',
},
{
title: 'Check-in Note',
dataIndex: 'note',
},
{
title: 'Check-in Photo',
dataIndex: 'face_image',
render: (val, record) => val ? <a onClick={(e) => e.stopPropagation()} className='text-his hover:opacity-70 duration-200' href={process.env.BASE_URL_IMG + val} target="_blank">View Photo</a> : ''
},
{
title: 'Check-out',
dataIndex: 'working_hours_end',
filters: [
{
text: 'Less than 17:00 PM',
value: 'lt_17', // You can use any value you prefer
},
{
text: 'More than or equal to 17:00 PM',
value: 'gte_17', // You can use any value you prefer
},
],
onFilter: (value, record) => {
const time = new Date(record.presence_checkout?.working_hours_end).getHours();
if (value === 'lt_17') {
return time < 17;
} else if (value === 'gte_17') {
return time >= 17;
}
return false; // If the value doesn't match any filter
},
render: (val, record) => record.presence_checkout?.working_hours_end ? <span className='text-rose-500'>{dayjs(record.presence_checkout?.working_hours_end).format('HH:mm A')}</span> : undefined
},
{
title: 'Check-out Device',
dataIndex: 'device',
filters: [
{
text: 'FR Device',
value: '11001',
},
{
text: 'Web App',
value: '40001',
},
{
text: 'Android App',
value: '20001',
},
{
text: 'IOS App',
value: '30001',
}
],
onFilter: (value, record) => record.presence_checkout?.device?.code!.indexOf(value as string) === 0,
render: (val, record) => record.presence_checkout?.device?.name,
},
{
title: 'Check-out Location',
dataIndex: 'location_name',
render: (val, record) => record.presence_checkout?.location_name
},
{
title: 'Check-out Note',
dataIndex: 'note',
render: (val, record) => record.presence_checkout?.note
},
{
title: 'Check-out Photo',
dataIndex: 'face_image',
render: (val, record) => record.presence_checkout?.face_image ? <a onClick={(e) => e.stopPropagation()} className='text-his hover:opacity-70 duration-200' href={process.env.BASE_URL_IMG + record.presence_checkout?.face_image} target="_blank">View Photo</a> : ''
},
{
title: 'Auto Checkout',
dataIndex: 'autocheckout',
filters: [
{
text: 'Auto Checkout',
value: true,
}
],
onFilter: (value, record) => record.presence_checkout?.auto_checkout?.valueOf() === true,
render: (val, record) => record.presence_checkout?.auto_checkout ? <i className="ti ti-check text-xl text-green-500"></i> : '-'
},
{
title: 'Clear AutoChekout',
dataIndex: 'status',
render: (val, record) => record?.is_clear_auto_checkout === false ? <Badge>need to be approve</Badge> : record.is_clear_auto_checkout === true ? <Badge variant='secondary'>approved</Badge> : undefined
},
];
const tableProps: TableProps<IHistory> = {
size: 'small',
bordered: false,
showHeader: true,
pagination: {
pageSizeOptions: [5, 10, 20, 50],
defaultPageSize: 15,
showSizeChanger: true,
showQuickJumper: true,
size: 'default'
},
scroll: { x: 'max-content' },
tableLayout: 'auto',
};
return (
<>
{/* <div className='flex flex-col space-y-4 max-w-[300px] sm:max-w-[500px] md:max-w-[600px] lg:max-w-[800px] xl:max-w-[1200px] 2xl:max-w-[1400px]'> */}
<div style={{ width: windowWidth > 1900 ? 1400 : windowWidth > 1280 ? 1200 : windowWidth > 1000 ? 800 : windowWidth > 760 ? 600 : windowWidth * 0.72 }} className='flex flex-col space-y-4'>
<div className="flex items-center justify-between">
<div className="flex flex-1 items-center space-x-2">
<Input placeholder="Search attendance..." className="h-8 w-full sm:w-[250px]" onChange={handleSearch} />
</div>
</div>
<Table
{...tableProps}
onRow={(record, rowIndex) => {
return {
onClick: event => { console.log(record.face_image); }, // click row
};
}}
rowKey='presence_checkin_code'
columns={Columns}
dataSource={filterData || []}
style={{ cursor: "pointer" }}
/>
</div>
</>
);
}
export default TableAttendanceHistory;
@@ -0,0 +1,192 @@
import { Dispatch, FC, MouseEvent, SetStateAction, Suspense, lazy } from 'react';
import dayjs from 'dayjs';
import { Dialog, DialogContent, DialogFooter, DialogTitle } from '@/components/ui/dialog';
import { Button } from '@/components/ui/button';
import { Card, Card900, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card';
import LazyLoading from '@/components/loader/LazyLoading';
import ViewAvatar from '@/components/ViewAvatar';
import { type IUser } from '../type';
const DonutChart = lazy(() => import('./DonutChart'));
const AreaChart = lazy(() => import('./AreaChart'))
const TableAttendanceHistory = lazy(() => import('./Table'))
const ExportComponent = lazy(() => import('@/app/admin/report/history/component/Export'))
type Props = {
open: boolean
onOpenChange: Dispatch<SetStateAction<boolean>>
data: IUser
onClose: (e: MouseEvent<HTMLButtonElement>) => any
};
const EmployeePerformance: FC<Props> = ({ open, onOpenChange, data, onClose }) => {
return (
<>
<Dialog open={open} onOpenChange={onOpenChange}>
<DialogContent className="min-w-[95vw] max-w-[95vw] 2xl:min-w-[80vw] 2xl:max-w-[80vw] overflow-hidden overflow-y-auto max-h-[95vh]">
<div className='gap-4 space-y-7'>
<Card900>
<CardContent className='flex xl:items-center mt-6'>
<ViewAvatar avatar={data.avatar} className='w-20 h-20 sm:w-44 sm:h-44 duration-300' />
<div className='ml-6 2xl:ml-10 w-full'>
<DialogTitle className='sm:text-2xl'>{data.fullname}</DialogTitle>
<div className='grid grid-cols-1 sm:grid-cols-2 xl:grid-cols-4 gap-2 mt-3 w-full'>
<div className='flex flex-col'>
<span className='text-muted-foreground text-sm'>Position</span>
<span>{data.position?.name}</span>
</div>
<div className='flex flex-col'>
<span className='text-muted-foreground text-sm'>NIKTG</span>
<span>{data.niktg || '-'}</span>
</div>
<div className='flex flex-col'>
<span className='text-muted-foreground text-sm'>NIK</span>
<span>{data.nik || '-'}</span>
</div>
<div className='flex flex-col'>
<span className='text-muted-foreground text-sm'>Employee Type</span>
<span>{data.employee_type?.name || '-'}</span>
</div>
<div className='flex flex-col'>
<span className='text-muted-foreground text-sm'>Office Email</span>
<a title={data.email_office || ''} href={`mailto:${data.email_office}`} referrerPolicy="no-referrer" className='truncate'>
{data.email_office || '-'}
</a>
</div>
<div className='flex flex-col'>
<span className='text-muted-foreground text-sm'>Phone</span>
<span>{data.phone_number}</span>
</div>
<div className='flex flex-col'>
<span className='text-muted-foreground text-sm'>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 text-sm'>Contract Expiration Date</span>
<span>{data.contract_expiration_date ? dayjs(data.contract_expiration_date).format('MMM DD, YYYY') : '-'}</span>
</div>
</div>
</div>
</CardContent>
</Card900>
<div className='grid gap-3 grid-cols-1 sm:grid-cols-2 xl:grid-cols-4'>
<div className='space-y-3'>
<Card900>
<CardHeader className="flex flex-row items-center justify-between space-y-0 pb-2">
<CardTitle className="text-sm font-medium">Working Hour in this Month</CardTitle>
<i className="ti ti-clock-play icon h-4 w-4 text-his text-xl"></i>
</CardHeader>
<CardContent>
<div className="text-2xl font-bold">{'0 Hour'}</div>
<p className="text-xs text-muted-foreground">
number of working hours in this month
</p>
</CardContent>
</Card900>
<Card900>
<CardHeader className="flex flex-row items-center justify-between space-y-0 pb-2">
<CardTitle className="text-sm font-medium">Total OvertIme</CardTitle>
<i className="ti ti-clock-play icon h-4 w-4 text-his text-xl"></i>
</CardHeader>
<CardContent>
<div className="text-2xl font-bold">{'0 Hour'}</div>
<p className="text-xs text-muted-foreground">
in the Past 30 Days (Weekend Only)
</p>
</CardContent>
</Card900>
</div>
<div className='space-y-3'>
<Card900 className='relative'>
<CardHeader className="flex flex-row items-center justify-between space-y-0 pb-2">
<CardTitle className="text-sm font-medium">Total <span className='text-cyan-500 font-semibold'>Task</span> | <span className='text-amber-500 font-semibold'>On Progress</span> | <span className='text-lime-500 font-semibold'>Done</span></CardTitle>
<i className="ti ti-clock-play icon h-4 w-4 text-his text-xl"></i>
</CardHeader>
<CardContent>
<div className="text-2xl font-bold"><span className='text-cyan-500'>-</span> | <span className='text-amber-500'>-</span> | <span className='text-lime-500'>-</span></div>
<p className="text-xs text-muted-foreground">
in the Past 30 Days
</p>
</CardContent>
<div className='absolute inset-0 w-full h-full bg-black rounded-2xl bg-opacity-60 flex justify-center items-center font-semibold text-xl'>
<p className='animate-pulse'>Coming soon</p>
</div>
</Card900>
<Card900>
<CardHeader className="flex flex-row items-center justify-between space-y-0 pb-2">
<CardTitle className="text-sm font-medium">Average <span className='text-green-500 font-semibold'>Check IN</span> | <span className='text-rose-500 font-semibold'>Check OUT</span></CardTitle>
<i className="ti ti-clock-play icon h-4 w-4 text-his text-xl"></i>
</CardHeader>
<CardContent>
<div className="text-2xl font-bold"><span className='text-green-500'>--:--</span> | <span className='text-rose-500'>--:--</span></div>
<p className="text-xs text-muted-foreground">
in the Past 30 Days
</p>
</CardContent>
</Card900>
</div>
<Card900>
<CardHeader className="flex flex-row items-center justify-between space-y-0 pb-0">
<CardTitle className="text-sm font-medium">Total <span className='text-emerald-500 font-semibold'>Leave</span> | <span className='text-yellow-500 font-semibold'>Sick</span> | <span className='text-orange-500 font-semibold'>Permit</span></CardTitle>
<i className="ti ti-clock-play icon h-4 w-4 text-his text-xl"></i>
</CardHeader>
<CardContent className='pb-0'>
<p className="text-xs text-muted-foreground">in the Past 30 Days</p>
<Suspense fallback={<LazyLoading />}>
<DonutChart data={[2, 3, 1]} labels={['Leave', 'Sick', 'Permit']} colors={['#10b981', '#eab308', '#f97316']} />
</Suspense>
</CardContent>
</Card900>
<Card900>
<CardHeader className="flex flex-row items-center justify-between space-y-0 pb-0">
<CardTitle className="text-sm font-medium">Total <span className='text-sky-500 font-semibold'>WFO</span> | <span className='text-indigo-500 font-semibold'>WFS</span> | <span className='text-fuchsia-500 font-semibold'>WFH</span></CardTitle>
<i className="ti ti-clock-play icon h-4 w-4 text-his text-xl"></i>
</CardHeader>
<CardContent className='pb-0'>
<p className="text-xs text-muted-foreground">in the Past 30 Days</p>
<Suspense fallback={<LazyLoading />}>
<DonutChart data={[15, 3, 1]} labels={['WFO', 'WFS', 'WFH']} colors={['#0ea5e9', '#6366f1', '#d946ef']} />
</Suspense>
</CardContent>
</Card900>
</div>
<Card900>
<CardHeader>
<CardTitle>Attendance Statistics</CardTitle>
<CardDescription>Statistics of your attendance in last 30 days.</CardDescription>
</CardHeader>
<CardContent className="px-0">
<Suspense fallback={<LazyLoading />}>
<AreaChart data={[]} />
</Suspense>
</CardContent>
</Card900>
<Card>
<CardHeader className='flex flex-col md:flex-row items-center justify-between space-y-5 sm:space-y-0'>
<div>
<CardTitle>Attendance History</CardTitle>
<CardDescription className='mt-1 sm:block hidden'>Here&apos;s a list of your attendance history in the Past 30 Days!</CardDescription>
</div>
<Suspense fallback={<LazyLoading />}>
<ExportComponent data={[]} />
</Suspense>
</CardHeader>
<CardContent className='flex justify-center items-center'>
<Suspense fallback={<LazyLoading />}>
<TableAttendanceHistory data={[]} />
</Suspense>
</CardContent>
</Card>
</div>
<DialogFooter>
<Button variant="outline" type="button" onClick={onClose} >
Close
</Button>
</DialogFooter>
</DialogContent>
</Dialog>
</>
);
}
export default EmployeePerformance;