Commit 755f2adb authored by Ramadevi Guduri's avatar Ramadevi Guduri

reportsuiand slice

parent 09e51d5b
This diff is collapsed.
......@@ -3,16 +3,17 @@ import { base_url } from "../../utils/constants";
import axios from "axios";
const initialState = {
totalReporteesData: [],
activitiesData:null,
// totalReporteesData: [],
activitiesData:[],
loading: false,
error: null,
fromDate: null,
toDate: null,
};
export const fetchReportstableData = createAsyncThunk("getreportees", async (data) => {
return await axios.post(`${base_url}/getreportees`, data)
export const fetchReportesActivitiesData = createAsyncThunk("gettotalactivities", async (data) => {
return await axios.post(`${base_url}/getActivities`, data)
.then((response) => response.data);
});
......@@ -23,57 +24,28 @@ const exporttableSlice = createSlice({
resetReporteesTableData:() => {
return initialState
},
setPastMonth: (state) => {
const toDate = new Date();
const fromDate = new Date();
fromDate.setMonth(fromDate.getMonth() - 1);
state.fromDate = fromDate;
state.toDate = toDate;
console.log(fromDate,toDate)
},
setPastTwoMonths: (state) => {
const toDate = new Date();
const fromDate = new Date();
fromDate.setMonth(fromDate.getMonth() - 3);
state.fromDate = fromDate;
state.toDate = toDate;
console.log(fromDate,toDate)
},
setPastsixMonths: (state) => {
const toDate = new Date();
const fromDate = new Date();
fromDate.setMonth(fromDate.getMonth() - 6);
state.fromDate = fromDate;
state.toDate = toDate;
console.log(fromDate,toDate)
},
setPasttwelvemonths: (state) => {
const toDate = new Date();
const fromDate = new Date();
fromDate.setMonth(fromDate.getMonth() - 12);
state.fromDate = fromDate;
state.toDate = toDate;
console.log(fromDate,toDate)
},
},
extraReducers: (builder) => {
builder.addCase(fetchReportstableData.pending, (state) => {
builder.addCase(fetchReportesActivitiesData.pending, (state) => {
state.loading = true;
state.error = "pending";
});
builder.addCase(fetchReportstableData.fulfilled, (state, action) => {
builder.addCase(fetchReportesActivitiesData.fulfilled, (state, action) => {
console.log(action.payload.activities)
state.loading = false;
state.totalReporteesData = action.payload.data;
state.activitiesData = action.payload.activities ;
state.error = "";
});
builder.addCase(fetchReportstableData.rejected, (state, action) => {
builder.addCase(fetchReportesActivitiesData.rejected, (state, action) => {
state.loading = false;
state.totalReporteesData = null;
state.activitiesData = null;
state.error = action.error || "Something went wrong!";
});
},
});
export const {resetReporteesTableData,setPastMonth,setPastTwoMonths,setPastsixMonths,setPasttwelvemonths} = exporttableSlice.actions;
export const {resetReporteesTableData} = exporttableSlice.actions;
export default exporttableSlice.reducer;
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment