-
Notifications
You must be signed in to change notification settings - Fork 2.9k
/
ConfirmDelegatePage.tsx
88 lines (78 loc) · 3.53 KB
/
ConfirmDelegatePage.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
import type {StackScreenProps} from '@react-navigation/stack';
import React, {useState} from 'react';
import type {ValueOf} from 'type-fest';
import Button from '@components/Button';
import HeaderPageLayout from '@components/HeaderPageLayout';
import {FallbackAvatar} from '@components/Icon/Expensicons';
import MenuItem from '@components/MenuItem';
import MenuItemWithTopDescription from '@components/MenuItemWithTopDescription';
import Text from '@components/Text';
import useLocalize from '@hooks/useLocalize';
import useNetwork from '@hooks/useNetwork';
import useThemeStyles from '@hooks/useThemeStyles';
import {formatPhoneNumber} from '@libs/LocalePhoneNumber';
import Navigation from '@libs/Navigation/Navigation';
import type {SettingsNavigatorParamList} from '@libs/Navigation/types';
import * as PersonalDetailsUtils from '@libs/PersonalDetailsUtils';
import CONST from '@src/CONST';
import ROUTES from '@src/ROUTES';
import type SCREENS from '@src/SCREENS';
import DelegateMagicCodeModal from './DelegateMagicCodeModal';
type ConfirmDelegatePageProps = StackScreenProps<SettingsNavigatorParamList, typeof SCREENS.SETTINGS.DELEGATE.DELEGATE_CONFIRM>;
function ConfirmDelegatePage({route}: ConfirmDelegatePageProps) {
const {translate} = useLocalize();
const styles = useThemeStyles();
const login = route.params.login;
const role = route.params.role as ValueOf<typeof CONST.DELEGATE_ROLE>;
const {isOffline} = useNetwork();
const [isValidateCodeActionModalVisible, setIsValidateCodeActionModalVisible] = useState(false);
const personalDetails = PersonalDetailsUtils.getPersonalDetailByEmail(login);
const avatarIcon = personalDetails?.avatar ?? FallbackAvatar;
const formattedLogin = formatPhoneNumber(login ?? '');
const displayName = personalDetails?.displayName ?? formattedLogin;
const submitButton = (
<Button
success
isDisabled={isOffline}
large
text={translate('delegate.addCopilot')}
style={styles.mt6}
pressOnEnter
onPress={() => setIsValidateCodeActionModalVisible(true)}
/>
);
return (
<HeaderPageLayout
onBackButtonPress={() => Navigation.goBack(ROUTES.SETTINGS_DELEGATE_ROLE.getRoute(login, role))}
title={translate('delegate.addCopilot')}
testID={ConfirmDelegatePage.displayName}
footer={submitButton}
childrenContainerStyles={[styles.pt3, styles.gap6]}
>
<Text style={[styles.ph5]}>{translate('delegate.confirmCopilot')}</Text>
<MenuItem
avatarID={personalDetails?.accountID ?? -1}
iconType={CONST.ICON_TYPE_AVATAR}
icon={avatarIcon}
title={displayName}
description={formattedLogin}
interactive={false}
/>
<MenuItemWithTopDescription
title={translate('delegate.role', {role})}
description={translate('delegate.accessLevel')}
helperText={translate('delegate.roleDescription', {role})}
onPress={() => Navigation.navigate(ROUTES.SETTINGS_DELEGATE_ROLE.getRoute(login, role))}
shouldShowRightIcon
/>
{isValidateCodeActionModalVisible && (
<DelegateMagicCodeModal
login={login}
role={role}
/>
)}
</HeaderPageLayout>
);
}
ConfirmDelegatePage.displayName = 'ConfirmDelegatePage';
export default ConfirmDelegatePage;