feat: update shift management with jadwal shift integration and improved error handling
This commit is contained in:
@@ -31,7 +31,6 @@ import IndexRole from './pages/role/IndexRole';
|
|||||||
import IndexUser from './pages/user/IndexUser';
|
import IndexUser from './pages/user/IndexUser';
|
||||||
|
|
||||||
// Shift Management
|
// Shift Management
|
||||||
import IndexSchedule from './pages/shiftManagement/schedule/IndexSchedule';
|
|
||||||
import IndexMember from './pages/shiftManagement/member/IndexMember';
|
import IndexMember from './pages/shiftManagement/member/IndexMember';
|
||||||
|
|
||||||
import SvgTest from './pages/home/SvgTest';
|
import SvgTest from './pages/home/SvgTest';
|
||||||
@@ -87,7 +86,6 @@ const App = () => {
|
|||||||
</Route>
|
</Route>
|
||||||
|
|
||||||
<Route path="/shift-management" element={<ProtectedRoute />}>
|
<Route path="/shift-management" element={<ProtectedRoute />}>
|
||||||
<Route path="schedule" element={<IndexSchedule />} />
|
|
||||||
<Route path="member" element={<IndexMember />} />
|
<Route path="member" element={<IndexMember />} />
|
||||||
</Route>
|
</Route>
|
||||||
|
|
||||||
|
|||||||
@@ -130,16 +130,20 @@ const allItems = [
|
|||||||
</Link>
|
</Link>
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
key: 'jadwal-shift',
|
||||||
|
icon: <CalendarOutlined style={{ fontSize: '19px' }} />,
|
||||||
|
label: (
|
||||||
|
<Link to="/jadwal-shift" className="fontMenus">
|
||||||
|
Jadwal Shift
|
||||||
|
</Link>
|
||||||
|
),
|
||||||
|
},
|
||||||
{
|
{
|
||||||
key: 'shift-management',
|
key: 'shift-management',
|
||||||
icon: <ClockCircleOutlined style={{ fontSize: '19px' }} />,
|
icon: <ClockCircleOutlined style={{ fontSize: '19px' }} />,
|
||||||
label: 'Manajemen Shift',
|
label: 'Manajemen Shift',
|
||||||
children: [
|
children: [
|
||||||
{
|
|
||||||
key: 'shift-schedule',
|
|
||||||
icon: <CalendarOutlined style={{ fontSize: '19px' }} />,
|
|
||||||
label: <Link to="/shift-management/schedule">Jadwal Shift</Link>,
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
key: 'shift-member',
|
key: 'shift-member',
|
||||||
icon: <UsergroupAddOutlined style={{ fontSize: '19px' }} />,
|
icon: <UsergroupAddOutlined style={{ fontSize: '19px' }} />,
|
||||||
@@ -165,6 +169,7 @@ const LayoutMenu = () => {
|
|||||||
if (pathname === '/role') return 'role';
|
if (pathname === '/role') return 'role';
|
||||||
if (pathname === '/notification') return 'notification';
|
if (pathname === '/notification') return 'notification';
|
||||||
if (pathname === '/event-alarm') return 'event-alarm';
|
if (pathname === '/event-alarm') return 'event-alarm';
|
||||||
|
if (pathname === '/jadwal-shift') return 'jadwal-shift';
|
||||||
|
|
||||||
// Handle master routes
|
// Handle master routes
|
||||||
if (pathname.startsWith('/master/')) {
|
if (pathname.startsWith('/master/')) {
|
||||||
|
|||||||
@@ -1,10 +1,39 @@
|
|||||||
import { useState } from 'react';
|
import { useState, useEffect } from 'react';
|
||||||
import ListJadwalShift from './component/ListJadwalShift';
|
import ListJadwalShift from './component/ListJadwalShift';
|
||||||
import DetailJadwalShift from './component/DetailJadwalShift';
|
import DetailJadwalShift from './component/DetailJadwalShift';
|
||||||
|
import { getAllJadwalShift, deleteJadwalShift } from '../../api/jadwal-shift';
|
||||||
|
|
||||||
const IndexJadwalShift = () => {
|
const IndexJadwalShift = () => {
|
||||||
const [actionMode, setActionMode] = useState('list');
|
const [actionMode, setActionMode] = useState('list');
|
||||||
const [selectedData, setSelectedData] = useState(null);
|
const [selectedData, setSelectedData] = useState(null);
|
||||||
|
const [jadwalShiftData, setJadwalShiftData] = useState([]);
|
||||||
|
const [loading, setLoading] = useState(false);
|
||||||
|
|
||||||
|
const fetchData = async () => {
|
||||||
|
setLoading(true);
|
||||||
|
try {
|
||||||
|
const response = await getAllJadwalShift(new URLSearchParams());
|
||||||
|
if (response.data) {
|
||||||
|
setJadwalShiftData(response.data.data);
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Error fetching jadwal shift data:", error);
|
||||||
|
}
|
||||||
|
setLoading(false);
|
||||||
|
};
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
fetchData();
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
const handleDelete = async (id) => {
|
||||||
|
try {
|
||||||
|
await deleteJadwalShift(id);
|
||||||
|
fetchData();
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Error deleting jadwal shift:", error);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
@@ -12,6 +41,9 @@ const IndexJadwalShift = () => {
|
|||||||
<ListJadwalShift
|
<ListJadwalShift
|
||||||
setActionMode={setActionMode}
|
setActionMode={setActionMode}
|
||||||
setSelectedData={setSelectedData}
|
setSelectedData={setSelectedData}
|
||||||
|
jadwalShiftData={jadwalShiftData}
|
||||||
|
loading={loading}
|
||||||
|
onDelete={handleDelete}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
{(actionMode === 'add' || actionMode === 'edit') && (
|
{(actionMode === 'add' || actionMode === 'edit') && (
|
||||||
@@ -19,6 +51,8 @@ const IndexJadwalShift = () => {
|
|||||||
actionMode={actionMode}
|
actionMode={actionMode}
|
||||||
selectedData={selectedData}
|
selectedData={selectedData}
|
||||||
setActionMode={setActionMode}
|
setActionMode={setActionMode}
|
||||||
|
setSelectedData={setSelectedData}
|
||||||
|
fetchData={fetchData}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
</>
|
</>
|
||||||
|
|||||||
@@ -22,13 +22,23 @@ const DetailJadwalShift = (props) => {
|
|||||||
const [FormData, setFormData] = useState(defaultData);
|
const [FormData, setFormData] = useState(defaultData);
|
||||||
|
|
||||||
const fetchShifts = async () => {
|
const fetchShifts = async () => {
|
||||||
const response = await getAllShift(new URLSearchParams());
|
try {
|
||||||
setShifts(response.data.data);
|
const response = await getAllShift(new URLSearchParams());
|
||||||
|
setShifts(response?.data?.data || []);
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Failed to fetch shifts:", error);
|
||||||
|
setShifts([]);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const fetchUsers = async () => {
|
const fetchUsers = async () => {
|
||||||
const response = await getAllUser(new URLSearchParams("limit=1000")); // Fetch all users
|
try {
|
||||||
setUsers(response.data.data);
|
const response = await getAllUser(new URLSearchParams("limit=1000")); // Fetch all users
|
||||||
|
setUsers(response?.data?.data || []);
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Failed to fetch users:", error);
|
||||||
|
setUsers([]);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@@ -82,6 +92,7 @@ const DetailJadwalShift = (props) => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
props.setActionMode('list');
|
props.setActionMode('list');
|
||||||
|
props.fetchData();
|
||||||
} else {
|
} else {
|
||||||
NotifAlert({
|
NotifAlert({
|
||||||
icon: 'error',
|
icon: 'error',
|
||||||
|
|||||||
@@ -1,60 +1,66 @@
|
|||||||
import { useEffect, useState } from 'react';
|
import React, { memo, useState, useEffect } from 'react';
|
||||||
import { Button, Table, Space, Popconfirm } from 'antd';
|
import { Button, Col, Row, Input, ConfigProvider, Card, Table, Space } from 'antd';
|
||||||
import { getAllJadwalShift, deleteJadwalShift } from '../../../api/jadwal-shift';
|
import {
|
||||||
import { NotifAlert, NotifOk } from '../../../components/Global/ToastNotif';
|
PlusOutlined,
|
||||||
|
EditOutlined,
|
||||||
|
DeleteOutlined,
|
||||||
|
SearchOutlined,
|
||||||
|
EyeOutlined,
|
||||||
|
} from '@ant-design/icons';
|
||||||
|
import { NotifConfirmDialog } from '../../../components/Global/ToastNotif';
|
||||||
|
import { useNavigate } from 'react-router-dom';
|
||||||
|
|
||||||
const ListJadwalShift = (props) => {
|
const ListJadwalShift = (props) => {
|
||||||
const [data, setData] = useState([]);
|
const [searchValue, setSearchValue] = useState('');
|
||||||
const [loading, setLoading] = useState(false);
|
const navigate = useNavigate();
|
||||||
|
|
||||||
const fetchData = async () => {
|
useEffect(() => {
|
||||||
setLoading(true);
|
const token = localStorage.getItem('token');
|
||||||
try {
|
if (!token) {
|
||||||
const response = await getAllJadwalShift(new URLSearchParams());
|
navigate('/signin');
|
||||||
if (response.data && response.data.data) {
|
|
||||||
setData(response.data.data);
|
|
||||||
} else {
|
|
||||||
setData([]);
|
|
||||||
}
|
|
||||||
} catch (error) {
|
|
||||||
console.error("Failed to fetch shift schedule data:", error);
|
|
||||||
setData([]); // Set data to empty array on error
|
|
||||||
} finally {
|
|
||||||
setLoading(false);
|
|
||||||
}
|
}
|
||||||
|
}, [navigate]);
|
||||||
|
|
||||||
|
const handleSearch = (value) => {
|
||||||
|
console.log('Search value:', value);
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleAdd = () => {
|
const handleSearchClear = () => {
|
||||||
props.setSelectedData(null);
|
setSearchValue('');
|
||||||
props.setActionMode('add');
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleEdit = (record) => {
|
const showPreviewModal = (record) => {
|
||||||
|
props.setSelectedData(record);
|
||||||
|
props.setActionMode('preview');
|
||||||
|
};
|
||||||
|
|
||||||
|
const showEditModal = (record) => {
|
||||||
props.setSelectedData(record);
|
props.setSelectedData(record);
|
||||||
props.setActionMode('edit');
|
props.setActionMode('edit');
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleDelete = async (id) => {
|
const showAddModal = () => {
|
||||||
try {
|
props.setSelectedData(null);
|
||||||
const response = await deleteJadwalShift(id);
|
props.setActionMode('add');
|
||||||
if (response.statusCode === 200) {
|
|
||||||
NotifOk({ icon: 'success', title: 'Berhasil', message: 'Data jadwal shift berhasil dihapus' });
|
|
||||||
fetchData();
|
|
||||||
} else {
|
|
||||||
NotifAlert({ icon: 'error', title: 'Gagal', message: response.message });
|
|
||||||
}
|
|
||||||
} catch (error) {
|
|
||||||
NotifAlert({ icon: 'error', title: 'Error', message: error.message });
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
useEffect(() => {
|
const showDeleteDialog = (record) => {
|
||||||
if(props.actionMode === 'list') {
|
NotifConfirmDialog({
|
||||||
fetchData();
|
icon: 'question',
|
||||||
}
|
title: 'Konfirmasi',
|
||||||
}, [props.actionMode]);
|
message: `Apakah anda yakin ingin menghapus data jadwal shift untuk "${record.nama_employee}"?`,
|
||||||
|
onConfirm: () => props.onDelete(record.id),
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
const columns = [
|
const columns = [
|
||||||
|
{
|
||||||
|
title: 'No',
|
||||||
|
key: 'no',
|
||||||
|
width: '5%',
|
||||||
|
align: 'center',
|
||||||
|
render: (_, __, index) => index + 1,
|
||||||
|
},
|
||||||
{
|
{
|
||||||
title: 'Nama Shift',
|
title: 'Nama Shift',
|
||||||
dataIndex: 'nama_shift',
|
dataIndex: 'nama_shift',
|
||||||
@@ -83,35 +89,97 @@ const ListJadwalShift = (props) => {
|
|||||||
{
|
{
|
||||||
title: 'Aksi',
|
title: 'Aksi',
|
||||||
key: 'action',
|
key: 'action',
|
||||||
render: (text, record) => (
|
align: 'center',
|
||||||
<Space size="middle">
|
width: '15%',
|
||||||
<Button type="primary" onClick={() => handleEdit(record)}>Edit</Button>
|
render: (_, record) => (
|
||||||
<Popconfirm
|
<Space>
|
||||||
title="Hapus data jadwal shift?"
|
<Button
|
||||||
description="Apakah anda yakin untuk menghapus data jadwal shift ini?"
|
icon={<EyeOutlined />}
|
||||||
onConfirm={() => handleDelete(record.id)}
|
onClick={() => showPreviewModal(record)}
|
||||||
okText="Yes"
|
style={{
|
||||||
cancelText="No"
|
color: '#1890ff',
|
||||||
>
|
borderColor: '#1890ff',
|
||||||
<Button danger>Delete</Button>
|
}}
|
||||||
</Popconfirm>
|
/>
|
||||||
|
<Button
|
||||||
|
icon={<EditOutlined />}
|
||||||
|
onClick={() => showEditModal(record)}
|
||||||
|
style={{
|
||||||
|
color: '#faad14',
|
||||||
|
borderColor: '#faad14',
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
<Button
|
||||||
|
danger
|
||||||
|
icon={<DeleteOutlined />}
|
||||||
|
onClick={() => showDeleteDialog(record)}
|
||||||
|
style={{
|
||||||
|
borderColor: '#ff4d4f',
|
||||||
|
}}
|
||||||
|
/>
|
||||||
</Space>
|
</Space>
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
|
const filteredData = props.jadwalShiftData.filter(item =>
|
||||||
|
item.nama_employee.toLowerCase().includes(searchValue.toLowerCase()) ||
|
||||||
|
item.username.toLowerCase().includes(searchValue.toLowerCase()) ||
|
||||||
|
item.nama_shift.toLowerCase().includes(searchValue.toLowerCase())
|
||||||
|
);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div>
|
<Card>
|
||||||
<Button type="primary" onClick={handleAdd} style={{ marginBottom: 16 }}>
|
<Row justify="space-between" align="middle" gutter={[16, 16]}>
|
||||||
Tambah Jadwal Shift
|
<Col xs={24} sm={12} md={10} lg={8}>
|
||||||
</Button>
|
<Input.Search
|
||||||
<Table
|
placeholder="Cari jadwal shift..."
|
||||||
columns={columns}
|
value={searchValue}
|
||||||
dataSource={data}
|
onChange={(e) => setSearchValue(e.target.value)}
|
||||||
loading={loading}
|
onSearch={handleSearch}
|
||||||
rowKey="id"
|
allowClear={{
|
||||||
/>
|
clearIcon: <span onClick={handleSearchClear}>x</span>,
|
||||||
</div>
|
}}
|
||||||
|
enterButton={<Button type="primary" icon={<SearchOutlined />} style={{ backgroundColor: '#23A55A', borderColor: '#23A55A' }}>Cari</Button>}
|
||||||
|
size="large"
|
||||||
|
/>
|
||||||
|
</Col>
|
||||||
|
<Col>
|
||||||
|
<ConfigProvider
|
||||||
|
theme={{
|
||||||
|
token: { colorBgContainer: '#E9F6EF' },
|
||||||
|
components: {
|
||||||
|
Button: {
|
||||||
|
defaultBg: 'white',
|
||||||
|
defaultColor: '#23A55A',
|
||||||
|
defaultBorderColor: '#23A55A',
|
||||||
|
defaultHoverColor: '#23A55A',
|
||||||
|
defaultHoverBorderColor: '#23A55A',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<Button
|
||||||
|
icon={<PlusOutlined />}
|
||||||
|
onClick={showAddModal}
|
||||||
|
size="large"
|
||||||
|
>
|
||||||
|
Tambah Jadwal Shift
|
||||||
|
</Button>
|
||||||
|
</ConfigProvider>
|
||||||
|
</Col>
|
||||||
|
</Row>
|
||||||
|
<Row style={{ marginTop: 16 }}>
|
||||||
|
<Col span={24}>
|
||||||
|
<Table
|
||||||
|
columns={columns}
|
||||||
|
dataSource={filteredData}
|
||||||
|
loading={props.loading}
|
||||||
|
rowKey="id"
|
||||||
|
/>
|
||||||
|
</Col>
|
||||||
|
</Row>
|
||||||
|
</Card>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user