Skip to content

Commit 029ec46

Browse files
Refactor: isolate requestUnlockAccount from ONYXKEYS.SESSION Onyx data
1 parent 1dd01da commit 029ec46

4 files changed

Lines changed: 11 additions & 6 deletions

File tree

src/libs/actions/User.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1452,9 +1452,9 @@ function lockAccount(accountID?: number, domainAccountID?: number, domainName?:
14521452
return API.makeRequestWithSideEffects(SIDE_EFFECT_REQUEST_COMMANDS.LOCK_ACCOUNT, params, {optimisticData, successData, failureData});
14531453
}
14541454

1455-
function requestUnlockAccount(accountID?: number) {
1455+
function requestUnlockAccount(currentAccountIDParam: number, accountID: number | undefined) {
14561456
const params: LockAccountParams = {
1457-
accountID: accountID ?? currentUserAccountID,
1457+
accountID: accountID ?? currentAccountIDParam,
14581458
};
14591459

14601460
API.write(WRITE_COMMANDS.REQUEST_UNLOCK_ACCOUNT, params);

src/pages/domain/Members/DomainMemberDetailsPage.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import MenuItem from '@components/MenuItem';
1010
import {ModalActions} from '@components/Modal/Global/ModalContext';
1111
import VacationDelegateMenuItem from '@components/VacationDelegateMenuItem';
1212
import useConfirmModal from '@hooks/useConfirmModal';
13+
import useCurrentUserPersonalDetails from '@hooks/useCurrentUserPersonalDetails';
1314
import {useMemoizedLazyExpensifyIcons} from '@hooks/useLazyAsset';
1415
import useLocalize from '@hooks/useLocalize';
1516
import useOnyx from '@hooks/useOnyx';
@@ -36,6 +37,7 @@ function DomainMemberDetailsPage({route}: DomainMemberDetailsPageProps) {
3637
const {domainAccountID, accountID} = route.params;
3738
const styles = useThemeStyles();
3839
const {translate} = useLocalize();
40+
const currentUserPersonalDetails = useCurrentUserPersonalDetails();
3941
const icons = useMemoizedLazyExpensifyIcons(['RemoveMembers', 'Flag', 'Unlock', 'CircularArrowBackwards']);
4042
const [isModalVisible, setIsModalVisible] = useState(false);
4143
const [shouldForceCloseAccount, setShouldForceCloseAccount] = useState<boolean>();
@@ -119,7 +121,7 @@ function DomainMemberDetailsPage({route}: DomainMemberDetailsPageProps) {
119121
);
120122

121123
const showUnlockAccountModal = () => {
122-
requestUnlockAccount(accountID);
124+
requestUnlockAccount(currentUserPersonalDetails.accountID, accountID);
123125
showConfirmModal({
124126
title: translate('lockAccountPage.unlockTitle'),
125127
prompt: translate('lockAccountPage.unlockDescription'),

src/pages/settings/Security/LockAccount/UnlockAccountPage.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import ConfirmationPage from '@components/ConfirmationPage';
33
import HeaderWithBackButton from '@components/HeaderWithBackButton';
44
import ScreenWrapper from '@components/ScreenWrapper';
55
import ScrollView from '@components/ScrollView';
6+
import useCurrentUserPersonalDetails from '@hooks/useCurrentUserPersonalDetails';
67
import {useMemoizedLazyExpensifyIcons} from '@hooks/useLazyAsset';
78
import useLocalize from '@hooks/useLocalize';
89
import useThemeStyles from '@hooks/useThemeStyles';
@@ -12,6 +13,7 @@ import ROUTES from '@src/ROUTES';
1213

1314
function UnlockAccountPage() {
1415
const {translate} = useLocalize();
16+
const currentUserPersonalDetails = useCurrentUserPersonalDetails();
1517
const styles = useThemeStyles();
1618
const icons = useMemoizedLazyExpensifyIcons(['EmptyStateSpyPigeon']);
1719

@@ -33,7 +35,7 @@ function UnlockAccountPage() {
3335
descriptionStyle={styles.colorMuted}
3436
buttonText={translate('unlockAccountPage.chatWithConcierge')}
3537
onButtonPress={() => {
36-
requestUnlockAccount();
38+
requestUnlockAccount(currentUserPersonalDetails.accountID, undefined);
3739
Navigation.navigate(ROUTES.CONCIERGE);
3840
}}
3941
containerStyle={styles.h100}

tests/actions/UserTest.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -792,8 +792,9 @@ describe('actions/User', () => {
792792

793793
describe('requestUnlockAccount', () => {
794794
it('should call API.write with REQUEST_UNLOCK_ACCOUNT command and explicit accountID', async () => {
795+
const currentAccountID = 888;
795796
const accountID = 123456;
796-
UserActions.requestUnlockAccount(accountID);
797+
UserActions.requestUnlockAccount(currentAccountID, accountID);
797798
await waitForBatchedUpdates();
798799

799800
expect(mockAPI.write).toHaveBeenCalledWith(WRITE_COMMANDS.REQUEST_UNLOCK_ACCOUNT, {accountID});
@@ -804,7 +805,7 @@ describe('actions/User', () => {
804805
await Onyx.merge(ONYXKEYS.SESSION, {accountID: currentAccountID, email: 'user@expensify.com'});
805806
await waitForBatchedUpdates();
806807

807-
UserActions.requestUnlockAccount();
808+
UserActions.requestUnlockAccount(currentAccountID, undefined);
808809
await waitForBatchedUpdates();
809810

810811
expect(mockAPI.write).toHaveBeenCalledWith(WRITE_COMMANDS.REQUEST_UNLOCK_ACCOUNT, {accountID: currentAccountID});

0 commit comments

Comments
 (0)