-
Notifications
You must be signed in to change notification settings - Fork 3k
/
PreferencesPage.js
executable file
·125 lines (115 loc) · 4.86 KB
/
PreferencesPage.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
import _ from 'underscore';
import lodashGet from 'lodash/get';
import React from 'react';
import {View, ScrollView} from 'react-native';
import {withOnyx} from 'react-native-onyx';
import PropTypes from 'prop-types';
import HeaderWithCloseButton from '../../components/HeaderWithCloseButton';
import LocalePicker from '../../components/LocalePicker';
import Navigation from '../../libs/Navigation/Navigation';
import ROUTES from '../../ROUTES';
import ONYXKEYS from '../../ONYXKEYS';
import styles from '../../styles/styles';
import Text from '../../components/Text';
import CONST from '../../CONST';
import * as User from '../../libs/actions/User';
import ScreenWrapper from '../../components/ScreenWrapper';
import Switch from '../../components/Switch';
import withLocalize, {withLocalizePropTypes} from '../../components/withLocalize';
import compose from '../../libs/compose';
import Picker from '../../components/Picker';
import withEnvironment, {environmentPropTypes} from '../../components/withEnvironment';
import TestToolMenu from '../../components/TestToolMenu';
const propTypes = {
/** The chat priority mode */
priorityMode: PropTypes.string,
/** The details about the user that is signed in */
user: PropTypes.shape({
/** Whether or not the user is subscribed to news updates */
isSubscribedToNewsletter: PropTypes.bool,
shouldUseStagingServer: PropTypes.bool,
}),
...withLocalizePropTypes,
...environmentPropTypes,
};
const defaultProps = {
priorityMode: CONST.PRIORITY_MODE.DEFAULT,
user: {},
};
const PreferencesPage = (props) => {
const priorityModes = {
default: {
value: CONST.PRIORITY_MODE.DEFAULT,
label: props.translate('preferencesPage.mostRecent'),
description: props.translate('preferencesPage.mostRecentModeDescription'),
},
gsd: {
value: CONST.PRIORITY_MODE.GSD,
label: props.translate('preferencesPage.focus'),
description: props.translate('preferencesPage.focusModeDescription'),
},
};
return (
<ScreenWrapper>
<HeaderWithCloseButton
title={props.translate('common.preferences')}
shouldShowBackButton
onBackButtonPress={() => Navigation.navigate(ROUTES.SETTINGS)}
onCloseButtonPress={() => Navigation.dismissModal(true)}
/>
<ScrollView style={styles.flex1} contentContainerStyle={styles.p5}>
<View style={[styles.settingsPageBody, styles.mb6]}>
<Text style={[styles.formLabel]} numberOfLines={1}>
{props.translate('common.notifications')}
</Text>
<View style={[styles.flexRow, styles.mb6, styles.justifyContentBetween]}>
<View style={styles.flex4}>
<Text>
{props.translate('preferencesPage.receiveRelevantFeatureUpdatesAndExpensifyNews')}
</Text>
</View>
<View style={[styles.flex1, styles.alignItemsEnd]}>
<Switch
isOn={lodashGet(props.user, 'isSubscribedToNewsletter', true)}
onToggle={User.updateNewsletterSubscription}
/>
</View>
</View>
<View style={[styles.mb2, styles.w100]}>
<Picker
label={props.translate('preferencesPage.priorityMode')}
onInputChange={
mode => User.updateChatPriorityMode(mode)
}
items={_.values(priorityModes)}
value={props.priorityMode}
/>
</View>
<Text style={[styles.textLabel, styles.colorMuted, styles.mb6]}>
{priorityModes[props.priorityMode].description}
</Text>
<View style={[styles.mb2]}>
<LocalePicker />
</View>
{/* If we are in the staging environment then we enable additional test features */}
{_.contains([CONST.ENVIRONMENT.STAGING, CONST.ENVIRONMENT.DEV], props.environment) && <TestToolMenu />}
</View>
</ScrollView>
</ScreenWrapper>
);
};
PreferencesPage.propTypes = propTypes;
PreferencesPage.defaultProps = defaultProps;
PreferencesPage.displayName = 'PreferencesPage';
export default compose(
withEnvironment,
withLocalize,
withOnyx({
priorityMode: {
key: ONYXKEYS.NVP_PRIORITY_MODE,
},
user: {
key: ONYXKEYS.USER,
},
}),
)(PreferencesPage);