confirmDateSlice.js 1.72 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
import {createAsyncThunk, createSlice} from '@reduxjs/toolkit';

import serviceRequest from '../../app/serviceRequest';

import Utils from '../../utils';
import authAPI from '../../api/authAPI';
import confirmDateAPI from '../../api/confirmDateAPI';
const initialState = {};

export const getUserConfirmDay = createAsyncThunk(
  'confirmDate/getUserConfirmDay',
  async (data, thunkAPI) => {
    return serviceRequest({
      dispatch: thunkAPI.dispatch,
      serviceMethod: confirmDateAPI.requestGetConfirmDay,
      payload: data,
      options: {
        skipLoader: false,
      },
    });
  },
);
export const getConfirmApprovedDate = createAsyncThunk(
  'confirmDate/getConfirmApprovedDate',
  async (data, thunkAPI) => {
    return serviceRequest({
      dispatch: thunkAPI.dispatch,
      serviceMethod: confirmDateAPI.requestGetConfirmApprovedDate,
      payload: data,
      options: {
        skipLoader: false,
      },
    });
  },
);
const authSlice = createSlice({
  name: 'confirmDate',
  initialState: initialState,
  reducers: {},
  extraReducers: builder => {
    builder.addCase(getUserConfirmDay.fulfilled, (state, action) => {
      const {success} = Utils.getValues(action, 'payload', false);

      if (success) {
        state.confirmDateList = Utils.getValues(
          action,
          'payload.data.collection',
          [],
        );
      }
    });
    builder.addCase(getConfirmApprovedDate.fulfilled, (state, action) => {
      const {success} = Utils.getValues(action, 'payload', false);
      if (success) {
        state.confirmApprovedDateList = Utils.getValues(
          action,
          'payload.data.collection',
          [],
        );
      }
    });
  },
});

const {reducer} = authSlice;
export default reducer;