bookingReducer.js
1.08 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
import { BOOKING_DETAILS_SUCCESS, BOOKING_DETAILS_FAIL, FETCH_MY_BOOKINGS_SUCCESS, FETCH_MY_BOOKINGS_FAIL, CLEAR_ERRORS } from "../constants/bookingConstants";
// Get all booked dates.
export const fetchMyBookingsReducer = (state = { bookings: [] }, action) => {
switch (action.type) {
case FETCH_MY_BOOKINGS_SUCCESS:
return {
loading: false,
bookings: action.payload
};
case FETCH_MY_BOOKINGS_FAIL:
return {
loading: false,
error: action.payload.error.message
};
case CLEAR_ERRORS:
return {
...state,
error: null
};
default:
return state;
}
};
// Room details reducer.
export const bookingDetailsReducer = (state = { booking: {} }, action) => {
switch (action.type) {
case BOOKING_DETAILS_SUCCESS:
return {
booking: action.payload.data
};
case BOOKING_DETAILS_FAIL:
return {
error: action.payload.error.message
};
case CLEAR_ERRORS:
return {
...state,
error: null
};
default:
return state;
}
};