cpConnectPageAction.js 1003 Bytes
import axios from "axios";
import { FETCH_CP_CONNECT_PAGE_SUCCESS, FETCH_CP_CONNECT_PAGE_FAIL, CLEAR_ERRORS } from "../constants/cpConnectPageConstants";
import qs from "qs";

// Get room details
export const getCPConnectPage = () => async dispatch => {
  try {
    const config = {
      headers: {
        "Content-Type": "application/json"
      }
    };
    const query = qs.stringify(
      {
        populate: ["banner"]
      },
      {
        encodeValuesOnly: true // prettify URL
      }
    );

    const response = await axios.get(`${process.env.NEXT_PUBLIC_BACKEND_API_URL}/api/cp-connect-page?${query}`, config);

    dispatch({
      type: FETCH_CP_CONNECT_PAGE_SUCCESS,
      payload: response.data
    });
  } catch (error) {
    console.log(error.response.data);

    dispatch({
      type: FETCH_CP_CONNECT_PAGE_FAIL,
      payload: error.response.data
    });
  }
};

// Clear errors
export const clearErrors = () => async dispatch => {
  dispatch({
    type: CLEAR_ERRORS
  });
};