Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
91 changes: 44 additions & 47 deletions src/pages/settings/Security/CloseAccountPage.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import {Str} from 'expensify-common';
import React, {useEffect} from 'react';
import {View} from 'react-native';
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 @@ -94,53 +93,51 @@ 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={onSubmit}
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={onSubmit}
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}
/>
</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}
/>
</View>
</FormProvider>
</ScreenWrapper>
);
}
Expand Down
63 changes: 28 additions & 35 deletions src/pages/settings/Security/SecuritySettingsPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ function SecuritySettingsPage() {

const {isAccountLocked} = useLockedAccountState();
const {showLockedAccountModal} = useLockedAccountActions();
const {isActingAsDelegate, isDelegateAccessRestricted} = useDelegateNoAccessState();
const {isActingAsDelegate} = useDelegateNoAccessState();
const {showDelegateNoAccessModal} = useDelegateNoAccessActions();
const delegates = account?.delegatedAccess?.delegates ?? [];
const delegators = account?.delegatedAccess?.delegators ?? [];
Expand Down Expand Up @@ -158,7 +158,7 @@ function SecuritySettingsPage() {
icon: icons.Shield,
sentryLabel: CONST.SENTRY_LABEL.SETTINGS_SECURITY.TWO_FACTOR_AUTH,
action: () => {
if (isDelegateAccessRestricted) {
if (isActingAsDelegate) {
showDelegateNoAccessModal();
return;
}
Expand Down Expand Up @@ -191,10 +191,6 @@ function SecuritySettingsPage() {
icon: icons.ArrowCollapse,
sentryLabel: CONST.SENTRY_LABEL.SETTINGS_SECURITY.MERGE_ACCOUNTS,
action: () => {
if (isDelegateAccessRestricted) {
showDelegateNoAccessModal();
return;
}
if (isAccountLocked) {
showLockedAccountModal();
return;
Expand Down Expand Up @@ -231,11 +227,6 @@ function SecuritySettingsPage() {
icon: icons.ClosedSign,
sentryLabel: CONST.SENTRY_LABEL.SETTINGS_SECURITY.CLOSE_ACCOUNT,
action: () => {
if (isDelegateAccessRestricted) {
showDelegateNoAccessModal();
return;
}

if (isAccountLocked) {
showLockedAccountModal();
return;
Expand All @@ -260,7 +251,7 @@ function SecuritySettingsPage() {
icons.Shield,
icons.Fingerprint,
isAccountLocked,
isDelegateAccessRestricted,
isActingAsDelegate,
isUserValidated,
showDelegateNoAccessModal,
showLockedAccountModal,
Expand Down Expand Up @@ -355,7 +346,7 @@ function SecuritySettingsPage() {
icon: icons.Pencil,
sentryLabel: CONST.SENTRY_LABEL.SETTINGS_SECURITY.DELEGATE_CHANGE_ACCESS,
onPress: () => {
if (isDelegateAccessRestricted) {
if (isActingAsDelegate) {
modalClose(() => showDelegateNoAccessModal());
return;
}
Expand All @@ -374,7 +365,7 @@ function SecuritySettingsPage() {
icon: icons.Trashcan,
sentryLabel: CONST.SENTRY_LABEL.SETTINGS_SECURITY.DELEGATE_REMOVE,
onPress: () => {
if (isActingAsDelegate) {
if (selectedDelegate?.email !== account?.delegatedAccess?.delegate && isActingAsDelegate) {
modalClose(() => showDelegateNoAccessModal());
return;
}
Expand All @@ -389,7 +380,7 @@ function SecuritySettingsPage() {
if (result.action === ModalActions.CLOSE) {
setSelectedDelegate(undefined);
} else {
if (isActingAsDelegate) {
if (selectedDelegate?.email !== account?.delegatedAccess?.delegate && isActingAsDelegate) {
showDelegateNoAccessModal();
return;
}
Expand Down Expand Up @@ -470,26 +461,28 @@ function SecuritySettingsPage() {
<MenuItemList menuItems={delegateMenuItems} />
</>
)}
{!isDelegateAccessRestricted && (
<MenuItem
title={translate('delegate.addCopilot')}
icon={icons.UserPlus}
sentryLabel={CONST.SENTRY_LABEL.SETTINGS_SECURITY.ADD_COPILOT}
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}
sentryLabel={CONST.SENTRY_LABEL.SETTINGS_SECURITY.ADD_COPILOT}
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
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import React, {useMemo} from 'react';
import type {ValueOf} from 'type-fest';
import FullPageNotFoundView from '@components/BlockingViews/FullPageNotFoundView';
import FullPageOfflineBlockingView from '@components/BlockingViews/FullPageOfflineBlockingView';
import {useDelegateNoAccessState} from '@components/DelegateNoAccessModalProvider';
import DelegateNoAccessWrapper from '@components/DelegateNoAccessWrapper';
import HeaderWithBackButton from '@components/HeaderWithBackButton';
import ScreenWrapper from '@components/ScreenWrapper';
Expand Down Expand Up @@ -36,7 +35,6 @@ type TwoFactorAuthWrapperProps = ChildrenProps & {

function TwoFactorAuthWrapper({stepName, title, stepCounter, onBackButtonPress, shouldEnableKeyboardAvoidingView = true, shouldEnableMaxHeight = true, children}: TwoFactorAuthWrapperProps) {
const [account] = useOnyx(ONYXKEYS.ACCOUNT);
const {isDelegateAccessRestricted} = useDelegateNoAccessState();

// eslint-disable-next-line rulesdir/no-negated-variables
const shouldShowNotFound = useMemo(() => {
Expand All @@ -62,18 +60,6 @@ function TwoFactorAuthWrapper({stepName, title, stepCounter, onBackButtonPress,
}
}, [account, stepName]);

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 @@ -83,18 +69,20 @@ function TwoFactorAuthWrapper({stepName, title, stepCounter, onBackButtonPress,
shouldEnableMaxHeight={shouldEnableMaxHeight}
testID={stepName}
>
<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