From 1ed9ace71ad9929c25b8259a62850040dda06e32 Mon Sep 17 00:00:00 2001 From: Djorkaeff Alexandre Date: Fri, 6 Nov 2020 11:26:43 -0300 Subject: [PATCH] [FIX] User notification preferences throwing an error when select default Email option (#2615) Co-authored-by: Diego Mello --- app/views/UserNotificationPreferencesView/index.js | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/app/views/UserNotificationPreferencesView/index.js b/app/views/UserNotificationPreferencesView/index.js index 085fbe8a..e05bb534 100644 --- a/app/views/UserNotificationPreferencesView/index.js +++ b/app/views/UserNotificationPreferencesView/index.js @@ -51,7 +51,7 @@ class UserNotificationPreferencesView extends React.Component { this.setState({ preferences, loading: true }); } - findOption = (key) => { + findDefaultOption = (key) => { const { preferences } = this.state; const option = preferences[key] ? OPTIONS[key].find(item => item.value === preferences[key]) : OPTIONS[key][0]; return option; @@ -59,7 +59,7 @@ class UserNotificationPreferencesView extends React.Component { renderPickerOption = (key) => { const { theme } = this.props; - const text = this.findOption(key); + const text = this.findDefaultOption(key); return {I18n.t(text?.label, { defaultValue: text?.label, second: text?.second })}; } @@ -67,14 +67,17 @@ class UserNotificationPreferencesView extends React.Component { const { preferences } = this.state; const { navigation } = this.props; let values = OPTIONS[key]; + + const defaultOption = this.findDefaultOption(key); if (OPTIONS[key][0]?.value !== 'default') { - values = [{ label: `${ I18n.t('Default') } (${ I18n.t(this.findOption(key).label) })`, value: preferences[key]?.value }, ...OPTIONS[key]]; + values = [{ label: `${ I18n.t('Default') } (${ I18n.t(defaultOption.label) })` }, ...OPTIONS[key]]; } + navigation.navigate('PickerView', { title, data: values, value: preferences[key], - onChangeValue: value => this.onValueChangePicker(key, value) + onChangeValue: value => this.onValueChangePicker(key, value ?? defaultOption.value) }); }