import React, { memo, useState, useEffect } from 'react';
import { Button, Col, Row, Input, ConfigProvider, Card, Tag, Table, Space } from 'antd';
import {
PlusOutlined,
EditOutlined,
DeleteOutlined,
SearchOutlined,
EyeOutlined,
SyncOutlined,
} from '@ant-design/icons';
import { NotifConfirmDialog } from '../../../../components/Global/ToastNotif';
import { useNavigate } from 'react-router-dom';
const ListShift = (props) => {
const [searchValue, setSearchValue] = useState('');
const navigate = useNavigate();
useEffect(() => {
const token = localStorage.getItem('token');
if (!token) {
navigate('/signin');
}
}, [navigate]);
const handleSearch = (value) => {
// This will be handled by the parent component if server-side search is needed
console.log('Search value:', value);
};
const handleSearchClear = () => {
setSearchValue('');
// This will be handled by the parent component if server-side search is needed
};
const showPreviewModal = (record) => {
props.setSelectedData(record);
props.setActionMode('preview');
};
const showEditModal = (record) => {
props.setSelectedData(record);
props.setActionMode('edit');
};
const showAddModal = () => {
props.setSelectedData(null);
props.setActionMode('add');
};
const showDeleteDialog = (record) => {
NotifConfirmDialog({
icon: 'question',
title: 'Konfirmasi',
message: `Apakah anda yakin ingin menghapus data shift "${record.nama_shift}"?`,
onConfirm: () => props.onDelete(record.id),
});
};
const columns = [
{
title: 'No',
key: 'no',
width: '5%',
align: 'center',
render: (_, __, index) => index + 1,
},
{
title: 'Nama Shift',
dataIndex: 'nama_shift',
key: 'nama_shift',
},
{
title: 'Jam Shift',
dataIndex: 'jam_shift',
key: 'jam_shift',
},
{
title: 'Status',
dataIndex: 'status',
key: 'status',
align: 'center',
render: (status) => (
{status ? 'Active' : 'Inactive'}
),
},
{
title: 'Aksi',
key: 'action',
align: 'center',
width: '15%',
render: (_, record) => (
}
onClick={() => showPreviewModal(record)}
style={{
color: '#1890ff',
borderColor: '#1890ff',
}}
/>
}
onClick={() => showEditModal(record)}
style={{
color: '#faad14',
borderColor: '#faad14',
}}
/>
}
onClick={() => showDeleteDialog(record)}
style={{
borderColor: '#ff4d4f',
}}
/>
),
},
];
const filteredData = props.shiftData.filter(item =>
item.nama_shift.toLowerCase().includes(searchValue.toLowerCase())
);
return (
setSearchValue(e.target.value)}
onSearch={handleSearch}
allowClear={{
clearIcon: x,
}}
enterButton={} style={{ backgroundColor: '#23A55A', borderColor: '#23A55A' }}>Cari}
size="large"
/>
}
onClick={showAddModal}
size="large"
>
Tambah Shift
);
};
export default memo(ListShift);