import axios from 'axios';
import {
  FETCHING_RETURN_REQUESTS,
  RETURN_REQUESTS_SUCCESS,
  RETURN_REQUESTS_FAILURE,
} from './types';

import setHeader from '../helpers/setheader';
import { apiURL } from './userSignUp';

const fetchingreturnRequests = () => ({
  type: FETCHING_RETURN_REQUESTS,
});

const returnRequestsSuccess = returnRequests => ({
  type: RETURN_REQUESTS_SUCCESS,
  returnRequests,
});

const returnRequestsFailure = error => ({
  type: RETURN_REQUESTS_FAILURE,
  error,
});

const getReturnRequests = () => (dispatch) => {
  dispatch(fetchingreturnRequests());
  setHeader();
  return axios.get(`${apiURL}/returnrequests`)
    .then((response) => {
      console.log(response.data);
      dispatch(returnRequestsSuccess(response.data.requests));
    })
    .catch((error) => {
      if (error.response) {
        let errorMessage = '';
        errorMessage = error.response.msg;
        dispatch(returnRequestsFailure(errorMessage));
      } else {
        dispatch(returnRequestsFailure(error.message));
      }
    });
};

export default getReturnRequests;


@@ -111,16 +111,109 @@
 AILURE,%0A
+  HANDLING_RETURN_REQUEST,%0A  HANDLE_RETURN_REQUEST_SUCCESS,%0A  HANDLE_RETURN_REQUEST_FAILURE,%0A
 %7D from '
@@ -315,33 +315,33 @@
 %0A%0Aconst fetching
-r
+R
 eturnRequests = 
@@ -580,24 +580,31 @@
 error,%0A%7D);%0A%0A
+export 
 const getRet
@@ -658,17 +658,17 @@
 fetching
-r
+R
 eturnReq
@@ -1145,39 +1145,981 @@
 %7D;%0A%0A
-export default getReturnRequests;%0A
+const handlingReturnRequest = () =%3E (%7B%0A  type: HANDLING_RETURN_REQUEST,%0A%7D);%0A%0Aconst handleReturnRequestSuccess = (status, index) =%3E (%7B%0A  type: HANDLE_RETURN_REQUEST_SUCCESS,%0A  status,%0A  index,%0A%7D);%0A%0Aconst handleReturnRequestFailure = error =%3E (%7B%0A  type: HANDLE_RETURN_REQUEST_FAILURE,%0A  error,%0A%7D);%0A%0Aexport const handleReturnRequest = (status, userId, bookId, requestIndex) =%3E (dispatch) =%3E %7B%0A  dispatch(handlingReturnRequest());%0A  setHeader();%0A  return axios.put(%60$%7BapiURL%7D/users/$%7BuserId%7D/return/$%7BbookId%7D%60, status)%0A    .then((response) =%3E %7B%0A      console.log(response.data);%0A      dispatch(handleReturnRequestSuccess(response.data.msg, requestIndex));%0A    %7D)%0A    .catch((error) =%3E %7B%0A      if (error.response) %7B%0A        console.log(error.response);%0A        let errorMessage = '';%0A        errorMessage = error.response.msg;%0A        dispatch(handleReturnRequestFailure(errorMessage));%0A      %7D else %7B%0A        dispatch(handleReturnRequestFailure(error.message));%0A      %7D%0A    %7D);%0A%7D;
 %0A

Add action for handling return request