ilink-world/app/webservice/CreditCancelDemandeApi.js

43 lines
1.6 KiB
JavaScript
Raw Permalink Normal View History

2020-05-01 22:36:24 +00:00
import { creditCancelDemand } from "./IlinkConstants";
import { store } from "../redux/store";
import axios from "axios";
2020-05-06 13:07:53 +00:00
import I18n from 'react-native-i18n'
2020-05-01 22:36:24 +00:00
import { fetchTreatCreditCancelPending, fetchTreatCreditCancelSucsess, fetchTreatCreditCancelError, fetchTreatCreditCancelReset } from "../redux/actions/CreditCancelDemandAction";
export const treatCancelDemand = (idDemand) => {
const auth = store.getState().authKeyReducer;
const authKey = auth !== null ? `${auth.authKey.token_type} ${auth.authKey.access_token}` : '';
return dispatch => {
dispatch(fetchTreatCreditCancelPending());
axios({
url: `${creditCancelDemand}/${idDemand}`,
method: 'PUT',
headers: {
2020-05-06 13:07:53 +00:00
'Authorization': authKey,
'X-Localization': I18n.currentLocale()
2020-05-01 22:36:24 +00:00
}
})
.then(response => {
console.log(response);
dispatch(fetchTreatCreditCancelSucsess(response));
})
.catch(error => {
if (error.response)
dispatch(fetchTreatCreditCancelError(error.response));
else if (error.request)
dispatch(fetchTreatCreditCancelError(error.request))
else
dispatch(fetchTreatCreditCancelError(error.message))
});
}
}
export const creditCancelResetReducer = () => {
return dispatch => {
dispatch(fetchTreatCreditCancelReset());
}
}