testimonialAction.js 936 Bytes
import axios from "axios";
import qs from "qs";
import { GET_TESTIMONIAL_FAIL, GET_TESTIMONIAL_REQUEST, GET_TESTIMONIAL_SUCCESS } from "../constants/testimonialConstants";

export const getTestimonial = () => async dispatch => {
  try {

    dispatch({
      type: GET_TESTIMONIAL_REQUEST
    });

    const config = {
      headers: {
        "Content-Type": "application/json"
      }
    };
    const query = {
      populate: ["image"]
    };

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

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

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