diff --git a/src/slices/apiSlice/employeeAttendanceSlice.js b/src/slices/apiSlice/employeeAttendanceSlice.js new file mode 100644 index 00000000..e76c4989 --- /dev/null +++ b/src/slices/apiSlice/employeeAttendanceSlice.js @@ -0,0 +1,57 @@ +import { createSlice, createAsyncThunk } from '@reduxjs/toolkit'; +import AttendanceRepository from '../../repositories/AttendanceRepository'; +import { markAttendance } from './attedanceLogsSlice'; + +export const fetchEmployeeAttendanceData = createAsyncThunk( + 'employeeAttendance/fetchEmployeeAttendanceData', + async ( {employeeId, fromDate, toDate}, thunkAPI ) => + { + try { + const response = await AttendanceRepository.getAttendanceByEmployee( employeeId, fromDate, toDate ); + console.log(response) + // return response?.data?.filter((log) => log.checkInTime !== null && log.activity !== 0); + return response.data + } catch (error) { + return thunkAPI.rejectWithValue(error.message); + } + } +); + + +const employeeAttendancesSlice = createSlice({ + name: 'employeeAttendance', // Updated slice name + initialState: { + data: [], + loading: false, + error: null, + }, + reducers: { + setEmployeeAttendanceData: (state, action) => { + state.data = action.payload; + }, + }, + extraReducers: (builder) => { + builder + // Fetch attendance data + .addCase(fetchEmployeeAttendanceData.pending, (state) => { + state.loading = true; + }) + .addCase(fetchEmployeeAttendanceData.fulfilled, (state, action) => { + state.loading = false; + state.data = action.payload; + }) + + + .addCase(fetchEmployeeAttendanceData.rejected, (state, action) => { + state.loading = false; + state.error = action.payload; + }) + + + + + }, + }); + + export const { setEmployeeAttendanceData } = employeeAttendancesSlice.actions; + export default employeeAttendancesSlice.reducer; \ No newline at end of file