projectsReducer.js
1.89 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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
import {
FETCH_PROJECTS_REQUEST,
FETCH_PROJECTS_SUCCESS,
FETCH_PROJECTS_FAIL,
FETCH_PROJECT_REQUEST,
FETCH_PROJECT_SUCCESS,
FETCH_PROJECT_FAIL,
CLEAR_ERRORS,
FETCH_SIMILAR_PROJECTS_REQUEST,
FETCH_SIMILAR_PROJECTS_SUCCESS,
FETCH_SIMILAR_PROJECTS_FAIL
} from "../constants/projectsConstants";
// Room details reducer.
export const projectsReducer = (state = { projects: [] }, action) => {
switch (action.type) {
case FETCH_PROJECTS_REQUEST:
return {
loading: true
};
case FETCH_PROJECTS_SUCCESS:
return {
loading: false,
totalCount: action.payload.meta.pagination.total,
resultsPerPage: action.payload.meta.pagination.pageSize,
projects: action.payload.data
};
case FETCH_PROJECTS_FAIL:
return {
error: action.payload.error.message
};
case CLEAR_ERRORS:
return {
...state,
error: null
};
default:
return state;
}
};
export const projectReducer = (state = { project: {} }, action) => {
switch (action.type) {
case FETCH_PROJECT_REQUEST:
return {
loading: true
};
case FETCH_PROJECT_SUCCESS:
return {
project: action.payload.data
};
case FETCH_PROJECT_FAIL:
return {
error: action.payload.error.message
};
case CLEAR_ERRORS:
return {
...state,
error: null
};
default:
return state;
}
};
export const similarProjectsReducer = (state = { similarProjects: [] }, action) => {
switch (action.type) {
case FETCH_SIMILAR_PROJECTS_REQUEST:
return {
loading: true
};
case FETCH_SIMILAR_PROJECTS_SUCCESS:
return {
similarProjects: action.payload.data
};
case FETCH_SIMILAR_PROJECTS_FAIL:
return {
error: action.payload.error.message
};
default:
return state;
}
};