ilink-world/app/webservice/CountryApi.js

151 lines
5.4 KiB
JavaScript
Raw Permalink Normal View History

2020-06-23 08:55:19 +00:00
import axios from "axios";
import I18n from 'react-native-i18n';
import { fetchActiveCountryListPending, fetchActiveCountryListSucsess, fetchActiveCountryListError, fetchActiveCountryListReset, fetchPayCountryNetworkPending, fetchPayCountryNetworkSucsess, fetchPayCountryNetworkError, fetchPayCountryNetworkReset, fetchCountryByDialCodePending, fetchCountryByDialCodeSucsess, fetchCountryByDialCodeError, fetchCountryByDialCodeReset } from "../redux/actions/CountryAction";
import { store } from "../redux/store";
2020-07-08 19:01:56 +00:00
import { activeCountryUrl, payCountryNetworkUrl, otherPayCountryNetworkUrl } from "./IlinkConstants";
2020-06-23 08:55:19 +00:00
export const getActiveCountryAction = () => {
const auth = store.getState().authKeyReducer;
const authKey = auth !== null ? `${auth.authKey.token_type} ${auth.authKey.access_token}` : '';
return dispatch => {
dispatch(fetchActiveCountryListPending());
axios({
url: `${activeCountryUrl}`,
method: 'GET',
headers: {
'Authorization': authKey,
'X-Localization': I18n.currentLocale()
}
})
.then(response => {
console.log(response);
dispatch(fetchActiveCountryListSucsess(response));
})
.catch(error => {
if (error.response)
dispatch(fetchActiveCountryListError(error.response));
else if (error.request)
dispatch(fetchActiveCountryListError(error.request))
else
dispatch(fetchActiveCountryListError(error.message))
});
}
}
export const getActiveCountryReset = () => {
return dispatch => {
dispatch(fetchActiveCountryListReset());
}
}
2020-07-02 14:35:00 +00:00
export const getPayCountryNetworkAction = (data) => {
2020-06-23 08:55:19 +00:00
const auth = store.getState().authKeyReducer;
const authKey = auth !== null ? `${auth.authKey.token_type} ${auth.authKey.access_token}` : '';
return dispatch => {
dispatch(fetchPayCountryNetworkPending());
axios({
2020-07-02 14:35:00 +00:00
url: `${payCountryNetworkUrl}`,
method: 'POST',
data,
2020-06-23 08:55:19 +00:00
headers: {
'Authorization': authKey,
'X-Localization': I18n.currentLocale()
2020-07-08 19:01:56 +00:00
}
})
.then(response => {
console.log(response);
dispatch(fetchPayCountryNetworkSucsess(response));
})
.catch(error => {
if (error.response)
dispatch(fetchPayCountryNetworkError(error.response));
else if (error.request)
dispatch(fetchPayCountryNetworkError(error.request))
else
dispatch(fetchPayCountryNetworkError(error.message))
});
}
}
export const getOtherPayCountryNetworkAction = (data) => {
const auth = store.getState().authKeyReducer;
const authKey = auth !== null ? `${auth.authKey.token_type} ${auth.authKey.access_token}` : '';
return dispatch => {
dispatch(fetchPayCountryNetworkPending());
axios({
url: `${otherPayCountryNetworkUrl}`,
method: 'POST',
data,
headers: {
'Authorization': authKey,
'X-Localization': I18n.currentLocale()
2020-06-23 08:55:19 +00:00
}
})
.then(response => {
console.log(response);
dispatch(fetchPayCountryNetworkSucsess(response));
})
.catch(error => {
if (error.response)
dispatch(fetchPayCountryNetworkError(error.response));
else if (error.request)
dispatch(fetchPayCountryNetworkError(error.request))
else
dispatch(fetchPayCountryNetworkError(error.message))
});
}
}
export const getPayCountryNetworkReset = () => {
return dispatch => {
dispatch(fetchPayCountryNetworkReset());
}
}
export const getActiveCountryByDialCodeAction = (countryDialCode) => {
const auth = store.getState().authKeyReducer;
const authKey = auth !== null ? `${auth.authKey.token_type} ${auth.authKey.access_token}` : '';
return dispatch => {
dispatch(fetchCountryByDialCodePending());
axios({
url: `${activeCountryUrlGET}/${countryDialCode}`,
method: 'GET',
headers: {
'Authorization': authKey,
'X-Localization': I18n.currentLocale()
}
})
.then(response => {
console.log(response);
dispatch(fetchCountryByDialCodeSucsess(response));
})
.catch(error => {
if (error.response)
dispatch(fetchCountryByDialCodeError(error.response));
else if (error.request)
dispatch(fetchCountryByDialCodeError(error.request))
else
dispatch(fetchCountryByDialCodeError(error.message))
});
}
}
export const getActiveCountryByDialCodeReset = () => {
return dispatch => {
dispatch(fetchCountryByDialCodeReset());
}
}