43 lines
1.6 KiB
JavaScript
43 lines
1.6 KiB
JavaScript
|
|
||
|
import { creditCancelDemand } from "./IlinkConstants";
|
||
|
import { store } from "../redux/store";
|
||
|
import axios from "axios";
|
||
|
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: {
|
||
|
'Authorization': authKey
|
||
|
}
|
||
|
})
|
||
|
.then(response => {
|
||
|
console.log(response);
|
||
|
dispatch(fetchTreatCreditCancelSucsess(response));
|
||
|
})
|
||
|
.catch(error => {
|
||
|
console.log(error);
|
||
|
dispatch(fetchTreatCreditCancelError(error.message));
|
||
|
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());
|
||
|
}
|
||
|
}
|