homeBannerAction.js 951 Bytes
import axios from "axios";
import qs from "qs";
import { GET_HOMEBANNER_FAIL, GET_HOMEBANNER_REQUEST, GET_HOMEBANNER_SUCCESS } from "../constants/homeBannerConstants";

export const getHomeBanner = () => async dispatch => {
  try {
    
    dispatch({
      type: GET_HOMEBANNER_REQUEST
    });
    const config = {
      headers: {
        "Content-Type": "application/json"
      }
    };

    const query = {
      populate: ["desktopBanner, mobileBanner"]
    };

    const queryString = qs.stringify(query, {
      encodeValuesOnly: true
    });

    const response = await axios.get(`${process.env.NEXT_PUBLIC_BACKEND_API_URL}/api/home-banners?${queryString}`, config);
    console.log("response > ", response);
    dispatch({
      type: GET_HOMEBANNER_SUCCESS,
      payload: response.data
    });

    return response.data;
  } catch (error) {
    dispatch({
      type: GET_HOMEBANNER_FAIL,
      payload: error.response.data
    });
  }
};