import { createSlice } from '@reduxjs/toolkit';
import { aLocationChange, aSetFilterData } from './bonus';
/**
* @namespace reducer/reportsReducer
*/
const initialState = {
reports: null,
reportsShop: null,
turnover: null,
lastRoundStartDate: '',
freeBetShopReports: null,
};
const resetReports = (state) => {
state.reports = null;
state.reportsShop = null;
state.turnover = null;
state.lastRoundStartDate = '';
};
const reportsSlice = createSlice({
name: 'reports',
initialState,
reducers: {
aGetTurnoverReports: resetReports,
aGetRoundReportsSuccess: (state, action) => {
state.reports = action.payload ? action.payload.roundStats : null;
state.lastRoundStartDate = action.payload.lastRoundStartDate;
},
aGetRoundReportsShopSuccess: (state, action) => {
state.reportsShop = action.payload ? action.payload.roundStats : null;
state.lastRoundStartDate = action.payload.lastRoundStartDate;
},
aGetTurnoverReportsSuccess: (state, action) => {
state.turnover = action.payload.turnover;
},
aGetFreeBetShopReportsSuccess: (state, action) => {
state.freeBetShopReports = action.payload.freeBetShopReports;
},
},
extraReducers: (builder) => {
builder.addCase(aLocationChange, resetReports);
builder.addCase(aSetFilterData, resetReports);
},
});
export default reportsSlice.reducer;
export const {
aGetTurnoverReports,
aGetRoundReportsSuccess,
aGetRoundReportsShopSuccess,
aGetTurnoverReportsSuccess,
aGetFreeBetShopReportsSuccess,
} = reportsSlice.actions;