mirror of
https://github.com/ichsankurnia/hats-app.git
synced 2026-12-06 21:06:29 +00:00
initial commit for new hats app
This commit is contained in:
@@ -0,0 +1,146 @@
|
||||
import { FC } from 'react';
|
||||
import { type Metadata } from 'next';
|
||||
import Link from 'next/link';
|
||||
import dayjs from 'dayjs';
|
||||
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card';
|
||||
import fetchData from '@/lib/fetchData';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { type IUser } from '../component/type';
|
||||
|
||||
export const metadata: Metadata = {
|
||||
title: "Admin | User Detail",
|
||||
}
|
||||
|
||||
type Props = {
|
||||
params: Promise<{ id: string | undefined }>
|
||||
};
|
||||
|
||||
const UserDetailPage: FC<Props> = async ({ params }) => {
|
||||
const id = (await params).id
|
||||
|
||||
const data: IUser = await fetchData(`/user/${id}`)
|
||||
|
||||
return (
|
||||
<>
|
||||
<Card>
|
||||
<CardHeader className='flex flex-col sm:flex-row items-center justify-between space-y-3 sm:space-y-0'>
|
||||
<div className='flex items-center sm:space-x-5'>
|
||||
<Link href='/admin/administration/user' className='hidden sm:block'>
|
||||
<Button variant='outline' size='icon'>
|
||||
<i className="ti ti-arrow-left text-xl"></i>
|
||||
</Button>
|
||||
</Link>
|
||||
<div className='space-y-1'>
|
||||
<CardTitle>User Detail</CardTitle>
|
||||
<CardDescription>Detail of user id {id}</CardDescription>
|
||||
</div>
|
||||
</div>
|
||||
{data.status.code === 'A' &&
|
||||
<Link href={`create?is_update=true&id=${id}`} className='w-full sm:w-max'>
|
||||
<Button variant='secondary' className='w-full'>
|
||||
Edit <i className="ti ti-edit ml-2 text-lg"></i>
|
||||
</Button>
|
||||
</Link>
|
||||
}
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<div className='grid grid-cols-1 sm:grid-cols-2 font-medium gap-y-5'>
|
||||
<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'>Company</span>
|
||||
<span>{data?.company?.name}</span>
|
||||
</div>
|
||||
<div className='flex flex-col'>
|
||||
<span className='text-muted-foreground'>Area</span>
|
||||
<span>{data?.area?.name}</span>
|
||||
</div>
|
||||
<div className='flex flex-col'>
|
||||
<span className='text-muted-foreground'>Department</span>
|
||||
<span>{data?.division?.name}</span>
|
||||
</div>
|
||||
<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'>Employee Type</span>
|
||||
<span>{data?.employee_type?.name || '-'}</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'>Birthday</span>
|
||||
<span>{data?.birthday ? dayjs(data?.birthday).format('MMM DD, YYYY') : '-'}</span>
|
||||
</div>
|
||||
<div className='flex flex-col'>
|
||||
<span className='text-muted-foreground'>Gender</span>
|
||||
<span>{data?.gender || '-'}</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'>Is Extend Contract</span>
|
||||
<span>{data?.is_extend_contract || '-'}</span>
|
||||
</div>
|
||||
<div className='flex flex-col'>
|
||||
<span className='text-muted-foreground'>Office Email</span>
|
||||
<span>{data?.email_office || '-'}</span>
|
||||
</div>
|
||||
<div className='flex flex-col'>
|
||||
<span className='text-muted-foreground'>Personal Email</span>
|
||||
<span>{data?.email_personal || '-'}</span>
|
||||
</div>
|
||||
<div className='flex flex-col'>
|
||||
<span className='text-muted-foreground'>Last Education</span>
|
||||
<span>{data?.last_education || '-'}</span>
|
||||
</div>
|
||||
<div className='flex flex-col'>
|
||||
<span className='text-muted-foreground'>Resign Date</span>
|
||||
<span>{data?.resign_date ? dayjs(data?.resign_date).format('MMM DD, YYYY') : '-'}</span>
|
||||
</div>
|
||||
<div className='flex flex-col'>
|
||||
<span className='text-muted-foreground'>Resign Reason</span>
|
||||
<span>{data?.resign_reason || '-'}</span>
|
||||
</div>
|
||||
<div className='flex flex-col'>
|
||||
<span className='text-muted-foreground'>Post Company</span>
|
||||
<span>{data?.post_company || '-'}</span>
|
||||
</div>
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
export default UserDetailPage;
|
||||
@@ -0,0 +1,75 @@
|
||||
import { FC, ReactNode, useState } from 'react';
|
||||
import { Icons } from '@/components/Icons';
|
||||
import { AlertDialogAction, AlertDialogCancel, AlertDialogContent, AlertDialogDescription, AlertDialogFooter, AlertDialogHeader, AlertDialogTitle } from '@/components/ui/alert-dialog';
|
||||
import { type ResponseData } from '@/types/types';
|
||||
import { useRouter } from 'next/navigation';
|
||||
import { toast } from 'sonner';
|
||||
|
||||
type Props = {
|
||||
title?: string
|
||||
description?: string
|
||||
onConfirm: () => Promise<any>
|
||||
okText?: string
|
||||
cancelText?: string
|
||||
contentSuccess?: ReactNode | string
|
||||
onOkSuccess?: () => any
|
||||
};
|
||||
|
||||
const ConfirmAsync: FC<Props> = ({ title, description, onConfirm, okText, cancelText, contentSuccess, onOkSuccess }) => {
|
||||
const [isLoading, setIsloading] = useState(false)
|
||||
const router = useRouter()
|
||||
|
||||
const confirm = async () => {
|
||||
if (isLoading) return
|
||||
try {
|
||||
setIsloading(true)
|
||||
const res: ResponseData = await onConfirm()
|
||||
setIsloading(false)
|
||||
|
||||
console.log(res)
|
||||
if (!res) return
|
||||
|
||||
if (res.code === '00') {
|
||||
showSuccess()
|
||||
} else {
|
||||
showError(res.message)
|
||||
}
|
||||
} catch (error: any) {
|
||||
console.log(error)
|
||||
setIsloading(false)
|
||||
showError(error?.message)
|
||||
}
|
||||
}
|
||||
|
||||
const showSuccess = () => {
|
||||
toast.success(contentSuccess || 'Data successfully removed.' as string)
|
||||
router.refresh()
|
||||
onOkSuccess!()
|
||||
};
|
||||
|
||||
const showError = (message?: string) => {
|
||||
toast.error(message)
|
||||
};
|
||||
|
||||
return (
|
||||
<AlertDialogContent onClick={e => e.stopPropagation()}>
|
||||
<AlertDialogHeader>
|
||||
<AlertDialogTitle>{title || 'Are you absolutely sure?'}</AlertDialogTitle>
|
||||
<AlertDialogDescription>
|
||||
{description || 'This action cannot be undone. This will permanently delete this data and remove from our servers.'}
|
||||
</AlertDialogDescription>
|
||||
</AlertDialogHeader>
|
||||
<AlertDialogFooter>
|
||||
<AlertDialogCancel disabled={isLoading}>{cancelText || 'Cancel'}</AlertDialogCancel>
|
||||
<AlertDialogAction disabled={isLoading} onClick={confirm}>
|
||||
{isLoading && (
|
||||
<Icons.spinner className="mr-1 h-4 w-4 animate-spin" />
|
||||
)}
|
||||
{okText || 'Continue'}
|
||||
</AlertDialogAction>
|
||||
</AlertDialogFooter>
|
||||
</AlertDialogContent>
|
||||
);
|
||||
}
|
||||
|
||||
export default ConfirmAsync;
|
||||
@@ -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'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;
|
||||
@@ -0,0 +1,74 @@
|
||||
'use client'
|
||||
import { FC, useState } from 'react';
|
||||
import { Icons } from '@/components/Icons';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { type IUser } from './type';
|
||||
import { useSession } from 'next-auth/react';
|
||||
import { exportTable } from '@/lib/exportExcel';
|
||||
import dayjs from 'dayjs';
|
||||
import { IExcelJSColumnType } from '@/types/types';
|
||||
|
||||
type Props = {
|
||||
data: IUser[]
|
||||
};
|
||||
|
||||
const ExportComponent: FC<Props> = ({ data }) => {
|
||||
const { data: session } = useSession()
|
||||
|
||||
const [isLoading, setIsLoading] = useState(false)
|
||||
|
||||
const handleExport = async () => {
|
||||
setIsLoading(true)
|
||||
|
||||
const columns: IExcelJSColumnType[] = [
|
||||
{ header: 'No', key: 'number', width: 5, style: { numFmt: '0;[Red]0' } },
|
||||
{ header: 'User ID', key: 'id', width: 8, style: { numFmt: '0;[Red]0' } },
|
||||
{ header: 'Fullname', key: 'fullname', width: 25 },
|
||||
{ header: 'Nickname', key: 'nickname', width: 15 },
|
||||
{ header: 'Email', key: 'email', width: 25 },
|
||||
{ header: 'NIK', key: 'nik', width: 15 },
|
||||
{ header: 'NIKTG', key: 'niktg', width: 10 },
|
||||
{ header: 'Phone Number', key: 'phone_number' },
|
||||
{ header: 'Employee Type', key: 'employee_type', width: 50, value: 'employee_type.name' },
|
||||
{ header: 'Position', key: 'position', value: 'position.name' },
|
||||
{ header: 'Department', key: 'department', value: 'division.name', width: 25 },
|
||||
{ header: 'Company', key: 'company', value: 'company.name' },
|
||||
{ header: 'Hire Date', key: 'hire_date', style: { numFmt: 'dd/mm/yyyy' } },
|
||||
{ header: 'Contract Expiration Date', key: 'contract_expiration_date', style: { numFmt: 'dd/mm/yyyy' } },
|
||||
{ header: 'Sex', key: 'gender', width: 10 },
|
||||
{ header: 'Date of Birth', key: 'birthday', style: { numFmt: 'dd/mm/yyyy' } },
|
||||
{ header: 'Role', key: 'role', value: 'role.name' },
|
||||
{ header: 'Activate at', key: 'activated_at', style: { numFmt: 'dd/mm/yyyy' }, width: 15 },
|
||||
{ header: 'Status', key: 'status', value: 'status.name', width: 15 }
|
||||
]
|
||||
|
||||
const resBlob: any = await exportTable(session?.user.detail as IUser, data, columns, 'List of Users')
|
||||
if (resBlob) {
|
||||
const url = URL.createObjectURL(resBlob);
|
||||
|
||||
// Create a link and trigger a click event to start the download
|
||||
const a = document.createElement("a");
|
||||
a.style.display = "none";
|
||||
a.href = url;
|
||||
a.download = `Employee List - Export by ${session?.user.detail.nik} - ${dayjs().format('YYYYMMDD HH:mm:ss')}`; // Set the downloaded filename
|
||||
document.body.appendChild(a);
|
||||
a.click();
|
||||
|
||||
// Clean up by removing the temporary link and URL
|
||||
document.body.removeChild(a);
|
||||
URL.revokeObjectURL(url);
|
||||
}
|
||||
setIsLoading(false)
|
||||
}
|
||||
|
||||
return (
|
||||
<Button className='w-full sm:w-max' disabled={isLoading} onClick={handleExport}>
|
||||
{isLoading && (
|
||||
<Icons.spinner className="mr-1 h-4 w-4 animate-spin" />
|
||||
)}
|
||||
Download
|
||||
</Button>
|
||||
);
|
||||
}
|
||||
|
||||
export default ExportComponent;
|
||||
@@ -0,0 +1,122 @@
|
||||
import { useState } from "react"
|
||||
import { useRouter } from "next/navigation"
|
||||
import { Form, Input } from "antd"
|
||||
import useAxiosAuth from "@/lib/axios/useAxiosAuth"
|
||||
import { Button } from "@/components/ui/button"
|
||||
import {
|
||||
DialogContent,
|
||||
DialogDescription,
|
||||
DialogFooter,
|
||||
DialogHeader,
|
||||
DialogTitle,
|
||||
} from "@/components/ui/dialog"
|
||||
import { Label } from "@/components/ui/label"
|
||||
import { Icons } from "@/components/Icons"
|
||||
import { type IUser } from "./type"
|
||||
import { toast } from "sonner"
|
||||
|
||||
type Props = {
|
||||
data?: IUser
|
||||
onCancel?: () => any
|
||||
}
|
||||
|
||||
export default function FormChangePassword({ data, onCancel }: Props) {
|
||||
const [isLoading, setIsLoading] = useState(false)
|
||||
|
||||
const [form] = Form.useForm();
|
||||
const router = useRouter()
|
||||
const axios = useAxiosAuth()
|
||||
|
||||
const handleSubmit = (value: any) => {
|
||||
console.log(value)
|
||||
|
||||
handleUpdate(value)
|
||||
}
|
||||
|
||||
const handleUpdate = async (payload: any) => {
|
||||
try {
|
||||
setIsLoading(true)
|
||||
|
||||
const request = {
|
||||
nik: data?.nik,
|
||||
old_password: payload['old_password'],
|
||||
new_password: payload['new_password']
|
||||
}
|
||||
await axios.post('/user/change-password', request)
|
||||
|
||||
toast.success('Password changed successfully.')
|
||||
setIsLoading(false)
|
||||
onCancel!()
|
||||
router.refresh()
|
||||
form.resetFields()
|
||||
} catch (error: any) {
|
||||
toast.error(`Failed to change password`, { description: `(${error.response.data.code || error.response.status || '-'}) ${error.response.data.message || error.response.statusText || error.message}}` })
|
||||
setIsLoading(false)
|
||||
}
|
||||
}
|
||||
|
||||
const handleCancel = () => {
|
||||
form.resetFields()
|
||||
onCancel!()
|
||||
}
|
||||
|
||||
return (
|
||||
<DialogContent className=" overflow-y-auto max-h-[95vh]">
|
||||
<Form form={form} onFinish={handleSubmit}>
|
||||
<DialogHeader>
|
||||
<DialogTitle className="dark:text-white">Change user password</DialogTitle>
|
||||
<DialogDescription>
|
||||
Update user password to maintain privacy of employee
|
||||
</DialogDescription>
|
||||
</DialogHeader>
|
||||
<div className="grid mt-8">
|
||||
<div className="grid gap-2">
|
||||
<Label htmlFor="old_password">Old password</Label>
|
||||
<Form.Item name='old_password' rules={[
|
||||
{ required: true, message: 'This field is required' }, { min: 5 }
|
||||
]}>
|
||||
<Input.Password className="input" type="password" id="old_password" placeholder="********" />
|
||||
</Form.Item>
|
||||
</div>
|
||||
<div className="grid gap-2">
|
||||
<Label htmlFor="new_password">New password</Label>
|
||||
<Form.Item name='new_password' rules={[
|
||||
{ required: true, message: 'This field is required' }, { min: 5 }
|
||||
]}>
|
||||
<Input.Password className="input" type="password" id="new_password" placeholder="********" />
|
||||
</Form.Item>
|
||||
</div>
|
||||
<div className="grid gap-2">
|
||||
<Label htmlFor="confirm_password">Confirm password</Label>
|
||||
<Form.Item name="confirm" dependencies={['new_password']} hasFeedback
|
||||
rules={[
|
||||
{ required: true, message: 'Please confirm your password!' },
|
||||
({ getFieldValue }) => ({
|
||||
validator(_, value) {
|
||||
if (!value || getFieldValue('new_password') === value) {
|
||||
return Promise.resolve();
|
||||
}
|
||||
return Promise.reject(new Error('The new password that you entered do not match!'));
|
||||
},
|
||||
}),
|
||||
]}
|
||||
>
|
||||
<Input.Password className="input" type="password" id="confirm_password" placeholder="********" />
|
||||
</Form.Item>
|
||||
</div>
|
||||
</div>
|
||||
<DialogFooter>
|
||||
<Button variant="outline" type="button" onClick={handleCancel} disabled={isLoading} >
|
||||
Cancel
|
||||
</Button>
|
||||
<Button type="submit" disabled={isLoading}>
|
||||
{isLoading && (
|
||||
<Icons.spinner className="mr-1 h-4 w-4 animate-spin" />
|
||||
)}
|
||||
Save
|
||||
</Button>
|
||||
</DialogFooter>
|
||||
</Form>
|
||||
</DialogContent>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
import { useState } from "react"
|
||||
import { Button } from "@/components/ui/button"
|
||||
import {
|
||||
DialogContent,
|
||||
DialogDescription,
|
||||
DialogFooter,
|
||||
DialogHeader,
|
||||
DialogTitle,
|
||||
} from "@/components/ui/dialog"
|
||||
import { Icons } from "@/components/Icons"
|
||||
import { type IUser } from "./type"
|
||||
import { useRouter } from "next/navigation"
|
||||
import useAxiosAuth from "@/lib/axios/useAxiosAuth"
|
||||
import { type ResponseData } from "@/types/types"
|
||||
import { toast } from "sonner"
|
||||
|
||||
type Props = {
|
||||
data?: IUser
|
||||
onCancel?: () => any
|
||||
}
|
||||
|
||||
export default function ResetPassword({ data, onCancel }: Props) {
|
||||
const [isLoading, setIsLoading] = useState(false)
|
||||
const router = useRouter()
|
||||
const axios = useAxiosAuth()
|
||||
|
||||
|
||||
const handleResetPassword = async () => {
|
||||
if (isLoading) return
|
||||
try {
|
||||
setIsLoading(true)
|
||||
const { data: res }: ResponseData = await axios.post('/user/reset-password', { nik: data?.nik })
|
||||
setIsLoading(false)
|
||||
|
||||
console.log(res)
|
||||
if (!res) return
|
||||
|
||||
if (res.code === '00') {
|
||||
showSuccess(res.message)
|
||||
} else {
|
||||
showError(`Failed to reset password, ${res.message}`)
|
||||
}
|
||||
} catch (error: any) {
|
||||
console.log(error)
|
||||
showError(`Failed to reset password, (${error.response.data.code || error.response.status || '-'}) ${error.response.data.message || error.response.statusText || error.message}`)
|
||||
}
|
||||
}
|
||||
|
||||
const showSuccess = (message: string) => {
|
||||
toast.success(message as string)
|
||||
router.refresh()
|
||||
onCancel!()
|
||||
};
|
||||
|
||||
const showError = (message?: string) => {
|
||||
setIsLoading(false)
|
||||
toast.error(message)
|
||||
};
|
||||
|
||||
return (
|
||||
<DialogContent className=" overflow-y-auto max-h-[95vh]">
|
||||
<DialogHeader>
|
||||
<DialogTitle className="dark:text-white">Confirm reset password</DialogTitle>
|
||||
<DialogDescription>
|
||||
This action will reset password for user <b>{data?.fullname}</b>, are you sure to continue this process?
|
||||
</DialogDescription>
|
||||
</DialogHeader>
|
||||
<DialogFooter>
|
||||
<Button variant="outline" type="button" onClick={onCancel} disabled={isLoading} >
|
||||
Cancel
|
||||
</Button>
|
||||
<Button type="submit" disabled={isLoading} onClick={handleResetPassword}>
|
||||
{isLoading && (
|
||||
<Icons.spinner className="mr-1 h-4 w-4 animate-spin" />
|
||||
)}
|
||||
Save
|
||||
</Button>
|
||||
</DialogFooter>
|
||||
</DialogContent>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,262 @@
|
||||
'use client'
|
||||
|
||||
import { ChangeEvent, FC, useEffect, useState } from 'react';
|
||||
import { MoreHorizontalIcon } from 'lucide-react';
|
||||
import { Table } from 'antd';
|
||||
import { TableProps, type ColumnsType } from 'antd/es/table';
|
||||
import { PlusCircledIcon } from '@radix-ui/react-icons';
|
||||
import useAxiosAuth from '@/lib/axios/useAxiosAuth';
|
||||
import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuTrigger } from '@/components/ui/dropdown-menu';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { AlertDialog, AlertDialogTrigger } from '@/components/ui/alert-dialog';
|
||||
import { Input } from '@/components/ui/input';
|
||||
import { Dialog } from '@/components/ui/dialog';
|
||||
import ConfirmAsync from './ConfirmAsync';
|
||||
import FormChangePassword from './FormChangePassword';
|
||||
import { type IUser } from './type';
|
||||
import { useRouter } from 'next/navigation';
|
||||
import Link from 'next/link';
|
||||
import Image from 'next/image';
|
||||
import ResetPassword from './ResetPassword';
|
||||
// import EmployeePerformance from './EmployeePerformance';
|
||||
|
||||
type Props = {
|
||||
data: IUser[]
|
||||
};
|
||||
|
||||
const ComponentPage: FC<Props> = ({ data }) => {
|
||||
const [filterData, setFilterData] = useState<IUser[]>([])
|
||||
const [selectedData, setSelectedData] = useState<IUser | undefined>(undefined)
|
||||
const [showFormChangePass, setShowFormChangePass] = useState(false)
|
||||
const [showResetPass, setShowResetPass] = useState(false)
|
||||
// const [showPerformance, setShowPerformance] = useState(false)
|
||||
|
||||
const axios = useAxiosAuth()
|
||||
const router = useRouter()
|
||||
|
||||
useEffect(() => {
|
||||
if (data) {
|
||||
setFilterData(data)
|
||||
}
|
||||
}, [data])
|
||||
|
||||
const handleDelete = (userId: string | number) => {
|
||||
return axios.delete(`/user/${userId}`).then(res => res.data)
|
||||
}
|
||||
|
||||
const handleResetForm = () => {
|
||||
setSelectedData(undefined)
|
||||
// setShowFormDialog(false)
|
||||
setShowFormChangePass(false)
|
||||
setShowResetPass(false)
|
||||
}
|
||||
|
||||
const handleSearch = (e: ChangeEvent<HTMLInputElement>) => {
|
||||
const text = e.target.value
|
||||
if (text) {
|
||||
const newData = [...data!].filter(item => (
|
||||
item.fullname?.toLowerCase().includes(text.toLowerCase()) ||
|
||||
item.nickname?.toLowerCase().includes(text.toLowerCase()) ||
|
||||
item.email?.toLowerCase().includes(text.toLowerCase()) ||
|
||||
item.nik?.toLowerCase().includes(text.toLowerCase()) ||
|
||||
item.phone_number?.toLowerCase().includes(text.toLowerCase()) ||
|
||||
item.role?.name?.toLowerCase().includes(text.toLowerCase()) ||
|
||||
item.position?.name?.toLowerCase().includes(text.toLowerCase())
|
||||
))
|
||||
setFilterData(newData)
|
||||
} else {
|
||||
setFilterData(data)
|
||||
}
|
||||
}
|
||||
|
||||
const Columns: ColumnsType<IUser> = [
|
||||
{
|
||||
title: 'Num',
|
||||
dataIndex: 'key',
|
||||
render: (text, record, index) => index + 1
|
||||
},
|
||||
{
|
||||
title: 'Fullname',
|
||||
dataIndex: 'fullname',
|
||||
sorter: (a, b) => a.fullname.localeCompare(b.fullname),
|
||||
render: (text, record) => (
|
||||
<div className='flex items-center space-x-2.5'>
|
||||
{record.avatar ?
|
||||
<img loading='lazy' className='w-8 h-8 rounded-full border dark:border-zinc-800 object-cover' alt='avatar' src={`${process.env.BASE_URL_IMG}/${record.avatar}`} />
|
||||
:
|
||||
<Image alt='avatar' height={0} width={0} quality={50} src='/assets/no-avatar.jpg' className='w-8 h-8 rounded-full border dark:border-zinc-800 object-cover' />
|
||||
}
|
||||
<p>{text}</p>
|
||||
</div>
|
||||
)
|
||||
},
|
||||
{
|
||||
title: 'Email',
|
||||
dataIndex: 'email',
|
||||
sorter: (a, b) => a.email.localeCompare(b.email)
|
||||
},
|
||||
{
|
||||
title: 'Phone',
|
||||
dataIndex: 'phone_number',
|
||||
sorter: (a, b) => a.phone_number.localeCompare(b.phone_number)
|
||||
},
|
||||
{
|
||||
title: 'Position',
|
||||
dataIndex: 'position',
|
||||
render: (text) => text?.name
|
||||
},
|
||||
{
|
||||
title: 'Role',
|
||||
dataIndex: 'role',
|
||||
render: (text) => text?.name
|
||||
},
|
||||
{
|
||||
title: 'Status',
|
||||
dataIndex: 'status',
|
||||
filters: [
|
||||
{
|
||||
text: 'ACTIVE',
|
||||
value: 'A',
|
||||
},
|
||||
{
|
||||
text: 'INACTIVE',
|
||||
value: 'N',
|
||||
},
|
||||
{
|
||||
text: 'DELETED',
|
||||
value: 'X',
|
||||
},
|
||||
],
|
||||
onFilter: (value, record) => record.status!.code.indexOf(value as string) === 0,
|
||||
align: 'center',
|
||||
render: (text, record) => (
|
||||
<div className='flex justify-center text-white font-semibold text-xs'>
|
||||
{record.status.code === 'A' ?
|
||||
<div className="px-2 py-1.5 rounded-full bg-green-500 w-24">{record.status.name}</div>
|
||||
:
|
||||
<div className="px-2 py-1.5 rounded-full bg-rose-500 w-24">{record.status.name}</div>
|
||||
}
|
||||
</div>
|
||||
)
|
||||
},
|
||||
{
|
||||
title: 'Action',
|
||||
key: 'action',
|
||||
fixed: 'right',
|
||||
render: (_, record) => (
|
||||
<AlertDialog>
|
||||
<DropdownMenu>
|
||||
<DropdownMenuTrigger asChild>
|
||||
<Button variant='ghost' size="icon" onClick={e => e?.stopPropagation()}>
|
||||
<MoreHorizontalIcon />
|
||||
<span className="sr-only">Action Button</span>
|
||||
</Button>
|
||||
</DropdownMenuTrigger>
|
||||
{record.status.code === 'A' ?
|
||||
<DropdownMenuContent align="end" onClick={e => e?.stopPropagation()}>
|
||||
<DropdownMenuItem><Link href={`user/${record.id}`} className='w-full'>View</Link></DropdownMenuItem>
|
||||
<DropdownMenuItem onClick={() => { setShowFormChangePass(true); setSelectedData(record) }}>Change password</DropdownMenuItem>
|
||||
<DropdownMenuItem onClick={() => { setShowResetPass(true), setSelectedData(record) }}>Reset Password</DropdownMenuItem>
|
||||
<DropdownMenuItem><Link href={`user/create?is_update=true&id=${record.id}`} className='w-full'>Edit</Link></DropdownMenuItem>
|
||||
<AlertDialogTrigger asChild>
|
||||
<DropdownMenuItem>Delete</DropdownMenuItem>
|
||||
</AlertDialogTrigger>
|
||||
</DropdownMenuContent>
|
||||
:
|
||||
<DropdownMenuContent align="end">
|
||||
<DropdownMenuItem><Link href={`user/${record.id}`} className='w-full'>View</Link></DropdownMenuItem>
|
||||
</DropdownMenuContent>
|
||||
}
|
||||
</DropdownMenu>
|
||||
<ConfirmAsync
|
||||
onConfirm={() => handleDelete(record.id)}
|
||||
onOkSuccess={() => { }}
|
||||
/>
|
||||
</AlertDialog >
|
||||
),
|
||||
},
|
||||
];
|
||||
|
||||
const tableProps: TableProps<IUser> = {
|
||||
bordered: false,
|
||||
size: 'large',
|
||||
showHeader: true,
|
||||
pagination: {
|
||||
pageSizeOptions: [5, 10, 20, 50],
|
||||
defaultPageSize: 10,
|
||||
showSizeChanger: true,
|
||||
showQuickJumper: true,
|
||||
size: 'default'
|
||||
},
|
||||
scroll: { x: 'max-content' },
|
||||
tableLayout: 'auto',
|
||||
};
|
||||
|
||||
return (
|
||||
<>
|
||||
<div className='flex flex-col space-y-4'>
|
||||
<div className="flex flex-col sm:flex-row items-start sm:items-center justify-between space-y-2 sm:space-y-0">
|
||||
<div className="flex flex-1 items-center space-x-2">
|
||||
<Input placeholder="Search user..." className="h-8 w-full sm:w-[250px]" onChange={handleSearch} />
|
||||
</div>
|
||||
<Link href='user/create'>
|
||||
<Button size="sm" className="ml-auto h-8 w-full sm:w-max text-his" variant='ghost'>
|
||||
<PlusCircledIcon className="mr-2 h-4 w-4" />
|
||||
Create New User
|
||||
</Button>
|
||||
</Link>
|
||||
</div>
|
||||
<Table
|
||||
{...tableProps}
|
||||
onRow={(record, rowIndex) => {
|
||||
return {
|
||||
onClick: event => {
|
||||
if (record.status.code !== 'A') return
|
||||
router.push(`/performance/${record.id}`)
|
||||
// setSelectedData(record); setShowPerformance(true)
|
||||
},
|
||||
};
|
||||
}}
|
||||
rowKey='id'
|
||||
columns={Columns}
|
||||
dataSource={filterData || []}
|
||||
style={{ cursor: "pointer" }}
|
||||
/>
|
||||
</div>
|
||||
|
||||
{showFormChangePass &&
|
||||
<Dialog open={showFormChangePass} onOpenChange={(state) => {
|
||||
if (state === false) setSelectedData(undefined)
|
||||
setShowFormChangePass(state)
|
||||
}}>
|
||||
<FormChangePassword
|
||||
data={selectedData}
|
||||
onCancel={handleResetForm}
|
||||
/>
|
||||
</Dialog>
|
||||
}
|
||||
|
||||
{showResetPass &&
|
||||
<Dialog open={showResetPass} onOpenChange={(state) => {
|
||||
if (state === false) setSelectedData(undefined)
|
||||
setShowResetPass(state)
|
||||
}}>
|
||||
<ResetPassword
|
||||
data={selectedData}
|
||||
onCancel={handleResetForm}
|
||||
/>
|
||||
</Dialog>
|
||||
}
|
||||
|
||||
{/* {showPerformance &&
|
||||
<EmployeePerformance
|
||||
open={showPerformance} onOpenChange={setShowPerformance}
|
||||
data={selectedData!}
|
||||
onClose={() => { setSelectedData(undefined); setShowPerformance(false) }}
|
||||
/>
|
||||
} */}
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
export default ComponentPage;
|
||||
@@ -0,0 +1,39 @@
|
||||
export interface IUser {
|
||||
id: number
|
||||
fullname: string
|
||||
nickname: string
|
||||
email: string
|
||||
password: string
|
||||
nik: string
|
||||
niktg: number
|
||||
phone_number: string
|
||||
company_id: number
|
||||
company?: any
|
||||
area_id: number
|
||||
area?: any
|
||||
division_id: number
|
||||
division?: any
|
||||
role_id: number
|
||||
role?: any
|
||||
employee_type_id: number
|
||||
employee_type?: any
|
||||
position_id: number
|
||||
position?: any
|
||||
status: {
|
||||
id: number
|
||||
code: "A" | 'N' | 'X'
|
||||
name: "ACTIVE" | 'INACTIVE' | 'DELETED'
|
||||
}
|
||||
avatar: string
|
||||
birthday: string
|
||||
gender: 'male' | 'female'
|
||||
hire_date: string
|
||||
contract_expiration_date?: string
|
||||
is_extend_contract?: boolean
|
||||
email_office?: string
|
||||
email_personal?: string
|
||||
last_education?: string
|
||||
resign_date?: string
|
||||
resign_reason?: string
|
||||
post_company?: string
|
||||
}
|
||||
@@ -0,0 +1,338 @@
|
||||
'use client'
|
||||
|
||||
import { FC, Suspense, useEffect, useState } from 'react';
|
||||
import Link from 'next/link';
|
||||
import { useRouter, useSearchParams } from 'next/navigation';
|
||||
import { DatePicker, Form, Input, Radio, Select } from 'antd';
|
||||
import dayjs from 'dayjs';
|
||||
import { Icons } from '@/components/Icons';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card';
|
||||
import { AlertDialog, AlertDialogAction, AlertDialogCancel, AlertDialogContent, AlertDialogDescription, AlertDialogFooter, AlertDialogHeader, AlertDialogTitle } from '@/components/ui/alert-dialog';
|
||||
import useFetch from '@/hooks/useFetch';
|
||||
import useAxiosAuth from '@/lib/axios/useAxiosAuth';
|
||||
import { titleCase } from '@/lib/helper';
|
||||
import PageLoading from '@/components/loader/PageLoading';
|
||||
import LazyLoading from '@/components/loader/LazyLoading';
|
||||
import { type IUser } from '../component/type';
|
||||
import { type IRole } from '@/app/admin/information/user-role/component/type';
|
||||
import { type ICompany } from '../../company/component/type';
|
||||
import { type IArea } from '../../area/component/type';
|
||||
import { type IDivision } from '../../division/component/type';
|
||||
import { type IPosition } from '@/app/admin/information/position/component/type';
|
||||
import { type IEmployeeType } from '@/app/admin/information/employee-type/component/type';
|
||||
import { toast } from 'sonner';
|
||||
|
||||
type Props = {};
|
||||
|
||||
const UserCreate: FC<Props> = ({ }) => {
|
||||
const [isLoading, setIsLoading] = useState(false)
|
||||
const [isFetching, setIsFetching] = useState(false)
|
||||
const [showConfirm, setShowConfirm] = useState(false)
|
||||
|
||||
const [form] = Form.useForm();
|
||||
const router = useRouter()
|
||||
const searchParams = useSearchParams();
|
||||
const axios = useAxiosAuth()
|
||||
|
||||
const isUpdate = searchParams!.get('is_update') as string || ''
|
||||
const id = searchParams!.get('id') as string || ''
|
||||
|
||||
const { data: companyList, isLoading: companyLoading } = useFetch('/company')
|
||||
const { data: areaList, isLoading: areaLoading } = useFetch('/area')
|
||||
const { data: divisionList, isLoading: divisionLoading } = useFetch('/division')
|
||||
const { data: roleList, isLoading: roleLoading } = useFetch('/role')
|
||||
const { data: positionList, isLoading: positionLoading } = useFetch('/position')
|
||||
const { data: employeeTypeList, isLoading: employeeTypeLoading } = useFetch('/employee-type')
|
||||
|
||||
useEffect(() => {
|
||||
async function fetchData() {
|
||||
setIsFetching(true)
|
||||
try {
|
||||
const res = await axios.get(`/user/${id}`)
|
||||
const data: IUser = res.data.data
|
||||
|
||||
form.setFieldsValue(data)
|
||||
|
||||
if (data.company) form.setFieldValue('company_id', data.company.id)
|
||||
if (data.area) form.setFieldValue('area_id', data.area.id)
|
||||
if (data.division) form.setFieldValue('division_id', data.division.id)
|
||||
if (data.role) form.setFieldValue('role_id', data.role.id)
|
||||
if (data.employee_type) form.setFieldValue('employee_type_id', data.employee_type.id)
|
||||
if (data.position) form.setFieldValue('position_id', data.position.id)
|
||||
|
||||
if (data.birthday) form.setFieldValue('birthday', dayjs(data.birthday))
|
||||
if (data.contract_expiration_date) form.setFieldValue('contract_expiration_date', dayjs(data.contract_expiration_date))
|
||||
if (data.hire_date) form.setFieldValue('hire_date', dayjs(data.hire_date))
|
||||
if (data.resign_date) form.setFieldValue('resign_date', dayjs(data.resign_date))
|
||||
|
||||
setIsFetching(false)
|
||||
} catch (error: any) {
|
||||
handleError(`Failed fetch data, (${error.response.data.code || error.response.status || '-'}) ${error.response.data.message || error.response.statusText || error.message}`)
|
||||
}
|
||||
}
|
||||
|
||||
if (isUpdate) {
|
||||
fetchData()
|
||||
} else {
|
||||
form.resetFields()
|
||||
}
|
||||
}, [isUpdate, form, id])
|
||||
|
||||
|
||||
const handleSubmit = () => {
|
||||
const payload = form.getFieldsValue()
|
||||
if (payload.fullname) payload.fullname = titleCase(payload.fullname)
|
||||
|
||||
!isUpdate ? handleCreate(payload) : handleUpdate(payload)
|
||||
}
|
||||
|
||||
const handleCreate = async (payload: IUser) => {
|
||||
try {
|
||||
setIsLoading(true)
|
||||
await axios.post('/user', payload)
|
||||
|
||||
handleSuccess('Data successfully created.')
|
||||
} catch (error: any) {
|
||||
handleError(`Data failed to create, (${error.response.data.code || error.response.status || '-'}) ${error.response.data.message || error.response.statusText || error.message}`)
|
||||
}
|
||||
}
|
||||
|
||||
const handleUpdate = async (payload: IUser) => {
|
||||
try {
|
||||
setIsLoading(true)
|
||||
await axios.put('/user/' + id, payload)
|
||||
|
||||
handleSuccess('Data successfully updated.')
|
||||
} catch (error: any) {
|
||||
handleError(`Data failed to update, (${error.response.data.code || error.response.status || '-'}) ${error.response.data.message || error.response.statusText || error.message}`)
|
||||
}
|
||||
}
|
||||
|
||||
const handleSuccess = (message: string) => {
|
||||
toast.success(message)
|
||||
router.replace('/admin/administration/user')
|
||||
router.refresh()
|
||||
form.resetFields()
|
||||
}
|
||||
|
||||
const handleError = (message: string) => {
|
||||
toast.error(message)
|
||||
setIsLoading(false)
|
||||
}
|
||||
|
||||
return (
|
||||
<>
|
||||
<Card>
|
||||
<CardHeader className='flex flex-row items-center sm:space-x-5'>
|
||||
<Link href='/admin/administration/user' className='hidden sm:block'>
|
||||
<Button variant='outline' size='icon'>
|
||||
<i className="ti ti-arrow-left text-xl"></i>
|
||||
</Button>
|
||||
</Link>
|
||||
<div className='space-y-1'>
|
||||
<CardTitle>{isUpdate ? 'Update user' : 'Create new user'}</CardTitle>
|
||||
<CardDescription>{isUpdate ? 'Update user id ' + id : 'Add a new team to join to your department'}</CardDescription>
|
||||
</div>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<Suspense fallback={<LazyLoading />}>
|
||||
<Form form={form} onFinish={() => setShowConfirm(true)} scrollToFirstError layout="vertical" size='small'>
|
||||
<div className='grid grid-cols-1 sm:grid-cols-2 font-medium gap-y-0 gap-x-5 2xl:gap-x-8'>
|
||||
{/* <Label htmlFor="fullname">Fullname</Label> */}
|
||||
<Form.Item name='fullname' labelAlign="left" label='Fullname' rules={[{ required: true, message: 'This field is required' }]} >
|
||||
<Input className="input" id="fullname" placeholder="John Doe" />
|
||||
</Form.Item>
|
||||
<Form.Item name='nickname' label='Nickname' rules={[{ required: true, message: 'This field is required' }]} >
|
||||
<Input className="input" id="nickname" placeholder="John" />
|
||||
</Form.Item>
|
||||
<Form.Item label='Email' name='email' rules={[
|
||||
{ required: true, message: 'This field is required' },
|
||||
{ type: 'email', message: 'The input is not valid E-mail!' }]}
|
||||
>
|
||||
<Input className="input" id="email" placeholder="john.nutech@gmail.com" />
|
||||
</Form.Item>
|
||||
{!isUpdate &&
|
||||
<Form.Item label='Password' name='password' rules={[
|
||||
{ required: true, message: 'This field is required' }, { min: 5 }
|
||||
]}>
|
||||
<Input.Password className="input" type="password" id="password" placeholder="********" />
|
||||
</Form.Item>
|
||||
}
|
||||
<Form.Item label='NIK' name='nik' rules={[
|
||||
{ required: true, message: 'This field is required' },
|
||||
{ pattern: /^\d+$/, message: 'Invalid NIK format' },
|
||||
{ len: 11 }
|
||||
]}>
|
||||
<Input className="input" id="nik" placeholder="04012345678" maxLength={11} />
|
||||
</Form.Item>
|
||||
<Form.Item label='NIKTG' name='niktg' rules={[
|
||||
{ pattern: /^\d+$/, message: 'Invalid NIKTG format' },
|
||||
]}>
|
||||
<Input className="input" id="niktg" placeholder="995500" maxLength={8} />
|
||||
</Form.Item>
|
||||
<Form.Item label='Phone Number' name='phone_number' rules={[
|
||||
{ required: true, message: 'This field is required' },
|
||||
{ pattern: /^\d+$/, message: 'Invalid phone number' },
|
||||
{ min: 10 }, { max: 13 }
|
||||
]}>
|
||||
<Input className="input" id="phone_number" placeholder="6281234567890" maxLength={13} />
|
||||
</Form.Item>
|
||||
<Form.Item label='Role' name='role_id' rules={[{ required: true, message: 'This field is required' }]} >
|
||||
<Select placeholder='Select role' showSearch allowClear loading={roleLoading}
|
||||
optionFilterProp="children"
|
||||
filterOption={(input, option) => option!.children!.toString().toLowerCase().indexOf(input.toLowerCase()) >= 0}
|
||||
getPopupContainer={(triggerNode: any) => triggerNode.parentNode}
|
||||
size='large'
|
||||
>
|
||||
{roleList?.role?.length > 0 && roleList.role.map((item: IRole, key: number) =>
|
||||
<Select.Option value={item.id} key={key}>{item.name}</Select.Option>
|
||||
)}
|
||||
</Select>
|
||||
</Form.Item>
|
||||
<Form.Item label='Company' name='company_id' rules={[{ required: true, message: 'This field is required' }]} >
|
||||
<Select placeholder='Select company' showSearch allowClear loading={companyLoading}
|
||||
optionFilterProp="children"
|
||||
filterOption={(input, option) => option!.children!.toString().toLowerCase().indexOf(input.toLowerCase()) >= 0}
|
||||
getPopupContainer={(triggerNode: any) => triggerNode.parentNode}
|
||||
size='large'
|
||||
>
|
||||
{companyList?.company?.length > 0 && companyList.company.map((item: ICompany, key: number) =>
|
||||
<Select.Option value={item.id} key={key}>{item.code} - {item.name}</Select.Option>
|
||||
)}
|
||||
</Select>
|
||||
</Form.Item>
|
||||
<Form.Item label='Area' name='area_id' rules={[{ required: true, message: 'This field is required' }]} >
|
||||
<Select placeholder='Select area' showSearch allowClear loading={areaLoading}
|
||||
optionFilterProp="children"
|
||||
filterOption={(input, option) => option!.children!.toString().toLowerCase().indexOf(input.toLowerCase()) >= 0}
|
||||
getPopupContainer={(triggerNode: any) => triggerNode.parentNode}
|
||||
size='large'
|
||||
>
|
||||
{areaList?.area?.length > 0 && areaList.area.map((item: IArea, key: number) =>
|
||||
<Select.Option value={item.id} key={key}>{item.name}</Select.Option>
|
||||
)}
|
||||
</Select>
|
||||
</Form.Item>
|
||||
<Form.Item label='Department' name='division_id' rules={[{ required: true, message: 'This field is required' }]} >
|
||||
<Select placeholder='Select division' showSearch allowClear loading={divisionLoading}
|
||||
optionFilterProp="children"
|
||||
filterOption={(input, option) => option!.children!.toString().toLowerCase().indexOf(input.toLowerCase()) >= 0}
|
||||
getPopupContainer={(triggerNode: any) => triggerNode.parentNode}
|
||||
size='large'
|
||||
>
|
||||
{divisionList?.division?.length > 0 && divisionList.division.map((item: IDivision, key: number) =>
|
||||
<Select.Option value={item.id} key={key}>{item.code} - {item.name}</Select.Option>
|
||||
)}
|
||||
</Select>
|
||||
</Form.Item>
|
||||
<Form.Item label='Position' name='position_id' rules={[{ required: true, message: 'This field is required' }]} >
|
||||
<Select placeholder='Select position' showSearch allowClear loading={positionLoading}
|
||||
optionFilterProp="children"
|
||||
filterOption={(input, option) => option!.children!.toString().toLowerCase().indexOf(input.toLowerCase()) >= 0}
|
||||
getPopupContainer={(triggerNode: any) => triggerNode.parentNode}
|
||||
size='large'
|
||||
>
|
||||
{positionList?.position?.length > 0 && positionList.position.map((item: IPosition, key: number) =>
|
||||
<Select.Option value={item.id} key={key}>{item.name}</Select.Option>
|
||||
)}
|
||||
</Select>
|
||||
</Form.Item>
|
||||
<Form.Item label='Employee Type' name='employee_type_id' rules={[{ required: true, message: 'This field is required' }]} >
|
||||
<Select placeholder='Select employee type' showSearch allowClear loading={employeeTypeLoading}
|
||||
optionFilterProp="children"
|
||||
filterOption={(input, option) => option!.children!.toString().toLowerCase().indexOf(input.toLowerCase()) >= 0}
|
||||
getPopupContainer={(triggerNode: any) => triggerNode.parentNode}
|
||||
size='large'
|
||||
>
|
||||
{employeeTypeList?.employee_type?.length > 0 && employeeTypeList.employee_type.map((item: IEmployeeType, key: number) =>
|
||||
<Select.Option value={item.id} key={key}>{item.name}</Select.Option>
|
||||
)}
|
||||
</Select>
|
||||
</Form.Item>
|
||||
<Form.Item label='Birthdate' name='birthday'>
|
||||
<DatePicker className='w-full' placeholder='Select date of birth' size='large' />
|
||||
</Form.Item>
|
||||
<Form.Item label='Gender' name='gender'>
|
||||
<Radio.Group>
|
||||
<Radio value="male">Male</Radio>
|
||||
<Radio value="female">Female</Radio>
|
||||
</Radio.Group>
|
||||
</Form.Item>
|
||||
<Form.Item label='Hire Date' name='hire_date'>
|
||||
<DatePicker className='w-full' placeholder='Select date of hire' size='large' />
|
||||
</Form.Item>
|
||||
<Form.Item label='Contract Expiration Date' name='contract_expiration_date'>
|
||||
<DatePicker className='w-full' placeholder='Select contract expiration date' size='large' />
|
||||
</Form.Item>
|
||||
<Form.Item label='Extend Contract' name='is_extend_contract'>
|
||||
<Radio.Group>
|
||||
<Radio value={true}>Yes</Radio>
|
||||
<Radio value={false}>No</Radio>
|
||||
</Radio.Group>
|
||||
</Form.Item>
|
||||
<Form.Item label='Office Email' name='email_office' rules={[
|
||||
{ type: 'email', message: 'The input is not valid E-mail!' }]}
|
||||
>
|
||||
<Input className="input" id="email_office" placeholder="john@nutech-integrasi.com" />
|
||||
</Form.Item>
|
||||
<Form.Item label='Personal Email' name='email_personal' rules={[
|
||||
{ type: 'email', message: 'The input is not valid E-mail!' }]}
|
||||
>
|
||||
<Input className="input" id="email_personal" placeholder="john@gmail.com" />
|
||||
</Form.Item>
|
||||
<Form.Item label='Last Education' name='last_education' >
|
||||
<Input className="input" id="last_education" placeholder="S1 Teknik Informatika" />
|
||||
</Form.Item>
|
||||
<Form.Item label='Resign Date' name='resign_date'>
|
||||
<DatePicker className='w-full' placeholder='Select resign date' size='large' />
|
||||
</Form.Item>
|
||||
<Form.Item label='Resign Reason' name='resign_reason' >
|
||||
<Input.TextArea className="input" id="resign_reason" placeholder="Describe reason of resign" rootClassName='px-3! py-2!' />
|
||||
</Form.Item>
|
||||
<Form.Item label='Post Company' name='post_company'>
|
||||
<Input className="input" id="post_company" placeholder="PT Tokopedia" />
|
||||
</Form.Item>
|
||||
</div>
|
||||
<div className='flex justify-end items-center'>
|
||||
<Button type='submit'>
|
||||
{isLoading && (
|
||||
<Icons.spinner className="mr-1 h-4 w-4 animate-spin" />
|
||||
)}
|
||||
Save
|
||||
</Button>
|
||||
</div>
|
||||
</Form>
|
||||
</Suspense>
|
||||
</CardContent>
|
||||
</Card>
|
||||
{isUpdate && isFetching &&
|
||||
<PageLoading />
|
||||
}
|
||||
|
||||
{showConfirm &&
|
||||
<AlertDialog open={true}>
|
||||
<AlertDialogContent>
|
||||
<AlertDialogHeader>
|
||||
<AlertDialogTitle>Are you absolutely sure?</AlertDialogTitle>
|
||||
<AlertDialogDescription>
|
||||
This data will be stored on our server, you can change it whenever you want later.
|
||||
</AlertDialogDescription>
|
||||
</AlertDialogHeader>
|
||||
<AlertDialogFooter>
|
||||
<AlertDialogCancel disabled={isLoading} onClick={() => setShowConfirm(false)}>Cancel</AlertDialogCancel>
|
||||
<AlertDialogAction disabled={isLoading} onClick={handleSubmit}>
|
||||
{isLoading && (
|
||||
<Icons.spinner className="mr-1 h-4 w-4 animate-spin" />
|
||||
)}
|
||||
Continue
|
||||
</AlertDialogAction>
|
||||
</AlertDialogFooter>
|
||||
</AlertDialogContent>
|
||||
</AlertDialog>
|
||||
}
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
export default UserCreate;
|
||||
@@ -0,0 +1,70 @@
|
||||
import { type Metadata } from 'next';
|
||||
import { FC, 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)
|
||||
|
||||
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?.length)
|
||||
|
||||
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'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>
|
||||
</>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user