-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnotifications.reducer.ts
More file actions
53 lines (51 loc) · 1.3 KB
/
notifications.reducer.ts
File metadata and controls
53 lines (51 loc) · 1.3 KB
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
import get from 'lodash/get'
import { IState } from './notifications.types'
import * as CONSTANTS from './notifications.constants'
import { NOTIFICATIONS } from 'src/constants'
const initialState: IState = {
notificationsList: [],
isLoading: false,
}
export default (state = initialState, action: any) => {
switch (action.type) {
case CONSTANTS.FETCH_NOTIFICATIONS_REQUEST:
return {
...state,
isLoading: true,
}
case CONSTANTS.FETCH_NOTIFICATIONS_SUCCESS:
const notificationsList = action.payload
return {
...state,
notificationsList,
isLoading: false,
}
case CONSTANTS.FETCH_NOTIFICATIONS_FAILURE:
return {
...state,
isLoading: false,
}
case CONSTANTS.UPDATE_NOTIFICATIONS_REQUEST:
return {
...state,
isLoading: false,
}
case CONSTANTS.UPDATE_NOTIFICATIONS_SUCCESS:
return {
...state,
isLoading: false,
notificationsList: state.notificationsList.map(elem => ({
...elem,
status: NOTIFICATIONS.STATUSES.READ,
})),
}
case CONSTANTS.UPDATE_NOTIFICATIONS_FAILURE:
return {
...state,
isLoading: false,
createGroupError: action.error,
}
default:
return state
}
}