| 
									
										
										
										
											2020-05-01 22:36:24 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | import { creditTreatDemand } 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 { 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: { | 
					
						
							| 
									
										
										
										
											2020-05-06 13:07:53 +00:00
										 |  |  |                     'Authorization': authKey, | 
					
						
							|  |  |  |                     'X-Localization': I18n.currentLocale() | 
					
						
							| 
									
										
										
										
											2020-05-01 22:36:24 +00:00
										 |  |  |                }, | 
					
						
							|  |  |  |                data: dataToSend | 
					
						
							|  |  |  |           }) | 
					
						
							|  |  |  |                .then(response => { | 
					
						
							|  |  |  |                     console.log(response); | 
					
						
							|  |  |  |                     dispatch(fetchTreatCreditDemandSucsess(response)); | 
					
						
							|  |  |  |                }) | 
					
						
							|  |  |  |                .catch(error => { | 
					
						
							|  |  |  |                     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()); | 
					
						
							|  |  |  |      } | 
					
						
							|  |  |  | } |