Skip to content

Commit e94f05d

Browse files
authored
Merge pull request Expensify#78785 from ChavdaSachin/copilot/align-security-features-access-with-OD
Copilot/align security features access with OldDot
2 parents e148704 + 8344f31 commit e94f05d

3 files changed

Lines changed: 95 additions & 122 deletions

File tree

src/pages/settings/Security/CloseAccountPage.tsx

Lines changed: 56 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import {Str} from 'expensify-common';
22
import React, {useEffect, useState} from 'react';
33
import {View} from 'react-native';
44
import ConfirmModal from '@components/ConfirmModal';
5-
import DelegateNoAccessWrapper from '@components/DelegateNoAccessWrapper';
65
import FormProvider from '@components/Form/FormProvider';
76
import InputWrapper from '@components/Form/InputWrapper';
87
import type {FormInputErrors, FormOnyxValues} from '@components/Form/types';
@@ -90,65 +89,63 @@ function CloseAccountPage() {
9089
includeSafeAreaPaddingBottom
9190
testID="CloseAccountPage"
9291
>
93-
<DelegateNoAccessWrapper accessDeniedVariants={[CONST.DELEGATE.DENIED_ACCESS_VARIANTS.SUBMITTER]}>
94-
<HeaderWithBackButton
95-
title={translate('closeAccountPage.closeAccount')}
96-
onBackButtonPress={() => Navigation.goBack()}
97-
/>
98-
<FormProvider
99-
formID={ONYXKEYS.FORMS.CLOSE_ACCOUNT_FORM}
100-
validate={validate}
101-
onSubmit={showConfirmModal}
102-
submitButtonText={translate('closeAccountPage.closeAccount')}
103-
style={[styles.flexGrow1, styles.mh5]}
104-
isSubmitActionDangerous
92+
<HeaderWithBackButton
93+
title={translate('closeAccountPage.closeAccount')}
94+
onBackButtonPress={() => Navigation.goBack()}
95+
/>
96+
<FormProvider
97+
formID={ONYXKEYS.FORMS.CLOSE_ACCOUNT_FORM}
98+
validate={validate}
99+
onSubmit={showConfirmModal}
100+
submitButtonText={translate('closeAccountPage.closeAccount')}
101+
style={[styles.flexGrow1, styles.mh5]}
102+
isSubmitActionDangerous
103+
>
104+
<View
105+
fsClass={CONST.FULLSTORY.CLASS.UNMASK}
106+
style={[styles.flexGrow1]}
105107
>
106-
<View
107-
fsClass={CONST.FULLSTORY.CLASS.UNMASK}
108-
style={[styles.flexGrow1]}
109-
>
110-
<Text>{translate('closeAccountPage.reasonForLeavingPrompt')}</Text>
111-
<InputWrapper
112-
InputComponent={TextInput}
113-
inputID={INPUT_IDS.REASON_FOR_LEAVING}
114-
autoGrowHeight
115-
maxAutoGrowHeight={variables.textInputAutoGrowMaxHeight}
116-
label={translate('closeAccountPage.enterMessageHere')}
117-
aria-label={translate('closeAccountPage.enterMessageHere')}
118-
role={CONST.ROLE.PRESENTATION}
119-
containerStyles={[styles.mt5]}
120-
forwardedFSClass={CONST.FULLSTORY.CLASS.UNMASK}
121-
/>
122-
<Text style={[styles.mt5]}>
123-
{translate('closeAccountPage.enterDefaultContactToConfirm')} <Text style={[styles.textStrong]}>{userEmailOrPhone}</Text>
124-
</Text>
125-
<InputWrapper
126-
InputComponent={TextInput}
127-
inputID={INPUT_IDS.PHONE_OR_EMAIL}
128-
autoCapitalize="none"
129-
label={translate('closeAccountPage.enterDefaultContact')}
130-
aria-label={translate('closeAccountPage.enterDefaultContact')}
131-
role={CONST.ROLE.PRESENTATION}
132-
containerStyles={[styles.mt5]}
133-
autoCorrect={false}
134-
inputMode={userEmailOrPhone && Str.isValidEmail(userEmailOrPhone) ? CONST.INPUT_MODE.EMAIL : CONST.INPUT_MODE.TEXT}
135-
forwardedFSClass={CONST.FULLSTORY.CLASS.UNMASK}
136-
/>
137-
<ConfirmModal
138-
danger
139-
title={translate('closeAccountPage.closeAccountWarning')}
140-
onConfirm={onConfirm}
141-
onCancel={hideConfirmModal}
142-
isVisible={isConfirmModalVisible}
143-
prompt={translate('closeAccountPage.closeAccountPermanentlyDeleteData')}
144-
confirmText={translate('common.yesContinue')}
145-
cancelText={translate('common.cancel')}
146-
shouldDisableConfirmButtonWhenOffline
147-
shouldShowCancelButton
148-
/>
149-
</View>
150-
</FormProvider>
151-
</DelegateNoAccessWrapper>
108+
<Text>{translate('closeAccountPage.reasonForLeavingPrompt')}</Text>
109+
<InputWrapper
110+
InputComponent={TextInput}
111+
inputID={INPUT_IDS.REASON_FOR_LEAVING}
112+
autoGrowHeight
113+
maxAutoGrowHeight={variables.textInputAutoGrowMaxHeight}
114+
label={translate('closeAccountPage.enterMessageHere')}
115+
aria-label={translate('closeAccountPage.enterMessageHere')}
116+
role={CONST.ROLE.PRESENTATION}
117+
containerStyles={[styles.mt5]}
118+
forwardedFSClass={CONST.FULLSTORY.CLASS.UNMASK}
119+
/>
120+
<Text style={[styles.mt5]}>
121+
{translate('closeAccountPage.enterDefaultContactToConfirm')} <Text style={[styles.textStrong]}>{userEmailOrPhone}</Text>
122+
</Text>
123+
<InputWrapper
124+
InputComponent={TextInput}
125+
inputID={INPUT_IDS.PHONE_OR_EMAIL}
126+
autoCapitalize="none"
127+
label={translate('closeAccountPage.enterDefaultContact')}
128+
aria-label={translate('closeAccountPage.enterDefaultContact')}
129+
role={CONST.ROLE.PRESENTATION}
130+
containerStyles={[styles.mt5]}
131+
autoCorrect={false}
132+
inputMode={userEmailOrPhone && Str.isValidEmail(userEmailOrPhone) ? CONST.INPUT_MODE.EMAIL : CONST.INPUT_MODE.TEXT}
133+
forwardedFSClass={CONST.FULLSTORY.CLASS.UNMASK}
134+
/>
135+
<ConfirmModal
136+
danger
137+
title={translate('closeAccountPage.closeAccountWarning')}
138+
onConfirm={onConfirm}
139+
onCancel={hideConfirmModal}
140+
isVisible={isConfirmModalVisible}
141+
prompt={translate('closeAccountPage.closeAccountPermanentlyDeleteData')}
142+
confirmText={translate('common.yesContinue')}
143+
cancelText={translate('common.cancel')}
144+
shouldDisableConfirmButtonWhenOffline
145+
shouldShowCancelButton
146+
/>
147+
</View>
148+
</FormProvider>
152149
</ScreenWrapper>
153150
);
154151
}

