diff --git a/src/pages/master/shift/IndexShift.jsx b/src/pages/master/shift/IndexShift.jsx
index bb67155..4e860d3 100644
--- a/src/pages/master/shift/IndexShift.jsx
+++ b/src/pages/master/shift/IndexShift.jsx
@@ -1,10 +1,58 @@
-import { useState } from 'react';
+import { useState, useEffect } from 'react';
import ListShift from './component/ListShift';
import DetailShift from './component/DetailShift';
+import { getAllShift } from '../../../api/master-shift';
const IndexShift = () => {
const [actionMode, setActionMode] = useState('list');
const [selectedData, setSelectedData] = useState(null);
+ const [shiftData, setShiftData] = useState([]);
+ const [loading, setLoading] = useState(false);
+
+ const fetchData = async () => {
+ setLoading(true);
+ try {
+ const localData = localStorage.getItem('shiftData');
+ if (localData) {
+ setShiftData(JSON.parse(localData));
+ } else {
+ const response = await getAllShift();
+ if (response.data) {
+ setShiftData(response.data.data);
+ localStorage.setItem('shiftData', JSON.stringify(response.data.data));
+ }
+ }
+ } catch (error) {
+ console.error("Error fetching shift data:", error);
+ }
+ setLoading(false);
+ };
+
+ useEffect(() => {
+ fetchData();
+ }, []);
+
+ const handleAddShift = (newShift) => {
+ const newData = { ...newShift, id: Date.now() }; // Simulate adding an ID
+ const updatedData = [newData, ...shiftData];
+ setShiftData(updatedData);
+ localStorage.setItem('shiftData', JSON.stringify(updatedData));
+ setActionMode('list');
+ };
+
+ const handleUpdateShift = (updatedShift) => {
+ const updatedData = shiftData.map(shift => shift.id === updatedShift.id ? updatedShift : shift);
+ setShiftData(updatedData);
+ localStorage.setItem('shiftData', JSON.stringify(updatedData));
+ setActionMode('list');
+ };
+
+ const handleDeleteShift = (id) => {
+ const updatedData = shiftData.filter(shift => shift.id !== id);
+ setShiftData(updatedData);
+ localStorage.setItem('shiftData', JSON.stringify(updatedData));
+ };
+
return (
<>
@@ -12,6 +60,10 @@ const IndexShift = () => {