From ede55e32a1155ffc1cc6b3135bc87fa228224480 Mon Sep 17 00:00:00 2001 From: Sachin Chavda Date: Thu, 22 Jan 2026 20:21:31 +0530 Subject: [PATCH 1/3] Align copilot security-features access with OD --- .../settings/Security/CloseAccountPage.tsx | 115 +++++++++--------- .../Security/SecuritySettingsPage.tsx | 55 ++++----- .../TwoFactorAuth/TwoFactorAuthWrapper.tsx | 42 +++---- 3 files changed, 93 insertions(+), 119 deletions(-) diff --git a/src/pages/settings/Security/CloseAccountPage.tsx b/src/pages/settings/Security/CloseAccountPage.tsx index a9113ffc59bf..06719d8e4314 100644 --- a/src/pages/settings/Security/CloseAccountPage.tsx +++ b/src/pages/settings/Security/CloseAccountPage.tsx @@ -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'; @@ -90,65 +89,63 @@ function CloseAccountPage() { includeSafeAreaPaddingBottom testID="CloseAccountPage" > - - Navigation.goBack()} - /> - Navigation.goBack()} + /> + + - - {translate('closeAccountPage.reasonForLeavingPrompt')} - - - {translate('closeAccountPage.enterDefaultContactToConfirm')} {userEmailOrPhone} - - - - - - + {translate('closeAccountPage.reasonForLeavingPrompt')} + + + {translate('closeAccountPage.enterDefaultContactToConfirm')} {userEmailOrPhone} + + + + + ); } diff --git a/src/pages/settings/Security/SecuritySettingsPage.tsx b/src/pages/settings/Security/SecuritySettingsPage.tsx index 3e4e91133ee0..f0abcf244888 100644 --- a/src/pages/settings/Security/SecuritySettingsPage.tsx +++ b/src/pages/settings/Security/SecuritySettingsPage.tsx @@ -130,7 +130,7 @@ function SecuritySettingsPage() { translationKey: 'twoFactorAuth.headerTitle', icon: icons.Shield, action: () => { - if (isDelegateAccessRestricted) { + if (isActingAsDelegate) { showDelegateNoAccessModal(); return; } @@ -149,10 +149,6 @@ function SecuritySettingsPage() { translationKey: 'mergeAccountsPage.mergeAccount', icon: icons.ArrowCollapse, action: () => { - if (isDelegateAccessRestricted) { - showDelegateNoAccessModal(); - return; - } if (isAccountLocked) { showLockedAccountModal(); return; @@ -187,11 +183,6 @@ function SecuritySettingsPage() { translationKey: 'closeAccountPage.closeAccount', icon: Expensicons.ClosedSign, action: () => { - if (isDelegateAccessRestricted) { - showDelegateNoAccessModal(); - return; - } - if (isAccountLocked) { showLockedAccountModal(); return; @@ -213,7 +204,7 @@ function SecuritySettingsPage() { icons.UserLock, icons.Shield, isAccountLocked, - isDelegateAccessRestricted, + isActingAsDelegate, isUserValidated, showDelegateNoAccessModal, showLockedAccountModal, @@ -301,7 +292,7 @@ function SecuritySettingsPage() { text: translate('delegate.changeAccessLevel'), icon: icons.Pencil, onPress: () => { - if (isDelegateAccessRestricted) { + if (isActingAsDelegate) { modalClose(() => showDelegateNoAccessModal()); return; } @@ -319,7 +310,7 @@ function SecuritySettingsPage() { text: translate('delegate.removeCopilot'), icon: Expensicons.Trashcan, onPress: () => { - if (isActingAsDelegate) { + if (selectedDelegate?.email !== account?.delegatedAccess?.delegate && isActingAsDelegate) { modalClose(() => showDelegateNoAccessModal()); return; } @@ -403,25 +394,23 @@ function SecuritySettingsPage() { )} - {!isDelegateAccessRestricted && ( - { - 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]} - /> - )} + { + 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 && ( <> {translate('delegate.youCanAccessTheseAccounts')} @@ -453,7 +442,7 @@ function SecuritySettingsPage() { prompt={translate('delegate.removeCopilotConfirmation')} danger onConfirm={() => { - if (isActingAsDelegate) { + if (selectedDelegate?.email !== account?.delegatedAccess?.delegate && isActingAsDelegate) { setShouldShowRemoveDelegateModal(false); showDelegateNoAccessModal(); return; diff --git a/src/pages/settings/Security/TwoFactorAuth/TwoFactorAuthWrapper.tsx b/src/pages/settings/Security/TwoFactorAuth/TwoFactorAuthWrapper.tsx index 3a83d92304d9..af891514f04d 100644 --- a/src/pages/settings/Security/TwoFactorAuth/TwoFactorAuthWrapper.tsx +++ b/src/pages/settings/Security/TwoFactorAuth/TwoFactorAuthWrapper.tsx @@ -1,8 +1,7 @@ -import React, {useContext, useMemo} from 'react'; +import {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'; @@ -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(() => { @@ -73,18 +71,6 @@ function TwoFactorAuthWrapper({ const viewportOffsetTop = useViewportOffsetTop(); - if (isDelegateAccessRestricted) { - return ( - - - - ); - } - const defaultGoBack = () => quitAndNavigateBack(ROUTES.SETTINGS_SECURITY); return ( @@ -95,18 +81,20 @@ function TwoFactorAuthWrapper({ testID={stepName} style={shouldEnableViewportOffsetTop ? {marginTop: viewportOffsetTop} : undefined} > - - - {children} - + + + + {children} + + ); } From 1a0a3771ebbda2c192705eb570ce89e7b64c6afe Mon Sep 17 00:00:00 2001 From: Sachin Chavda Date: Thu, 22 Jan 2026 20:27:19 +0530 Subject: [PATCH 2/3] lint --- src/pages/settings/Security/SecuritySettingsPage.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pages/settings/Security/SecuritySettingsPage.tsx b/src/pages/settings/Security/SecuritySettingsPage.tsx index f0abcf244888..e2d2c7cd7e9c 100644 --- a/src/pages/settings/Security/SecuritySettingsPage.tsx +++ b/src/pages/settings/Security/SecuritySettingsPage.tsx @@ -84,7 +84,7 @@ function SecuritySettingsPage() { }); const {isAccountLocked, showLockedAccountModal} = useContext(LockedAccountContext); - const {isActingAsDelegate, isDelegateAccessRestricted, showDelegateNoAccessModal} = useContext(DelegateNoAccessContext); + const {isActingAsDelegate, showDelegateNoAccessModal} = useContext(DelegateNoAccessContext); const delegates = account?.delegatedAccess?.delegates ?? []; const delegators = account?.delegatedAccess?.delegators ?? []; From 911986d06ce09a8b1a0bd4336c21ca408ed79295 Mon Sep 17 00:00:00 2001 From: Sachin Chavda Date: Tue, 24 Feb 2026 00:55:57 +0530 Subject: [PATCH 3/3] Lint --- .../settings/Security/TwoFactorAuth/TwoFactorAuthWrapper.tsx | 1 - 1 file changed, 1 deletion(-) diff --git a/src/pages/settings/Security/TwoFactorAuth/TwoFactorAuthWrapper.tsx b/src/pages/settings/Security/TwoFactorAuth/TwoFactorAuthWrapper.tsx index cdaa4bda44b0..d00c3cc78bb9 100644 --- a/src/pages/settings/Security/TwoFactorAuth/TwoFactorAuthWrapper.tsx +++ b/src/pages/settings/Security/TwoFactorAuth/TwoFactorAuthWrapper.tsx @@ -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';