src/pages/settings/Security/SecuritySettingsPage.tsx

Lines changed: 24 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ function SecuritySettingsPage() {
130130
translationKey: 'twoFactorAuth.headerTitle',
131131
icon: icons.Shield,
132132
action: () => {
133-
if (isDelegateAccessRestricted) {
133+
if (isActingAsDelegate) {
134134
showDelegateNoAccessModal();
135135
return;
136136
}
@@ -149,10 +149,6 @@ function SecuritySettingsPage() {
149149
translationKey: 'mergeAccountsPage.mergeAccount',
150150
icon: icons.ArrowCollapse,
151151
action: () => {
152-
if (isDelegateAccessRestricted) {
153-
showDelegateNoAccessModal();
154-
return;
155-
}
156152
if (isAccountLocked) {
157153
showLockedAccountModal();
158154
return;
@@ -187,11 +183,6 @@ function SecuritySettingsPage() {
187183
translationKey: 'closeAccountPage.closeAccount',
188184
icon: Expensicons.ClosedSign,
189185
action: () => {
190-
if (isDelegateAccessRestricted) {
191-
showDelegateNoAccessModal();
192-
return;
193-
}
194-
195186
if (isAccountLocked) {
196187
showLockedAccountModal();
197188
return;
@@ -301,7 +292,7 @@ function SecuritySettingsPage() {
301292
text: translate('delegate.changeAccessLevel'),
302293
icon: icons.Pencil,
303294
onPress: () => {
304-
if (isDelegateAccessRestricted) {
295+
if (isActingAsDelegate) {
305296
modalClose(() => showDelegateNoAccessModal());
306297
return;
307298
}
@@ -319,7 +310,7 @@ function SecuritySettingsPage() {
319310
text: translate('delegate.removeCopilot'),
320311
icon: Expensicons.Trashcan,
321312
onPress: () => {
322-
if (isActingAsDelegate) {
313+
if (selectedDelegate?.email !== account?.delegatedAccess?.delegate && isActingAsDelegate) {
323314
modalClose(() => showDelegateNoAccessModal());
324315
return;
325316
}
@@ -402,25 +393,27 @@ function SecuritySettingsPage() {
402393
<MenuItemList menuItems={delegateMenuItems} />
403394
</>
404395
)}
405-
{!isDelegateAccessRestricted && (
406-
<MenuItem
407-
title={translate('delegate.addCopilot')}
408-
icon={icons.UserPlus}
409-
onPress={() => {
410-
if (!isUserValidated) {
411-
Navigation.navigate(ROUTES.SETTINGS_DELEGATE_VERIFY_ACCOUNT);
412-
return;
413-
}
414-
if (isAccountLocked) {
415-
showLockedAccountModal();
416-
return;
417-
}
418-
Navigation.navigate(ROUTES.SETTINGS_ADD_DELEGATE);
419-
}}
420-
shouldShowRightIcon
421-
wrapperStyle={[styles.sectionMenuItemTopDescription, hasDelegators && styles.mb6]}
422-
/>
423-
)}
396+
<MenuItem
397+
title={translate('delegate.addCopilot')}
398+
icon={icons.UserPlus}
399+
onPress={() => {
400+
if (isActingAsDelegate) {
401+
modalClose(() => showDelegateNoAccessModal());
402+
return;
403+
}
404+
if (!isUserValidated) {
405+
Navigation.navigate(ROUTES.SETTINGS_DELEGATE_VERIFY_ACCOUNT);
406+
return;
407+
}
408+
if (isAccountLocked) {
409+
showLockedAccountModal();
410+
return;
411+
}
412+
Navigation.navigate(ROUTES.SETTINGS_ADD_DELEGATE);
413+
}}
414+
shouldShowRightIcon
415+
wrapperStyle={[styles.sectionMenuItemTopDescription, hasDelegators && styles.mb6]}
416+
/>
424417
{hasDelegators && (
425418
<>
426419
<Text style={[styles.textLabelSupporting, styles.pv1]}>{translate('delegate.youCanAccessTheseAccounts')}</Text>
@@ -452,11 +445,6 @@ function SecuritySettingsPage() {
452445
prompt={translate('delegate.removeCopilotConfirmation')}
453446
danger
454447
onConfirm={() => {
455-
if (isActingAsDelegate) {
456-
setShouldShowRemoveDelegateModal(false);
457-
showDelegateNoAccessModal();
458-
return;
459-
}
460448
removeDelegate({email: selectedDelegate?.email ?? '', delegatedAccess: account?.delegatedAccess});
461449
setShouldShowRemoveDelegateModal(false);
462450
setSelectedDelegate(undefined);

src/pages/settings/Security/TwoFactorAuth/TwoFactorAuthWrapper.tsx

Lines changed: 15 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
import React, {useContext, useMemo} from 'react';
1+
import React, {useMemo} from 'react';
22
import type {ValueOf} from 'type-fest';
33
import FullPageNotFoundView from '@components/BlockingViews/FullPageNotFoundView';
44
import FullPageOfflineBlockingView from '@components/BlockingViews/FullPageOfflineBlockingView';
5-
import {DelegateNoAccessContext} from '@components/DelegateNoAccessModalProvider';
65
import DelegateNoAccessWrapper from '@components/DelegateNoAccessWrapper';
76
import HeaderWithBackButton from '@components/HeaderWithBackButton';
87
import ScreenWrapper from '@components/ScreenWrapper';
@@ -45,7 +44,6 @@ function TwoFactorAuthWrapper({
4544
children,
4645
}: TwoFactorAuthWrapperProps) {
4746
const [account] = useOnyx(ONYXKEYS.ACCOUNT, {canBeMissing: false});
48-
const {isDelegateAccessRestricted} = useContext(DelegateNoAccessContext);
4947

5048
// eslint-disable-next-line rulesdir/no-negated-variables
5149
const shouldShowNotFound = useMemo(() => {
@@ -73,18 +71,6 @@ function TwoFactorAuthWrapper({
7371

7472
const viewportOffsetTop = useViewportOffsetTop();
7573

76-
if (isDelegateAccessRestricted) {
77-
return (
78-
<ScreenWrapper
79-
testID="TwoFactorAuthWrapper"
80-
includeSafeAreaPaddingBottom={false}
81-
shouldEnablePickerAvoiding={false}
82-
>
83-
<DelegateNoAccessWrapper accessDeniedVariants={[CONST.DELEGATE.DENIED_ACCESS_VARIANTS.DELEGATE]} />
84-
</ScreenWrapper>
85-
);
86-
}
87-
8874
const defaultGoBack = () => quitAndNavigateBack(ROUTES.SETTINGS_SECURITY);
8975

9076
return (
@@ -95,18 +81,20 @@ function TwoFactorAuthWrapper({
9581
testID={stepName}
9682
style={shouldEnableViewportOffsetTop ? {marginTop: viewportOffsetTop} : undefined}
9783
>
98-
<FullPageNotFoundView
99-
shouldShow={shouldShowNotFound}
100-
linkTranslationKey="securityPage.goToSecurity"
101-
onLinkPress={defaultGoBack}
102-
>
103-
<HeaderWithBackButton
104-
title={title}
105-
stepCounter={stepCounter}
106-
onBackButtonPress={onBackButtonPress ?? defaultGoBack}
107-
/>
108-
<FullPageOfflineBlockingView>{children}</FullPageOfflineBlockingView>
109-
</FullPageNotFoundView>
84+
<DelegateNoAccessWrapper accessDeniedVariants={[CONST.DELEGATE.DENIED_ACCESS_VARIANTS.DELEGATE]}>
85+
<FullPageNotFoundView
86+
shouldShow={shouldShowNotFound}
87+
linkTranslationKey="securityPage.goToSecurity"
88+
onLinkPress={defaultGoBack}
89+
>
90+
<HeaderWithBackButton
91+
title={title}
92+
stepCounter={stepCounter}
93+
onBackButtonPress={onBackButtonPress ?? defaultGoBack}
94+
/>
95+
<FullPageOfflineBlockingView>{children}</FullPageOfflineBlockingView>
96+
</FullPageNotFoundView>
97+
</DelegateNoAccessWrapper>
11098
</ScreenWrapper>
11199
);
112100
}

0 commit comments

Comments
 (0)