49 lines
1.7 KiB
JavaScript
49 lines
1.7 KiB
JavaScript
|
|
||
|
import { creditTreatDemand } from "./IlinkConstants";
|
||
|
import { store } from "../redux/store";
|
||
|
import axios from "axios";
|
||
|
import { fetchTreatCreditDemandPending, fetchTreatCreditDemandSucsess, fetchTreatCreditDemandError, fetchTreatCreditDemandReset } from "../redux/actions/CreditTreatDemandActions";
|
||
|
|
||
|
export const treatCreditDemand = (idDemand, montant) => {
|
||
|
|
||
|
let dataToSend = {};
|
||
|
|
||
|
if (typeof montant !== 'undefined')
|
||
|
dataToSend = { "montant": montant };
|
||
|
|
||
|
const auth = store.getState().authKeyReducer;
|
||
|
const authKey = auth !== null ? `${auth.authKey.token_type} ${auth.authKey.access_token}` : '';
|
||
|
|
||
|
return dispatch => {
|
||
|
dispatch(fetchTreatCreditDemandPending());
|
||
|
|
||
|
axios({
|
||
|
url: `${creditTreatDemand}/${idDemand}`,
|
||
|
method: 'PUT',
|
||
|
headers: {
|
||
|
'Authorization': authKey
|
||
|
},
|
||
|
data: dataToSend
|
||
|
})
|
||
|
.then(response => {
|
||
|
console.log(response);
|
||
|
dispatch(fetchTreatCreditDemandSucsess(response));
|
||
|
})
|
||
|
.catch(error => {
|
||
|
console.log(error);
|
||
|
dispatch(fetchTreatCreditDemandError(error.message));
|
||
|
if (error.response)
|
||
|
dispatch(fetchTreatCreditDemandError(error.response));
|
||
|
else if (error.request)
|
||
|
dispatch(fetchTreatCreditDemandError(error.request))
|
||
|
else
|
||
|
dispatch(fetchTreatCreditDemandError(error.message))
|
||
|
});
|
||
|
}
|
||
|
}
|
||
|
|
||
|
export const creditDemandResetReducer = () => {
|
||
|
return dispatch => {
|
||
|
dispatch(fetchTreatCreditDemandReset());
|
||
|
}
|
||
|
}
|