From 03308dac9fb7a119078b26f8e52119dbdba8958a Mon Sep 17 00:00:00 2001 From: Emre YILMAZ Date: Fri, 30 Nov 2018 17:25:23 +0300 Subject: [PATCH] Added set push token feature after settings changed --- .../container/applicationContainer.js | 1 - .../settings/container/settingsContainer.js | 28 +++++++++++++++++-- 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/src/screens/application/container/applicationContainer.js b/src/screens/application/container/applicationContainer.js index 50ee4716b..48b22563d 100644 --- a/src/screens/application/container/applicationContainer.js +++ b/src/screens/application/container/applicationContainer.js @@ -4,7 +4,6 @@ import { connect } from 'react-redux'; import { addLocaleData } from 'react-intl'; import Config from 'react-native-config'; import AppCenter from 'appcenter'; -import Push from 'appcenter-push'; // Constants import en from 'react-intl/locale-data/en'; diff --git a/src/screens/settings/container/settingsContainer.js b/src/screens/settings/container/settingsContainer.js index f9d065979..e65deee84 100644 --- a/src/screens/settings/container/settingsContainer.js +++ b/src/screens/settings/container/settingsContainer.js @@ -1,5 +1,7 @@ import React, { Component } from 'react'; +import { AsyncStorage, Platform } from 'react-native'; import { connect } from 'react-redux'; +import AppCenter from 'appcenter'; // Realm import { @@ -18,12 +20,15 @@ import { setApi, isDarkTheme, } from '../../../redux/actions/applicationActions'; +import { setPushToken } from '../../../providers/esteem/esteem'; + // Middleware // Constants import { VALUE as CURRENCY_VALUE } from '../../../constants/options/currency'; import { VALUE as LANGUAGE_VALUE } from '../../../constants/options/language'; import API_VALUE from '../../../constants/options/api'; +import INITIAL from '../../../constants/initial'; // Utilities @@ -89,8 +94,6 @@ class SettingsContainer extends Component { }; _handleOnChange = (action, type, actionType = null) => { - const { dispatch, navigation } = this.props; - switch (type) { case 'dropdown': this._handleDropdownSelected(action, actionType); @@ -109,6 +112,24 @@ class SettingsContainer extends Component { } }; + _setPushToken = async () => { + const { notificationSettings, isLoggedIn, username } = this.props; + if (isLoggedIn) { + const token = await AppCenter.getInstallId(); + AsyncStorage.getItem(INITIAL.IS_EXIST_USER, (err, result) => { + if (JSON.parse(result)) { + const data = { + username, + token, + system: Platform.OS, + allows_notify: notificationSettings, + }; + setPushToken(data); + } + }); + } + }; + render() { return ; } @@ -120,5 +141,8 @@ const mapStateToProps = state => ({ selectedCurrency: state.application.currency, isNotificationOpen: state.application.isNotificationOpen, isDarkTheme: state.application.isDarkTheme, + notificationSettings: state.application.isNotificationOpen, + isLoggedIn: state.application.isLoggedIn, + username: state.account.currentAccount && state.account.currentAccount.name, }); export default connect(mapStateToProps)(SettingsContainer);