Skip to content
Draft
115 changes: 56 additions & 59 deletions src/pages/settings/Security/CloseAccountPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import {Str} from 'expensify-common';
import React, {useEffect, useState} from 'react';
import {View} from 'react-native';
import ConfirmModal from '@components/ConfirmModal';
import DelegateNoAccessWrapper from '@components/DelegateNoAccessWrapper';
import FormProvider from '@components/Form/FormProvider';
import InputWrapper from '@components/Form/InputWrapper';
import type {FormInputErrors, FormOnyxValues} from '@components/Form/types';
Expand Down Expand Up @@ -97,65 +96,63 @@ function CloseAccountPage() {
includeSafeAreaPaddingBottom
testID="CloseAccountPage"
>
<DelegateNoAccessWrapper accessDeniedVariants={[CONST.DELEGATE.DENIED_ACCESS_VARIANTS.SUBMITTER]}>
<HeaderWithBackButton
title={translate('closeAccountPage.closeAccount')}
onBackButtonPress={() => Navigation.goBack()}
/>
<FormProvider
formID={ONYXKEYS.FORMS.CLOSE_ACCOUNT_FORM}
validate={validate}
onSubmit={showConfirmModal}
submitButtonText={translate('closeAccountPage.closeAccount')}
style={[styles.flexGrow1, styles.mh5]}
isSubmitActionDangerous
<HeaderWithBackButton
title={translate('closeAccountPage.closeAccount')}
onBackButtonPress={() => Navigation.goBack()}
/>
<FormProvider
formID={ONYXKEYS.FORMS.CLOSE_ACCOUNT_FORM}
validate={validate}
onSubmit={showConfirmModal}
submitButtonText={translate('closeAccountPage.closeAccount')}
style={[styles.flexGrow1, styles.mh5]}
isSubmitActionDangerous
>
<View
fsClass={CONST.FULLSTORY.CLASS.UNMASK}
style={[styles.flexGrow1]}
>
<View
fsClass={CONST.FULLSTORY.CLASS.UNMASK}
style={[styles.flexGrow1]}
>
<Text>{translate('closeAccountPage.reasonForLeavingPrompt')}</Text>
<InputWrapper
InputComponent={TextInput}
inputID={INPUT_IDS.REASON_FOR_LEAVING}
autoGrowHeight
maxAutoGrowHeight={variables.textInputAutoGrowMaxHeight}
label={translate('closeAccountPage.enterMessageHere')}
aria-label={translate('closeAccountPage.enterMessageHere')}
role={CONST.ROLE.PRESENTATION}
containerStyles={[styles.mt5]}
forwardedFSClass={CONST.FULLSTORY.CLASS.UNMASK}
/>
<Text style={[styles.mt5]}>
{translate('closeAccountPage.enterDefaultContactToConfirm')} <Text style={[styles.textStrong]}>{userEmailOrPhone}</Text>
</Text>
<InputWrapper
InputComponent={TextInput}
inputID={INPUT_IDS.PHONE_OR_EMAIL}
autoCapitalize="none"
label={translate('closeAccountPage.enterDefaultContact')}
aria-label={translate('closeAccountPage.enterDefaultContact')}
role={CONST.ROLE.PRESENTATION}
containerStyles={[styles.mt5]}
autoCorrect={false}
inputMode={userEmailOrPhone && Str.isValidEmail(userEmailOrPhone) ? CONST.INPUT_MODE.EMAIL : CONST.INPUT_MODE.TEXT}
forwardedFSClass={CONST.FULLSTORY.CLASS.UNMASK}
/>
<ConfirmModal
danger
title={translate('closeAccountPage.closeAccountWarning')}
onConfirm={onConfirm}
onCancel={hideConfirmModal}
isVisible={isConfirmModalVisible}
prompt={translate('closeAccountPage.closeAccountPermanentlyDeleteData')}
confirmText={translate('common.yesContinue')}
cancelText={translate('common.cancel')}
shouldDisableConfirmButtonWhenOffline
shouldShowCancelButton
/>
</View>
</FormProvider>
</DelegateNoAccessWrapper>
<Text>{translate('closeAccountPage.reasonForLeavingPrompt')}</Text>
<InputWrapper
InputComponent={TextInput}
inputID={INPUT_IDS.REASON_FOR_LEAVING}
autoGrowHeight
maxAutoGrowHeight={variables.textInputAutoGrowMaxHeight}
label={translate('closeAccountPage.enterMessageHere')}
aria-label={translate('closeAccountPage.enterMessageHere')}
role={CONST.ROLE.PRESENTATION}
containerStyles={[styles.mt5]}
forwardedFSClass={CONST.FULLSTORY.CLASS.UNMASK}
/>
<Text style={[styles.mt5]}>
{translate('closeAccountPage.enterDefaultContactToConfirm')} <Text style={[styles.textStrong]}>{userEmailOrPhone}</Text>
</Text>
<InputWrapper
InputComponent={TextInput}
inputID={INPUT_IDS.PHONE_OR_EMAIL}
autoCapitalize="none"
label={translate('closeAccountPage.enterDefaultContact')}
aria-label={translate('closeAccountPage.enterDefaultContact')}
role={CONST.ROLE.PRESENTATION}
containerStyles={[styles.mt5]}
autoCorrect={false}
inputMode={userEmailOrPhone && Str.isValidEmail(userEmailOrPhone) ? CONST.INPUT_MODE.EMAIL : CONST.INPUT_MODE.TEXT}
forwardedFSClass={CONST.FULLSTORY.CLASS.UNMASK}
/>
<ConfirmModal
danger
title={translate('closeAccountPage.closeAccountWarning')}
onConfirm={onConfirm}
onCancel={hideConfirmModal}
isVisible={isConfirmModalVisible}
prompt={translate('closeAccountPage.closeAccountPermanentlyDeleteData')}
confirmText={translate('common.yesContinue')}
cancelText={translate('common.cancel')}
shouldDisableConfirmButtonWhenOffline
shouldShowCancelButton
/>
</View>
</FormProvider>
</ScreenWrapper>
);
}
Expand Down
60 changes: 24 additions & 36 deletions src/pages/settings/Security/SecuritySettingsPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@
translationKey: 'twoFactorAuth.headerTitle',
icon: icons.Shield,
action: () => {
if (isDelegateAccessRestricted) {
if (isActingAsDelegate) {
showDelegateNoAccessModal();
return;
}
Expand All @@ -151,10 +151,6 @@
translationKey: 'mergeAccountsPage.mergeAccount',
icon: Expensicons.ArrowCollapse,
action: () => {
if (isDelegateAccessRestricted) {
showDelegateNoAccessModal();
return;
}
if (isAccountLocked) {
showLockedAccountModal();
return;
Expand Down Expand Up @@ -189,11 +185,6 @@
translationKey: 'closeAccountPage.closeAccount',
icon: Expensicons.ClosedSign,
action: () => {
if (isDelegateAccessRestricted) {
showDelegateNoAccessModal();
return;
}

if (isAccountLocked) {
showLockedAccountModal();
return;
Expand All @@ -210,7 +201,7 @@
link: '',
wrapperStyle: [styles.sectionMenuItemTopDescription],
}));
}, [

Check warning on line 204 in src/pages/settings/Security/SecuritySettingsPage.tsx

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

React Hook useMemo has a missing dependency: 'isActingAsDelegate'. Either include it or remove the dependency array
icons.UserLock,
icons.Shield,
isAccountLocked,
Expand Down Expand Up @@ -302,7 +293,7 @@
text: translate('delegate.changeAccessLevel'),
icon: icons.Pencil,
onPress: () => {
if (isDelegateAccessRestricted) {
if (isActingAsDelegate) {
modalClose(() => showDelegateNoAccessModal());
return;
}
Expand All @@ -320,7 +311,7 @@
text: translate('delegate.removeCopilot'),
icon: Expensicons.Trashcan,
onPress: () => {
if (isActingAsDelegate) {
if (selectedDelegate?.email !== account?.delegatedAccess?.delegate && isActingAsDelegate) {
modalClose(() => showDelegateNoAccessModal());
return;
}
Expand Down Expand Up @@ -403,25 +394,27 @@
<MenuItemList menuItems={delegateMenuItems} />
</>
)}
{!isDelegateAccessRestricted && (
<MenuItem
title={translate('delegate.addCopilot')}
icon={icons.UserPlus}
onPress={() => {
if (!isUserValidated) {
Navigation.navigate(ROUTES.SETTINGS_DELEGATE_VERIFY_ACCOUNT);
return;
}
if (isAccountLocked) {
showLockedAccountModal();
return;
}
Navigation.navigate(ROUTES.SETTINGS_ADD_DELEGATE);
}}
shouldShowRightIcon
wrapperStyle={[styles.sectionMenuItemTopDescription, hasDelegators && styles.mb6]}
/>
)}
<MenuItem
title={translate('delegate.addCopilot')}
icon={icons.UserPlus}
onPress={() => {
if (isActingAsDelegate) {
modalClose(() => showDelegateNoAccessModal());
return;
}
if (!isUserValidated) {
Navigation.navigate(ROUTES.SETTINGS_DELEGATE_VERIFY_ACCOUNT);
return;
}
if (isAccountLocked) {
showLockedAccountModal();
return;
}
Navigation.navigate(ROUTES.SETTINGS_ADD_DELEGATE);
}}
shouldShowRightIcon
wrapperStyle={[styles.sectionMenuItemTopDescription, hasDelegators && styles.mb6]}
/>
{hasDelegators && (
<>
<Text style={[styles.textLabelSupporting, styles.pv1]}>{translate('delegate.youCanAccessTheseAccounts')}</Text>
Expand Down Expand Up @@ -453,11 +446,6 @@
prompt={translate('delegate.removeCopilotConfirmation')}
danger
onConfirm={() => {
if (isActingAsDelegate) {
setShouldShowRemoveDelegateModal(false);
showDelegateNoAccessModal();
return;
}
removeDelegate({email: selectedDelegate?.email ?? '', delegatedAccess: account?.delegatedAccess});
setShouldShowRemoveDelegateModal(false);
setSelectedDelegate(undefined);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import React, {useContext, useMemo} from 'react';
import React, {useMemo} from 'react';
import type {ValueOf} from 'type-fest';
import FullPageNotFoundView from '@components/BlockingViews/FullPageNotFoundView';
import FullPageOfflineBlockingView from '@components/BlockingViews/FullPageOfflineBlockingView';
import {DelegateNoAccessContext} from '@components/DelegateNoAccessModalProvider';
import DelegateNoAccessWrapper from '@components/DelegateNoAccessWrapper';
import HeaderWithBackButton from '@components/HeaderWithBackButton';
import ScreenWrapper from '@components/ScreenWrapper';
Expand Down Expand Up @@ -45,7 +44,6 @@ function TwoFactorAuthWrapper({
children,
}: TwoFactorAuthWrapperProps) {
const [account] = useOnyx(ONYXKEYS.ACCOUNT, {canBeMissing: false});
const {isDelegateAccessRestricted} = useContext(DelegateNoAccessContext);

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

const viewportOffsetTop = useViewportOffsetTop();

if (isDelegateAccessRestricted) {
return (
<ScreenWrapper
testID="TwoFactorAuthWrapper"
includeSafeAreaPaddingBottom={false}
shouldEnablePickerAvoiding={false}
>
<DelegateNoAccessWrapper accessDeniedVariants={[CONST.DELEGATE.DENIED_ACCESS_VARIANTS.DELEGATE]} />
</ScreenWrapper>
);
}

const defaultGoBack = () => quitAndNavigateBack(ROUTES.SETTINGS_SECURITY);

return (
Expand All @@ -95,18 +81,20 @@ function TwoFactorAuthWrapper({
testID={stepName}
style={shouldEnableViewportOffsetTop ? {marginTop: viewportOffsetTop} : undefined}
>
<FullPageNotFoundView
shouldShow={shouldShowNotFound}
linkTranslationKey="securityPage.goToSecurity"
onLinkPress={defaultGoBack}
>
<HeaderWithBackButton
title={title}
stepCounter={stepCounter}
onBackButtonPress={onBackButtonPress ?? defaultGoBack}
/>
<FullPageOfflineBlockingView>{children}</FullPageOfflineBlockingView>
</FullPageNotFoundView>
<DelegateNoAccessWrapper accessDeniedVariants={[CONST.DELEGATE.DENIED_ACCESS_VARIANTS.DELEGATE]}>
<FullPageNotFoundView
shouldShow={shouldShowNotFound}
linkTranslationKey="securityPage.goToSecurity"
onLinkPress={defaultGoBack}
>
<HeaderWithBackButton
title={title}
stepCounter={stepCounter}
onBackButtonPress={onBackButtonPress ?? defaultGoBack}
/>
<FullPageOfflineBlockingView>{children}</FullPageOfflineBlockingView>
</FullPageNotFoundView>
</DelegateNoAccessWrapper>
</ScreenWrapper>
);
}
Expand Down
Loading