locationsAction.js
1.06 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
import axios from "axios";
import { FETCH_LOCATIONS_SUCCESS, FETCH_LOCATIONS_FAIL, CLEAR_ERRORS } from "../constants/locationsConstants";
import qs from "qs";
// Get room details
export const getLocations = () => async dispatch => {
try {
const config = {
headers: {
"Content-Type": "application/json"
}
};
const query = qs.stringify(
{
filters: {},
populate: [],
pagination: {
pageSize: 100,
page: 1
}
},
{
encodeValuesOnly: true // prettify URL
}
);
const response = await axios.get(`${process.env.NEXT_PUBLIC_BACKEND_API_URL}/api/locations?${query}`, config);
dispatch({
type: FETCH_LOCATIONS_SUCCESS,
payload: response.data
});
} catch (error) {
console.log("Error while locations: ");
console.log(error);
dispatch({
type: FETCH_LOCATIONS_FAIL,
payload: error.response.data
});
}
};
// Clear errors
export const clearErrors = () => async dispatch => {
dispatch({
type: CLEAR_ERRORS
});
};