import axios from "axios"; import I18n from 'react-native-i18n'; import { fetchCreateGroupError, fetchCreateGroupPending, fetchCreateGroupReset, fetchCreateGroupSuccess } from "../redux/actions/NanoCreditAction"; import { store } from "../redux/store"; import { groupUrl } from "./IlinkConstants"; export const createGroupAction = (data) => { 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: 'POST', 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()); } }