reducers/rounds.js

import { createSlice } from '@reduxjs/toolkit';
import { aGetInitSuccess, aLocationChange, aSetFilterData } from './bonus';

/**
 * @namespace reducer/roundsReducer
 */
const initialState = {
  rounds: null,
  roundsTurbo: null,
  roundsShop: null,
  selectedRound: null,
  roundDropDown: null,
  lastStartDate: '',
  turboLastStartDate: '',
};

const resetRounds = (state) => {
  state.selectedRound = null;
  state.rounds = null;
  state.roundsTurbo = null;
  state.roundsShop = null;
  state.turboLastStartDate = '';
  state.lastStartDate = '';
};

const roundsSlice = createSlice({
  name: 'rounds',
  initialState,
  reducers: {
    aGetRoundsSuccess: (state, action) => {
      state.rounds = action.payload.rounds;
      state.lastStartDate = action.payload.lastStartDate;
    },
    aGetRoundsTurboSuccess: (state, action) => {
      state.roundsTurbo = action.payload.roundsTurbo;
      state.turboLastStartDate = action.payload.turboLastStartDate;
    },
    aGetRoundShopSuccess: (state, action) => {
      state.roundsShop = action.payload.roundsShop;
      state.lastStartDate = action.payload.lastStartDate;
    },
    aGetRoundDetailsSuccess: (state, action) => {
      state.selectedRound = action.payload.selectedRound;
    },
  },
  extraReducers: (builder) => {
    builder.addCase(aGetInitSuccess, (state, action) => {
      state.roundDropDown = action.payload.selects.roundStatus;
    });
    builder.addCase(aLocationChange, resetRounds);
    builder.addCase(aSetFilterData, resetRounds);
  },
});

export default roundsSlice.reducer;

export const { aGetRoundsSuccess, aGetRoundsTurboSuccess, aGetRoundShopSuccess, aGetRoundDetailsSuccess } =
  roundsSlice.actions;