-
Notifications
You must be signed in to change notification settings - Fork 2.9k
/
AllSettingsScreen.tsx
129 lines (121 loc) · 4.97 KB
/
AllSettingsScreen.tsx
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
126
127
128
129
import React, {useMemo} from 'react';
import type {OnyxCollection} from 'react-native-onyx';
import {useOnyx, withOnyx} from 'react-native-onyx';
import Breadcrumbs from '@components/Breadcrumbs';
import * as Expensicons from '@components/Icon/Expensicons';
import MenuItemList from '@components/MenuItemList';
import ScreenWrapper from '@components/ScreenWrapper';
import ScrollView from '@components/ScrollView';
import useLocalize from '@hooks/useLocalize';
import useResponsiveLayout from '@hooks/useResponsiveLayout';
import useThemeStyles from '@hooks/useThemeStyles';
import useWaitForNavigation from '@hooks/useWaitForNavigation';
import Navigation from '@libs/Navigation/Navigation';
import {hasGlobalWorkspaceSettingsRBR} from '@libs/WorkspacesSettingsUtils';
import * as Link from '@userActions/Link';
import CONST from '@src/CONST';
import type {TranslationPaths} from '@src/languages/types';
import ONYXKEYS from '@src/ONYXKEYS';
import ROUTES from '@src/ROUTES';
import type {Policy} from '@src/types/onyx';
type AllSettingsScreenOnyxProps = {
policies: OnyxCollection<Policy>;
};
type AllSettingsScreenProps = AllSettingsScreenOnyxProps;
function AllSettingsScreen({policies}: AllSettingsScreenProps) {
const styles = useThemeStyles();
const waitForNavigate = useWaitForNavigation();
const {translate} = useLocalize();
const {shouldUseNarrowLayout} = useResponsiveLayout();
const [privateSubscription] = useOnyx(ONYXKEYS.NVP_PRIVATE_SUBSCRIPTION);
/**
* Retuns a list of menu items data for All workspaces settings
* @returns {Object} object with translationKey, style and items
*/
const menuItems = useMemo(() => {
const baseMenuItems = [
{
translationKey: 'common.workspaces',
icon: Expensicons.Building,
action: () => {
waitForNavigate(() => {
Navigation.navigate(ROUTES.SETTINGS_WORKSPACES);
})();
},
focused: !shouldUseNarrowLayout,
brickRoadIndicator: hasGlobalWorkspaceSettingsRBR(policies) ? CONST.BRICK_ROAD_INDICATOR_STATUS.ERROR : undefined,
},
...(privateSubscription
? [
{
translationKey: 'allSettingsScreen.subscription',
icon: Expensicons.MoneyBag,
action: () => {
Link.openOldDotLink(CONST.OLDDOT_URLS.ADMIN_POLICIES_URL);
},
shouldShowRightIcon: true,
iconRight: Expensicons.NewWindow,
link: () => Link.buildOldDotURL(CONST.OLDDOT_URLS.ADMIN_POLICIES_URL),
},
]
: []),
{
translationKey: 'allSettingsScreen.domains',
icon: Expensicons.Globe,
action: () => {
Link.openOldDotLink(CONST.OLDDOT_URLS.ADMIN_DOMAINS_URL);
},
shouldShowRightIcon: true,
iconRight: Expensicons.NewWindow,
link: () => Link.buildOldDotURL(CONST.OLDDOT_URLS.ADMIN_DOMAINS_URL),
},
];
return baseMenuItems.map((item) => ({
key: item.translationKey,
title: translate(item.translationKey as TranslationPaths),
icon: item.icon,
link: item.link,
iconRight: item.iconRight,
onPress: item.action,
shouldShowRightIcon: item.shouldShowRightIcon,
shouldBlockSelection: !!item.link,
wrapperStyle: styles.sectionMenuItem,
isPaneMenu: true,
focused: item.focused,
hoverAndPressStyle: styles.hoveredComponentBG,
brickRoadIndicator: item.brickRoadIndicator,
}));
}, [shouldUseNarrowLayout, policies, privateSubscription, waitForNavigate, translate, styles]);
return (
<ScreenWrapper
testID={AllSettingsScreen.displayName}
includePaddingTop={false}
includeSafeAreaPaddingBottom={false}
style={[styles.pb0]}
>
<Breadcrumbs
breadcrumbs={[
{
type: CONST.BREADCRUMB_TYPE.ROOT,
},
{
text: translate('common.settings'),
},
]}
style={[styles.mb5, styles.ph5]}
/>
<ScrollView style={[styles.pb4, styles.mh3]}>
<MenuItemList
menuItems={menuItems}
shouldUseSingleExecution
/>
</ScrollView>
</ScreenWrapper>
);
}
AllSettingsScreen.displayName = 'AllSettingsScreen';
export default withOnyx<AllSettingsScreenProps, AllSettingsScreenOnyxProps>({
policies: {
key: ONYXKEYS.COLLECTION.POLICY,
},
})(AllSettingsScreen);