From 18d1dcbc09225c3be646810155daf97bb63d3d96 Mon Sep 17 00:00:00 2001 From: Rahim Rahman Date: Wed, 12 Aug 2020 09:10:48 -0600 Subject: [PATCH] [MM-18765] remove lifecycle methods from settings (#4596) --- .../radio_button/radio_button_group.js | 36 ++----------------- .../notification_settings.js | 6 ++-- .../notification_settings_email_base.js | 28 ++++++++------- 3 files changed, 22 insertions(+), 48 deletions(-) diff --git a/app/components/radio_button/radio_button_group.js b/app/components/radio_button/radio_button_group.js index 529793a6c..2c20e2d1e 100644 --- a/app/components/radio_button/radio_button_group.js +++ b/app/components/radio_button/radio_button_group.js @@ -17,41 +17,11 @@ export default class RadioButtonGroup extends PureComponent { options: [], }; - constructor(props) { - super(props); - - this.state = { - selected: this.getSelectedValue(props.options), - }; - } - - componentWillReceiveProps(nextProps) { - if (this.props.options !== nextProps.options) { - this.setState({selected: this.getSelectedValue(nextProps.options)}); - } - } - - getSelectedValue = (options = []) => { - let selected; - for (const option in options) { - if (option.checked) { - selected = option.value; - break; - } - } - - return selected; - } - onChange = (value) => { const {onSelect} = this.props; - this.setState({ - selected: value, - }, () => { - if (onSelect) { - onSelect(value); - } - }); + if (onSelect) { + onSelect(value); + } }; render = () => { diff --git a/app/screens/settings/notification_settings/notification_settings.js b/app/screens/settings/notification_settings/notification_settings.js index 827ae423c..05c238ba4 100644 --- a/app/screens/settings/notification_settings/notification_settings.js +++ b/app/screens/settings/notification_settings/notification_settings.js @@ -40,10 +40,10 @@ export default class NotificationSettings extends PureComponent { intl: intlShape.isRequired, }; - componentWillReceiveProps(nextProps) { - const {updateMeRequest} = nextProps; + componentDidUpdate(prevProps) { + const {updateMeRequest} = this.props; const {intl} = this.context; - if (this.props.updateMeRequest !== updateMeRequest && updateMeRequest.status === RequestStatus.FAILURE) { + if (prevProps.updateMeRequest.status !== updateMeRequest.status && updateMeRequest.status === RequestStatus.FAILURE) { Alert.alert( intl.formatMessage({ id: 'mobile.notification_settings.save_failed_title', 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 f6686a510..6f698117a 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 @@ -44,19 +44,29 @@ export default class NotificationSettingsEmailBase extends PureComponent { this.navigationEventListener = Navigation.events().bindComponent(this); } - componentWillReceiveProps(nextProps) { + componentDidDisappear() { + if (this.getPlatformOS() === 'ios') { + this.saveEmailNotifyProps(); + } + } + + componentDidUpdate(prevProps) { + this.setEmailIntervalIfNeeded(prevProps); + } + + setEmailIntervalIfNeeded = (prevProps) => { const { notifyProps, sendEmailNotifications, enableEmailBatching, emailInterval, - } = nextProps; + } = this.props; if ( - this.props.sendEmailNotifications !== sendEmailNotifications || - this.props.enableEmailBatching !== enableEmailBatching || - this.props.emailInterval !== emailInterval || - this.props.notifyProps?.email !== notifyProps?.email + sendEmailNotifications !== prevProps.sendEmailNotifications || + enableEmailBatching !== prevProps.enableEmailBatching || + emailInterval !== prevProps.emailInterval || + notifyProps?.email !== prevProps.notifyProps?.email ) { this.setState({ emailInterval, @@ -65,12 +75,6 @@ export default class NotificationSettingsEmailBase extends PureComponent { } } - componentDidDisappear() { - if (this.getPlatformOS() === 'ios') { - this.saveEmailNotifyProps(); - } - } - getPlatformOS = () => { return Platform.OS; }