[FIX] User notification preferences throwing an error when select default Email option (#2615)
Co-authored-by: Diego Mello <diegolmello@gmail.com>
This commit is contained in:
parent
5673595a9b
commit
1ed9ace71a
|
@ -51,7 +51,7 @@ class UserNotificationPreferencesView extends React.Component {
|
||||||
this.setState({ preferences, loading: true });
|
this.setState({ preferences, loading: true });
|
||||||
}
|
}
|
||||||
|
|
||||||
findOption = (key) => {
|
findDefaultOption = (key) => {
|
||||||
const { preferences } = this.state;
|
const { preferences } = this.state;
|
||||||
const option = preferences[key] ? OPTIONS[key].find(item => item.value === preferences[key]) : OPTIONS[key][0];
|
const option = preferences[key] ? OPTIONS[key].find(item => item.value === preferences[key]) : OPTIONS[key][0];
|
||||||
return option;
|
return option;
|
||||||
|
@ -59,7 +59,7 @@ class UserNotificationPreferencesView extends React.Component {
|
||||||
|
|
||||||
renderPickerOption = (key) => {
|
renderPickerOption = (key) => {
|
||||||
const { theme } = this.props;
|
const { theme } = this.props;
|
||||||
const text = this.findOption(key);
|
const text = this.findDefaultOption(key);
|
||||||
return <Text style={[styles.pickerText, { color: themes[theme].actionTintColor }]}>{I18n.t(text?.label, { defaultValue: text?.label, second: text?.second })}</Text>;
|
return <Text style={[styles.pickerText, { color: themes[theme].actionTintColor }]}>{I18n.t(text?.label, { defaultValue: text?.label, second: text?.second })}</Text>;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -67,14 +67,17 @@ class UserNotificationPreferencesView extends React.Component {
|
||||||
const { preferences } = this.state;
|
const { preferences } = this.state;
|
||||||
const { navigation } = this.props;
|
const { navigation } = this.props;
|
||||||
let values = OPTIONS[key];
|
let values = OPTIONS[key];
|
||||||
|
|
||||||
|
const defaultOption = this.findDefaultOption(key);
|
||||||
if (OPTIONS[key][0]?.value !== 'default') {
|
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', {
|
navigation.navigate('PickerView', {
|
||||||
title,
|
title,
|
||||||
data: values,
|
data: values,
|
||||||
value: preferences[key],
|
value: preferences[key],
|
||||||
onChangeValue: value => this.onValueChangePicker(key, value)
|
onChangeValue: value => this.onValueChangePicker(key, value ?? defaultOption.value)
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue