diff --git a/app/components/radio_button/radio_button_group.js b/app/components/radio_button/radio_button_group.js index 85b003cde..529793a6c 100644 --- a/app/components/radio_button/radio_button_group.js +++ b/app/components/radio_button/radio_button_group.js @@ -70,7 +70,6 @@ export default class RadioButtonGroup extends PureComponent { return ( { - const {currentUser, intl} = this.props; + const {intl} = this.props; const screen = 'NotificationSettingsEmail'; const title = intl.formatMessage({ id: 'mobile.notification_settings.email_title', defaultMessage: 'Email Notifications', }); - const passProps = { - currentUser, - }; - goToScreen(screen, title, passProps); + goToScreen(screen, title); }; goToNotificationSettingsMentions = () => { diff --git a/app/screens/settings/notification_settings_email/index.js b/app/screens/settings/notification_settings_email/index.js index 2debe732c..37658a7cf 100644 --- a/app/screens/settings/notification_settings_email/index.js +++ b/app/screens/settings/notification_settings_email/index.js @@ -9,15 +9,22 @@ import {Preferences} from 'mattermost-redux/constants'; import {savePreferences} from 'mattermost-redux/actions/preferences'; import {updateMe} from 'mattermost-redux/actions/users'; +import {getCurrentUser} from 'mattermost-redux/selectors/entities/users'; import {getConfig} from 'mattermost-redux/selectors/entities/general'; import { get as getPreference, getTheme, } from 'mattermost-redux/selectors/entities/preferences'; + import {isLandscape} from 'app/selectors/device'; +import {getNotificationProps} from 'app/utils/notify_props'; + import NotificationSettingsEmail from './notification_settings_email'; function mapStateToProps(state) { + const currentUser = getCurrentUser(state) || {}; + const notifyProps = getNotificationProps(currentUser); + const config = getConfig(state); const sendEmailNotifications = config.SendEmailNotifications === 'true'; const enableEmailBatching = config.EnableEmailBatching === 'true'; @@ -29,6 +36,8 @@ function mapStateToProps(state) { ); return { + currentUser, + notifyProps, enableEmailBatching, emailInterval, sendEmailNotifications, diff --git a/app/screens/settings/notification_settings_email/notification_settings_email.android.test.js b/app/screens/settings/notification_settings_email/notification_settings_email.android.test.js index dc797176d..25cf7509d 100644 --- a/app/screens/settings/notification_settings_email/notification_settings_email.android.test.js +++ b/app/screens/settings/notification_settings_email/notification_settings_email.android.test.js @@ -20,6 +20,9 @@ jest.mock('Platform', () => { describe('NotificationSettingsEmailAndroid', () => { const baseProps = { currentUser: {id: 'current_user_id'}, + notifyProps: { + email: 'true', + }, emailInterval: '30', enableEmailBatching: false, actions: { diff --git a/app/screens/settings/notification_settings_email/notification_settings_email.ios.test.js b/app/screens/settings/notification_settings_email/notification_settings_email.ios.test.js index 1fd757a61..07d7613cd 100644 --- a/app/screens/settings/notification_settings_email/notification_settings_email.ios.test.js +++ b/app/screens/settings/notification_settings_email/notification_settings_email.ios.test.js @@ -27,6 +27,9 @@ jest.mock('app/utils/theme', () => { describe('NotificationSettingsEmailIos', () => { const baseProps = { currentUser: {id: 'current_user_id'}, + notifyProps: { + email: 'true', + }, emailInterval: '30', enableEmailBatching: false, actions: { diff --git a/app/screens/settings/notification_settings_email/notification_settings_email_base.js b/app/screens/settings/notification_settings_email/notification_settings_email_base.js index 60f56ab8c..feebf7e7c 100644 --- a/app/screens/settings/notification_settings_email/notification_settings_email_base.js +++ b/app/screens/settings/notification_settings_email/notification_settings_email_base.js @@ -9,7 +9,6 @@ import {Navigation} from 'react-native-navigation'; import {Preferences} from 'mattermost-redux/constants'; import {getEmailInterval} from 'mattermost-redux/utils/notify_props'; -import {getNotificationProps} from 'app/utils/notify_props'; import {setNavigatorStyles} from 'app/utils/theme'; export default class NotificationSettingsEmailBase extends PureComponent { @@ -20,6 +19,7 @@ export default class NotificationSettingsEmailBase extends PureComponent { }), componentId: PropTypes.string, currentUser: PropTypes.object.isRequired, + notifyProps: PropTypes.object.isRequired, emailInterval: PropTypes.string.isRequired, enableEmailBatching: PropTypes.bool.isRequired, sendEmailNotifications: PropTypes.bool.isRequired, @@ -31,14 +31,12 @@ export default class NotificationSettingsEmailBase extends PureComponent { super(props); const { - currentUser, + notifyProps, emailInterval, enableEmailBatching, sendEmailNotifications, } = props; - const notifyProps = getNotificationProps(currentUser); - this.state = { emailInterval, newInterval: this.computeEmailInterval(notifyProps?.email === 'true' && sendEmailNotifications, enableEmailBatching, emailInterval), @@ -56,7 +54,7 @@ export default class NotificationSettingsEmailBase extends PureComponent { } const { - currentUser, + notifyProps, sendEmailNotifications, enableEmailBatching, emailInterval, @@ -65,10 +63,9 @@ export default class NotificationSettingsEmailBase extends PureComponent { if ( this.props.sendEmailNotifications !== sendEmailNotifications || this.props.enableEmailBatching !== enableEmailBatching || - this.props.emailInterval !== emailInterval + this.props.emailInterval !== emailInterval || + this.props.notifyProps?.email !== notifyProps?.email ) { - const notifyProps = getNotificationProps(currentUser); - this.setState({ emailInterval, newInterval: this.computeEmailInterval(notifyProps?.email === 'true' && sendEmailNotifications, enableEmailBatching, emailInterval), @@ -93,6 +90,7 @@ export default class NotificationSettingsEmailBase extends PureComponent { const { actions, currentUser, + notifyProps, sendEmailNotifications, } = this.props; @@ -101,7 +99,6 @@ export default class NotificationSettingsEmailBase extends PureComponent { email = 'true'; } - const notifyProps = getNotificationProps(currentUser); actions.updateMe({notify_props: {...notifyProps, email}}); const emailIntervalPreference = {category: Preferences.CATEGORY_NOTIFICATIONS, user_id: currentUser.id, name: Preferences.EMAIL_INTERVAL, value: newInterval}; diff --git a/app/screens/settings/notification_settings_mobile/notification_settings_mobile.android.js b/app/screens/settings/notification_settings_mobile/notification_settings_mobile.android.js index bda1c76b0..cc45dca1d 100644 --- a/app/screens/settings/notification_settings_mobile/notification_settings_mobile.android.js +++ b/app/screens/settings/notification_settings_mobile/notification_settings_mobile.android.js @@ -370,11 +370,11 @@ class NotificationSettingsMobileAndroid extends NotificationSettingsMobileBase { ); } - componentWillReceiveProps(nextProps) { - super.componentWillReceiveProps(nextProps); + componentDidUpdate(prevProps) { + super.componentDidUpdate(prevProps); - const {updateMeRequest, intl} = nextProps; - if (this.props.updateMeRequest !== updateMeRequest && updateMeRequest.status === RequestStatus.FAILURE) { + const {updateMeRequest, intl} = this.props; + if (updateMeRequest !== prevProps.updateMeRequest && updateMeRequest.status === RequestStatus.FAILURE) { Alert.alert( intl.formatMessage({ id: 'mobile.notification_settings.save_failed_title',