companyInformationAction.js 1.09 KB
import axios from "axios";
import { FETCH_COMPANY_INFORMATION_SUCCESS, FETCH_COMPANY_INFORMATION_FAIL, CLEAR_ERRORS } from "../constants/companyInformationConstants";
import qs from "qs";

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

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

    dispatch({
      type: FETCH_COMPANY_INFORMATION_SUCCESS,
      payload: response.data
    });
  } catch (error) {
    console.log("Error while fetching company information");
    console.log(error);
    // console.log(error.response.data);

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

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