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
import {createAsyncThunk, createSlice} from '@reduxjs/toolkit';
import serviceRequest from '../../app/serviceRequest';
import notificationAPI from '../../api/notificationAPI';
import Utils from '../../utils';
const initialState = {
notificationList: [],
};
export const getNotification = createAsyncThunk(
'notification/getNotification',
async (data, thunkAPI) => {
return serviceRequest({
dispatch: thunkAPI.dispatch,
serviceMethod: notificationAPI.requestGetNotification,
payload: data,
options: {
skipLoader: false,
},
});
},
);
const notificationSlice = createSlice({
name: 'notification',
initialState: initialState,
reducers: {},
extraReducers: builder => {
builder.addCase(getNotification.fulfilled, (state, action) => {
const {success} = Utils.getValues(action, 'payload', false);
if (success) {
state.notificationList = Utils.getValues(
action,
'payload.data.collection',
[],
);
}
});
},
});
const {reducer} = notificationSlice;
export default reducer;