Blame view

redux/actions/testimonialAction.js 936 Bytes
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
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);
.  
jaymehta committed
26
    // console.log("response > ", response);
27 28 29 30 31 32 33 34 35 36 37 38 39
    dispatch({
      type: GET_TESTIMONIAL_SUCCESS,
      payload: response.data
    });

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