ilink-world/webservice/IdentificationApi.js

46 lines
1.7 KiB
JavaScript
Raw Normal View History

2020-06-12 11:13:59 +00:00
import { createIdentificationUrl } from "./IlinkConstants";
import { store } from "../redux/store";
import axios from "axios";
import I18n from 'react-native-i18n'
import { fetchCreateIdentificationReset, fetchCreateIdentificationSuccess, fetchCreateIdentificationError, fetchCreateIdentificationPending } from "../redux/actions/IdentificationAction";
export const createIndentificationAction = (data) => {
const auth = store.getState().authKeyReducer;
const authKey = auth !== null ? `${auth.authKey.token_type} ${auth.authKey.access_token}` : '';
return dispatch => {
dispatch(fetchCreateIdentificationPending());
axios({
url: `${createIdentificationUrl}`,
method: 'POST',
headers: {
'Authorization': authKey,
'X-Localization': I18n.currentLocale()
},
data
})
.then(response => {
console.log(response);
dispatch(fetchCreateIdentificationSuccess(response));
})
.catch(error => {
console.log(error);
//dispatch(fetchCreateIdentificationError(error.message));
if (error.response)
dispatch(fetchCreateIdentificationError(error.response));
else if (error.request)
dispatch(fetchCreateIdentificationError(error.request))
else
dispatch(fetchCreateIdentificationError(error.message))
});
}
}
export const createIndentificationResetAction = () => {
return dispatch => {
dispatch(fetchCreateIdentificationReset());
}
}