ilink-world/app/webservice/OnesignalApi.js

84 lines
3.0 KiB
JavaScript
Raw Normal View History

2020-08-11 09:42:31 +00:00
import axios from "axios";
import I18n from 'react-native-i18n';
import { store } from "../redux/store";
2020-08-24 19:18:19 +00:00
import { saveOnesignalIds, getNotificationUrl } from "./IlinkConstants";
2020-08-11 09:42:31 +00:00
import { fetchSaveOnesignalPlayerIdsPending, fetchSaveOnesignalPlayerIdsSuccess, fetchSaveOnesignalPlayerIdsError, fetchSaveOnesignalPlayerIdsReset } from "../redux/actions/NotificationAction";
2020-08-25 08:26:21 +00:00
import { fetchGetNotificationSuccess, fetchGetNotificationPending, fetchGetNotificationError } from "../redux/actions/NanoCreditAction";
2020-08-11 09:42:31 +00:00
export const saveOnesignalIdsAction = (isUser, data) => {
const auth = store.getState().authKeyReducer;
const authKey = auth !== null ? `${auth.authKey.token_type} ${auth.authKey.access_token}` : '';
return dispatch => {
dispatch(fetchSaveOnesignalPlayerIdsPending());
axios({
url: isUser ? `${saveOnesignalIds}/saveUser` : `${saveOnesignalIds}/saveAgent`,
method: 'POST',
data,
headers: {
'Authorization': authKey,
'X-Localization': I18n.currentLocale()
}
})
.then(response => {
console.log(response);
dispatch(fetchSaveOnesignalPlayerIdsSuccess(response));
})
.catch(error => {
if (error.response)
dispatch(fetchSaveOnesignalPlayerIdsError(error.response));
else if (error.request)
dispatch(fetchSaveOnesignalPlayerIdsError(error.request))
else
dispatch(fetchSaveOnesignalPlayerIdsError(error.message))
});
}
}
export const saveOnesignalIdsReset = () => {
return dispatch => {
dispatch(fetchSaveOnesignalPlayerIdsReset());
}
}
2020-08-24 19:18:19 +00:00
export const getNotificationAction = (data) => {
const auth = store.getState().authKeyReducer;
const authKey = auth !== null ? `${auth.authKey.token_type} ${auth.authKey.access_token}` : '';
return dispatch => {
dispatch(fetchGetNotificationPending());
axios({
url: getNotificationUrl,
method: 'POST',
data,
headers: {
'Authorization': authKey,
'X-Localization': I18n.currentLocale()
}
})
.then(response => {
console.log(response);
dispatch(fetchGetNotificationSuccess(response));
})
.catch(error => {
if (error.response)
dispatch(fetchGetNotificationError(error.response));
else if (error.request)
dispatch(fetchGetNotificationError(error.request))
else
dispatch(fetchGetNotificationError(error.message))
});
}
}
export const getNotificationReset = () => {
return dispatch => {
dispatch(fetchGetNotificationReset());
}
}