-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patheventReducer.ts
36 lines (31 loc) · 1.2 KB
/
eventReducer.ts
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
import * as ActionTypes from '../actions/actionTypes';
import { EventActionTypes } from '../actions/eventActions';
interface EventState {
loading: boolean;
data: any; // Define a more specific type based on your data structure
error: string | null;
}
const initialState: EventState = {
loading: true,
data: [],
error: null,
};
const eventReducer = (state = initialState, action: EventActionTypes): EventState => {
switch (action.type) {
case ActionTypes.FETCH_EVENT_REQUEST:
return { ...state, loading: true };
case ActionTypes.FETCH_EVENT_SUCCESS:
return { ...state, loading: false, data: action.payload };
case ActionTypes.FETCH_EVENT_FAILURE:
return { ...state, loading: false, error: action.payload };
case ActionTypes.FETCH_EVENT_TIMEOUT:
return { ...state, loading: false, error: 'Network request timed out' };
case ActionTypes.FETCH_EVENT_CONNECTION_ERROR:
return { ...state, loading: false, error: 'Error connecting to the server' };
case ActionTypes.FETCH_EVENT_SERVER_ERROR:
return { ...state, loading: false, error: action.payload };
default:
return state;
}
};
export default eventReducer;