348 lines
11 KiB
JavaScript
348 lines
11 KiB
JavaScript
|
import axios from "axios";
|
||
|
import I18n from 'react-native-i18n';
|
||
|
import {
|
||
|
fetchAskNanoCreditError,
|
||
|
fetchAskNanoCreditPending,
|
||
|
fetchAskNanoCreditReset,
|
||
|
fetchAskNanoCreditSuccess,
|
||
|
fetchCreateGroupError,
|
||
|
fetchCreateGroupPending,
|
||
|
fetchCreateGroupReset,
|
||
|
fetchCreateGroupSuccess,
|
||
|
fetchGetEpargneInProgressError,
|
||
|
fetchGetEpargneInProgressPending,
|
||
|
fetchGetEpargneInProgressReset,
|
||
|
fetchGetEpargneInProgressSuccess,
|
||
|
fetchGetNanoCreditDemandDurationError,
|
||
|
fetchGetNanoCreditDemandDurationPending,
|
||
|
fetchGetNanoCreditDemandDurationReset,
|
||
|
fetchGetNanoCreditDemandDurationSuccess,
|
||
|
fetchGetNanoCreditUserHistoryInProgressError,
|
||
|
fetchGetNanoCreditUserHistoryInProgressPending,
|
||
|
fetchGetNanoCreditUserHistoryInProgressReset,
|
||
|
fetchGetNanoCreditUserHistoryInProgressSuccess,
|
||
|
fetchJoinGroupError,
|
||
|
fetchJoinGroupPending,
|
||
|
fetchJoinGroupReset,
|
||
|
fetchJoinGroupSuccess,
|
||
|
fetchTreatDemandsGroupError,
|
||
|
fetchTreatDemandsGroupPending,
|
||
|
fetchTreatDemandsGroupReset,
|
||
|
fetchTreatDemandsGroupSuccess
|
||
|
} from "../redux/actions/NanoCreditAction";
|
||
|
import {store} from "../redux/store";
|
||
|
import {
|
||
|
askNanoCreditUrl,
|
||
|
cancelDemandUrl, getHistoryEpargnePendingUrl,
|
||
|
getHistoryNanoPendingCreditUrl,
|
||
|
getNanoCreditDemandDureationUrl,
|
||
|
groupUrl,
|
||
|
joinGroupUrl,
|
||
|
treatDemandUrl
|
||
|
} from "./IlinkConstants";
|
||
|
|
||
|
/**
|
||
|
*
|
||
|
* @param {*} data
|
||
|
* @param {*} isToMofidy | 0-> CREATE 1->MODIFY 2->DELETE
|
||
|
*/
|
||
|
export const createGroupAction = (data, isToMofidy) => {
|
||
|
|
||
|
|
||
|
const auth = store.getState().authKeyReducer;
|
||
|
const authKey = auth !== null ? `${auth.authKey.token_type} ${auth.authKey.access_token}` : '';
|
||
|
|
||
|
return dispatch => {
|
||
|
dispatch(fetchCreateGroupPending());
|
||
|
|
||
|
axios({
|
||
|
url: `${groupUrl}`,
|
||
|
method: isToMofidy === 0 ?
|
||
|
'POST' :
|
||
|
isToMofidy === 1 ? 'PUT' : 'DELETE',
|
||
|
data,
|
||
|
headers: {
|
||
|
'Authorization': authKey,
|
||
|
'X-Localization': I18n.currentLocale()
|
||
|
}
|
||
|
})
|
||
|
.then(response => {
|
||
|
console.log(response);
|
||
|
dispatch(fetchCreateGroupSuccess(response));
|
||
|
})
|
||
|
.catch(error => {
|
||
|
if (error.response)
|
||
|
dispatch(fetchCreateGroupError(error.response));
|
||
|
else if (error.request)
|
||
|
dispatch(fetchCreateGroupError(error.request))
|
||
|
else
|
||
|
dispatch(fetchCreateGroupError(error.message))
|
||
|
});
|
||
|
}
|
||
|
}
|
||
|
|
||
|
export const createGroupReset = () => {
|
||
|
return dispatch => {
|
||
|
dispatch(fetchCreateGroupReset());
|
||
|
}
|
||
|
}
|
||
|
|
||
|
export const treatDemandGroupAction = (data) => {
|
||
|
|
||
|
const auth = store.getState().authKeyReducer;
|
||
|
const authKey = auth !== null ? `${auth.authKey.token_type} ${auth.authKey.access_token}` : '';
|
||
|
|
||
|
return dispatch => {
|
||
|
dispatch(fetchTreatDemandsGroupPending());
|
||
|
|
||
|
axios({
|
||
|
url: `${treatDemandUrl}`,
|
||
|
method: 'POST',
|
||
|
data,
|
||
|
headers: {
|
||
|
'Authorization': authKey,
|
||
|
'X-Localization': I18n.currentLocale()
|
||
|
}
|
||
|
})
|
||
|
.then(response => {
|
||
|
console.log(response);
|
||
|
dispatch(fetchTreatDemandsGroupSuccess(response));
|
||
|
})
|
||
|
.catch(error => {
|
||
|
if (error.response)
|
||
|
dispatch(fetchTreatDemandsGroupError(error.response));
|
||
|
else if (error.request)
|
||
|
dispatch(fetchTreatDemandsGroupError(error.request))
|
||
|
else
|
||
|
dispatch(fetchTreatDemandsGroupError(error.message))
|
||
|
});
|
||
|
}
|
||
|
}
|
||
|
|
||
|
export const cancelDemandGroupAction = (data) => {
|
||
|
|
||
|
const auth = store.getState().authKeyReducer;
|
||
|
const authKey = auth !== null ? `${auth.authKey.token_type} ${auth.authKey.access_token}` : '';
|
||
|
|
||
|
return dispatch => {
|
||
|
dispatch(fetchTreatDemandsGroupPending());
|
||
|
|
||
|
axios({
|
||
|
url: `${cancelDemandUrl}`,
|
||
|
method: 'POST',
|
||
|
data,
|
||
|
headers: {
|
||
|
'Authorization': authKey,
|
||
|
'X-Localization': I18n.currentLocale()
|
||
|
}
|
||
|
})
|
||
|
.then(response => {
|
||
|
console.log(response);
|
||
|
dispatch(fetchTreatDemandsGroupSuccess(response));
|
||
|
})
|
||
|
.catch(error => {
|
||
|
if (error.response)
|
||
|
dispatch(fetchTreatDemandsGroupError(error.response));
|
||
|
else if (error.request)
|
||
|
dispatch(fetchTreatDemandsGroupError(error.request))
|
||
|
else
|
||
|
dispatch(fetchTreatDemandsGroupError(error.message))
|
||
|
});
|
||
|
}
|
||
|
}
|
||
|
|
||
|
export const treatDemandGroupReset = () => {
|
||
|
return dispatch => {
|
||
|
dispatch(fetchTreatDemandsGroupReset());
|
||
|
}
|
||
|
}
|
||
|
|
||
|
export const joinGroupAction = (data) => {
|
||
|
|
||
|
const auth = store.getState().authKeyReducer;
|
||
|
const authKey = auth !== null ? `${auth.authKey.token_type} ${auth.authKey.access_token}` : '';
|
||
|
|
||
|
return dispatch => {
|
||
|
dispatch(fetchJoinGroupPending());
|
||
|
|
||
|
axios({
|
||
|
url: `${joinGroupUrl}`,
|
||
|
method: 'POST',
|
||
|
data,
|
||
|
headers: {
|
||
|
'Authorization': authKey,
|
||
|
'X-Localization': I18n.currentLocale()
|
||
|
}
|
||
|
})
|
||
|
.then(response => {
|
||
|
console.log(response);
|
||
|
dispatch(fetchJoinGroupSuccess(response));
|
||
|
})
|
||
|
.catch(error => {
|
||
|
if (error.response)
|
||
|
dispatch(fetchJoinGroupError(error.response));
|
||
|
else if (error.request)
|
||
|
dispatch(fetchJoinGroupError(error.request))
|
||
|
else
|
||
|
dispatch(fetchJoinGroupError(error.message))
|
||
|
});
|
||
|
}
|
||
|
}
|
||
|
|
||
|
export const joinGroupReset = () => {
|
||
|
return dispatch => {
|
||
|
dispatch(fetchJoinGroupReset());
|
||
|
}
|
||
|
}
|
||
|
|
||
|
|
||
|
export const askNanoCreditAction = (data) => {
|
||
|
|
||
|
const auth = store.getState().authKeyReducer;
|
||
|
const authKey = auth !== null ? `${auth.authKey.token_type} ${auth.authKey.access_token}` : '';
|
||
|
|
||
|
return dispatch => {
|
||
|
dispatch(fetchAskNanoCreditPending());
|
||
|
|
||
|
axios({
|
||
|
url: `${askNanoCreditUrl}`,
|
||
|
method: 'POST',
|
||
|
data,
|
||
|
headers: {
|
||
|
'Authorization': authKey,
|
||
|
'X-Localization': I18n.currentLocale()
|
||
|
}
|
||
|
})
|
||
|
.then(response => {
|
||
|
console.log(response);
|
||
|
dispatch(fetchAskNanoCreditSuccess(response));
|
||
|
})
|
||
|
.catch(error => {
|
||
|
if (error.response)
|
||
|
dispatch(fetchAskNanoCreditError(error.response));
|
||
|
else if (error.request)
|
||
|
dispatch(fetchAskNanoCreditError(error.request))
|
||
|
else
|
||
|
dispatch(fetchAskNanoCreditError(error.message))
|
||
|
});
|
||
|
}
|
||
|
}
|
||
|
|
||
|
export const askNanoCreditReset = () => {
|
||
|
return dispatch => {
|
||
|
dispatch(fetchAskNanoCreditReset());
|
||
|
}
|
||
|
}
|
||
|
|
||
|
export const getNanoCreditDemandDurationAction = (data) => {
|
||
|
|
||
|
const auth = store.getState().authKeyReducer;
|
||
|
const authKey = auth !== null ? `${auth.authKey.token_type} ${auth.authKey.access_token}` : '';
|
||
|
|
||
|
return dispatch => {
|
||
|
dispatch(fetchGetNanoCreditDemandDurationPending());
|
||
|
|
||
|
axios({
|
||
|
url: `${getNanoCreditDemandDureationUrl}`,
|
||
|
method: 'POST',
|
||
|
data,
|
||
|
headers: {
|
||
|
'Authorization': authKey,
|
||
|
'X-Localization': I18n.currentLocale()
|
||
|
}
|
||
|
})
|
||
|
.then(response => {
|
||
|
console.log(response);
|
||
|
dispatch(fetchGetNanoCreditDemandDurationSuccess(response));
|
||
|
})
|
||
|
.catch(error => {
|
||
|
if (error.response)
|
||
|
dispatch(fetchGetNanoCreditDemandDurationError(error.response));
|
||
|
else if (error.request)
|
||
|
dispatch(fetchGetNanoCreditDemandDurationError(error.request))
|
||
|
else
|
||
|
dispatch(fetchGetNanoCreditDemandDurationError(error.message))
|
||
|
});
|
||
|
}
|
||
|
}
|
||
|
|
||
|
export const getNanoCreditDemandDurationReset = () => {
|
||
|
return dispatch => {
|
||
|
dispatch(fetchGetNanoCreditDemandDurationReset());
|
||
|
}
|
||
|
}
|
||
|
|
||
|
|
||
|
export const getEpargneInProgressAction = (data) => {
|
||
|
|
||
|
const auth = store.getState().authKeyReducer;
|
||
|
const authKey = auth !== null ? `${auth.authKey.token_type} ${auth.authKey.access_token}` : '';
|
||
|
|
||
|
return dispatch => {
|
||
|
dispatch(fetchGetEpargneInProgressPending());
|
||
|
|
||
|
axios({
|
||
|
url: `${getHistoryEpargnePendingUrl}/${data}`,
|
||
|
method: 'GET',
|
||
|
headers: {
|
||
|
'Authorization': authKey,
|
||
|
'X-Localization': I18n.currentLocale()
|
||
|
}
|
||
|
})
|
||
|
.then(response => {
|
||
|
console.log(response);
|
||
|
dispatch(fetchGetEpargneInProgressSuccess(response));
|
||
|
})
|
||
|
.catch(error => {
|
||
|
if (error.response)
|
||
|
dispatch(fetchGetEpargneInProgressError(error.response));
|
||
|
else if (error.request)
|
||
|
dispatch(fetchGetEpargneInProgressError(error.request))
|
||
|
else
|
||
|
dispatch(fetchGetEpargneInProgressError(error.message))
|
||
|
});
|
||
|
}
|
||
|
}
|
||
|
|
||
|
|
||
|
export const getEpargneInProgressReset = () => {
|
||
|
return dispatch => {
|
||
|
dispatch(fetchGetEpargneInProgressReset());
|
||
|
}
|
||
|
}
|
||
|
export const getNanoCreditUserHistoryInProgressAction = (data) => {
|
||
|
|
||
|
const auth = store.getState().authKeyReducer;
|
||
|
const authKey = auth !== null ? `${auth.authKey.token_type} ${auth.authKey.access_token}` : '';
|
||
|
|
||
|
return dispatch => {
|
||
|
dispatch(fetchGetNanoCreditUserHistoryInProgressPending());
|
||
|
|
||
|
axios({
|
||
|
url: `${getHistoryNanoPendingCreditUrl}/${data}`,
|
||
|
method: 'GET',
|
||
|
headers: {
|
||
|
'Authorization': authKey,
|
||
|
'X-Localization': I18n.currentLocale()
|
||
|
}
|
||
|
})
|
||
|
.then(response => {
|
||
|
console.log(response);
|
||
|
dispatch(fetchGetNanoCreditUserHistoryInProgressSuccess(response));
|
||
|
})
|
||
|
.catch(error => {
|
||
|
if (error.response)
|
||
|
dispatch(fetchGetNanoCreditUserHistoryInProgressError(error.response));
|
||
|
else if (error.request)
|
||
|
dispatch(fetchGetNanoCreditUserHistoryInProgressError(error.request))
|
||
|
else
|
||
|
dispatch(fetchGetNanoCreditUserHistoryInProgressError(error.message))
|
||
|
});
|
||
|
}
|
||
|
}
|
||
|
|
||
|
export const getNanoCreditUserHistoryInProgressReset = () => {
|
||
|
return dispatch => {
|
||
|
dispatch(fetchGetNanoCreditUserHistoryInProgressReset());
|
||
|
}
|
||
|
}
|