46 lines
1.7 KiB
JavaScript
46 lines
1.7 KiB
JavaScript
|
|
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());
|
|
}
|
|
} |