'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 = ({ data }) => { const [filterData, setFilterData] = useState([]) const { isMobile, windowWidth } = useMobileView() useEffect(() => { if (data) { setFilterData(data) } }, [data]) const handleSearch = (e: ChangeEvent) => { 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 = [ { 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) => {val} }, { 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' ? {record.status.name} : '' }, { 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) => {dayjs(val).format('HH:mm A')} }, { 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 ? e.stopPropagation()} className='text-his hover:opacity-70 duration-200' href={process.env.BASE_URL_IMG + val} target="_blank">View Photo : '' }, { 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 ? {dayjs(record.presence_checkout?.working_hours_end).format('HH:mm A')} : 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 ? 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 : '' }, { 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 ? : '-' }, { title: 'Clear AutoChekout', dataIndex: 'status', render: (val, record) => record?.is_clear_auto_checkout === false ? need to be approve : record.is_clear_auto_checkout === true ? approved : undefined }, ]; const tableProps: TableProps = { 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 ( <> {/*
*/}
1900 ? 1400 : windowWidth > 1280 ? 1200 : windowWidth > 1000 ? 800 : windowWidth > 760 ? 600 : windowWidth * 0.72 }} className='flex flex-col space-y-4'>
{ return { onClick: event => { console.log(record.face_image); }, // click row }; }} rowKey='presence_checkin_code' columns={Columns} dataSource={filterData || []} style={{ cursor: "pointer" }} /> ); } export default TableAttendanceHistory;