Skip to content

Commit 4feae64

Browse files
committed
Fix domain reset optimistic deletion flow
1 parent 0471d1f commit 4feae64

3 files changed

Lines changed: 19 additions & 14 deletions

File tree

src/libs/actions/Domain.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import enhanceParameters from '@libs/Network/enhanceParameters';
2727
import {generateAccountID} from '@libs/UserUtils';
2828
import CONST from '@src/CONST';
2929
import ONYXKEYS from '@src/ONYXKEYS';
30-
import type {Domain, DomainSecurityGroup, UserSecurityGroupData} from '@src/types/onyx';
30+
import type {DomainSecurityGroup, UserSecurityGroupData} from '@src/types/onyx';
3131
import type {SecurityGroupKey} from '@src/types/onyx/Domain';
3232
import type {DomainSecurityGroupErrors} from '@src/types/onyx/DomainErrors';
3333
import type {PendingAction} from '@src/types/onyx/OnyxCommon';
@@ -765,7 +765,7 @@ function revokeDomainAdminAccess(domainAccountID: number, accountID: number) {
765765
/**
766766
* Removes the domain
767767
*/
768-
function resetDomain(domainAccountID: number, domainName: string, domain: Domain) {
768+
function resetDomain(domainAccountID: number, domainName: string) {
769769
const optimisticData: Array<OnyxUpdate<typeof ONYXKEYS.COLLECTION.DOMAIN_PENDING_ACTIONS | typeof ONYXKEYS.COLLECTION.DOMAIN>> = [
770770
{
771771
onyxMethod: Onyx.METHOD.MERGE,
@@ -777,10 +777,15 @@ function resetDomain(domainAccountID: number, domainName: string, domain: Domain
777777
{
778778
onyxMethod: Onyx.METHOD.MERGE,
779779
key: `${ONYXKEYS.COLLECTION.DOMAIN}${domainAccountID}`,
780-
value: null,
780+
value: {pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE},
781781
},
782782
];
783-
const successData: Array<OnyxUpdate<typeof ONYXKEYS.COLLECTION.DOMAIN_PENDING_ACTIONS | typeof ONYXKEYS.COLLECTION.DOMAIN_ERRORS>> = [
783+
const successData: Array<OnyxUpdate<typeof ONYXKEYS.COLLECTION.DOMAIN | typeof ONYXKEYS.COLLECTION.DOMAIN_PENDING_ACTIONS | typeof ONYXKEYS.COLLECTION.DOMAIN_ERRORS>> = [
784+
{
785+
onyxMethod: Onyx.METHOD.SET,
786+
key: `${ONYXKEYS.COLLECTION.DOMAIN}${domainAccountID}`,
787+
value: null,
788+
},
784789
{
785790
onyxMethod: Onyx.METHOD.MERGE,
786791
key: `${ONYXKEYS.COLLECTION.DOMAIN_PENDING_ACTIONS}${domainAccountID}`,
@@ -800,7 +805,7 @@ function resetDomain(domainAccountID: number, domainName: string, domain: Domain
800805
{
801806
onyxMethod: Onyx.METHOD.MERGE,
802807
key: `${ONYXKEYS.COLLECTION.DOMAIN}${domainAccountID}`,
803-
value: domain,
808+
value: {pendingAction: null},
804809
},
805810
{
806811
onyxMethod: Onyx.METHOD.MERGE,

src/pages/domain/DomainResetPage.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ function DomainResetDomainPage({route}: DomainResetDomainPageProps) {
5757
Log.hmmm('Domain data is missing or there are more than 1 admin left');
5858
return;
5959
}
60-
resetDomain(route.params.domainAccountID, domainName, domain);
60+
resetDomain(route.params.domainAccountID, domainName);
6161
Navigation.goBack(ROUTES.WORKSPACES_LIST.route);
6262
};
6363

tests/actions/DomainTest.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ import CONST from '@src/CONST';
2929
import IntlStore from '@src/languages/IntlStore';
3030
import OnyxUpdateManager from '@src/libs/actions/OnyxUpdateManager';
3131
import ONYXKEYS from '@src/ONYXKEYS';
32-
import type {Domain, DomainSecurityGroup, UserSecurityGroupData} from '@src/types/onyx';
32+
import type {DomainSecurityGroup, UserSecurityGroupData} from '@src/types/onyx';
3333
import type {SecurityGroupKey} from '@src/types/onyx/Domain';
3434
import type {BaseVacationDelegate} from '@src/types/onyx/VacationDelegate';
3535
import type PrefixedRecord from '@src/types/utils/PrefixedRecord';
@@ -90,20 +90,20 @@ describe('actions/Domain', () => {
9090
const apiWriteSpy = jest.spyOn(require('@libs/API'), 'write').mockImplementation(() => Promise.resolve());
9191
const domainAccountID = 123;
9292
const domainName = 'test.com';
93-
const domain = {
94-
accountID: domainAccountID,
95-
} as Domain;
9693

97-
resetDomain(domainAccountID, domainName, domain);
94+
resetDomain(domainAccountID, domainName);
9895

9996
expect(apiWriteSpy).toHaveBeenCalledWith(
10097
WRITE_COMMANDS.DELETE_DOMAIN,
10198
{domainAccountID, domainName},
10299
{
103-
optimisticData: [expect.objectContaining({value: {pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE}}), expect.objectContaining({value: null})],
104-
successData: [expect.objectContaining({value: {pendingAction: null}}), expect.objectContaining({value: {errors: null}})],
100+
optimisticData: [
101+
expect.objectContaining({value: {pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE}}),
102+
expect.objectContaining({value: {pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE}}),
103+
],
104+
successData: [expect.objectContaining({value: null}), expect.objectContaining({value: {pendingAction: null}}), expect.objectContaining({value: {errors: null}})],
105105
failureData: [
106-
expect.objectContaining({value: domain}),
106+
expect.objectContaining({value: {pendingAction: null}}),
107107
expect.objectContaining({value: {pendingAction: null}}),
108108
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
109109
expect.objectContaining({value: {errors: expect.any(Object)}}),

0 commit comments

Comments
 (0)