From 4feae64be8a6256d2fc13f379e96ed7eaedba2d8 Mon Sep 17 00:00:00 2001 From: emkhalid Date: Fri, 8 May 2026 00:26:06 +0430 Subject: [PATCH] Fix domain reset optimistic deletion flow --- src/libs/actions/Domain.ts | 15 ++++++++++----- src/pages/domain/DomainResetPage.tsx | 2 +- tests/actions/DomainTest.ts | 16 ++++++++-------- 3 files changed, 19 insertions(+), 14 deletions(-) diff --git a/src/libs/actions/Domain.ts b/src/libs/actions/Domain.ts index e44296439671..95bda9564e53 100644 --- a/src/libs/actions/Domain.ts +++ b/src/libs/actions/Domain.ts @@ -27,7 +27,7 @@ import enhanceParameters from '@libs/Network/enhanceParameters'; import {generateAccountID} from '@libs/UserUtils'; import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; -import type {Domain, DomainSecurityGroup, UserSecurityGroupData} from '@src/types/onyx'; +import type {DomainSecurityGroup, UserSecurityGroupData} from '@src/types/onyx'; import type {SecurityGroupKey} from '@src/types/onyx/Domain'; import type {DomainSecurityGroupErrors} from '@src/types/onyx/DomainErrors'; import type {PendingAction} from '@src/types/onyx/OnyxCommon'; @@ -765,7 +765,7 @@ function revokeDomainAdminAccess(domainAccountID: number, accountID: number) { /** * Removes the domain */ -function resetDomain(domainAccountID: number, domainName: string, domain: Domain) { +function resetDomain(domainAccountID: number, domainName: string) { const optimisticData: Array> = [ { onyxMethod: Onyx.METHOD.MERGE, @@ -777,10 +777,15 @@ function resetDomain(domainAccountID: number, domainName: string, domain: Domain { onyxMethod: Onyx.METHOD.MERGE, key: `${ONYXKEYS.COLLECTION.DOMAIN}${domainAccountID}`, - value: null, + value: {pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE}, }, ]; - const successData: Array> = [ + const successData: Array> = [ + { + onyxMethod: Onyx.METHOD.SET, + key: `${ONYXKEYS.COLLECTION.DOMAIN}${domainAccountID}`, + value: null, + }, { onyxMethod: Onyx.METHOD.MERGE, key: `${ONYXKEYS.COLLECTION.DOMAIN_PENDING_ACTIONS}${domainAccountID}`, @@ -800,7 +805,7 @@ function resetDomain(domainAccountID: number, domainName: string, domain: Domain { onyxMethod: Onyx.METHOD.MERGE, key: `${ONYXKEYS.COLLECTION.DOMAIN}${domainAccountID}`, - value: domain, + value: {pendingAction: null}, }, { onyxMethod: Onyx.METHOD.MERGE, diff --git a/src/pages/domain/DomainResetPage.tsx b/src/pages/domain/DomainResetPage.tsx index d4e6cab7e328..3b47b2af8749 100644 --- a/src/pages/domain/DomainResetPage.tsx +++ b/src/pages/domain/DomainResetPage.tsx @@ -57,7 +57,7 @@ function DomainResetDomainPage({route}: DomainResetDomainPageProps) { Log.hmmm('Domain data is missing or there are more than 1 admin left'); return; } - resetDomain(route.params.domainAccountID, domainName, domain); + resetDomain(route.params.domainAccountID, domainName); Navigation.goBack(ROUTES.WORKSPACES_LIST.route); }; diff --git a/tests/actions/DomainTest.ts b/tests/actions/DomainTest.ts index e81a31900a9a..c3f60715af07 100644 --- a/tests/actions/DomainTest.ts +++ b/tests/actions/DomainTest.ts @@ -29,7 +29,7 @@ import CONST from '@src/CONST'; import IntlStore from '@src/languages/IntlStore'; import OnyxUpdateManager from '@src/libs/actions/OnyxUpdateManager'; import ONYXKEYS from '@src/ONYXKEYS'; -import type {Domain, DomainSecurityGroup, UserSecurityGroupData} from '@src/types/onyx'; +import type {DomainSecurityGroup, UserSecurityGroupData} from '@src/types/onyx'; import type {SecurityGroupKey} from '@src/types/onyx/Domain'; import type {BaseVacationDelegate} from '@src/types/onyx/VacationDelegate'; import type PrefixedRecord from '@src/types/utils/PrefixedRecord'; @@ -90,20 +90,20 @@ describe('actions/Domain', () => { const apiWriteSpy = jest.spyOn(require('@libs/API'), 'write').mockImplementation(() => Promise.resolve()); const domainAccountID = 123; const domainName = 'test.com'; - const domain = { - accountID: domainAccountID, - } as Domain; - resetDomain(domainAccountID, domainName, domain); + resetDomain(domainAccountID, domainName); expect(apiWriteSpy).toHaveBeenCalledWith( WRITE_COMMANDS.DELETE_DOMAIN, {domainAccountID, domainName}, { - optimisticData: [expect.objectContaining({value: {pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE}}), expect.objectContaining({value: null})], - successData: [expect.objectContaining({value: {pendingAction: null}}), expect.objectContaining({value: {errors: null}})], + optimisticData: [ + expect.objectContaining({value: {pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE}}), + expect.objectContaining({value: {pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE}}), + ], + successData: [expect.objectContaining({value: null}), expect.objectContaining({value: {pendingAction: null}}), expect.objectContaining({value: {errors: null}})], failureData: [ - expect.objectContaining({value: domain}), + expect.objectContaining({value: {pendingAction: null}}), expect.objectContaining({value: {pendingAction: null}}), // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment expect.objectContaining({value: {errors: expect.any(Object)}}),