Skip to content

Commit 626a3df

Browse files
authored
Merge pull request Expensify#88188 from callstack-internal/fix/81452-pr-regressions-pt2
Do not show workspace deleted offline in the feed selector
2 parents 2684a1f + a2d7df7 commit 626a3df

9 files changed

Lines changed: 101 additions & 21 deletions

File tree

src/hooks/useCardFeedsForDisplay.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import type {CardFeedForDisplay} from '@libs/CardFeedUtils';
33
import {getCardFeedsForDisplayPerPolicy} from '@libs/CardFeedUtils';
44
import {isCustomFeed} from '@libs/CardUtils';
55
import {isPaidGroupPolicy} from '@libs/PolicyUtils';
6+
import CONST from '@src/CONST';
67
import ONYXKEYS from '@src/ONYXKEYS';
78
import type {Policy} from '@src/types/onyx';
89
import type {CardFeedWithNumber} from '@src/types/onyx/CardFeeds';
@@ -12,7 +13,7 @@ import useOnyx from './useOnyx';
1213

1314
const eligiblePoliciesSelector = (policies: OnyxCollection<Policy>): string[] => {
1415
return Object.values(policies ?? {}).reduce((policiesIDs, policy) => {
15-
if (isPaidGroupPolicy(policy) && policy?.areCompanyCardsEnabled) {
16+
if (isPaidGroupPolicy(policy) && policy?.areCompanyCardsEnabled && policy?.pendingAction !== CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE) {
1617
policiesIDs.push(policy.id);
1718
}
1819
return policiesIDs;

src/hooks/useDefaultFundID.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@ function useDefaultFundID(policyID: string | undefined) {
2525

2626
const getDomainFundID = useCallback(
2727
(cardSettings: OnyxCollection<ExpensifyCardSettings>) => {
28-
const eligibleEntries = Object.entries(cardSettings ?? {}).filter(([key, settings]) => !!settings && !key.includes(workspaceAccountID.toString()));
28+
const eligibleEntries = Object.entries(cardSettings ?? {}).filter(
29+
([key, settings]) => !!settings && !key.includes(workspaceAccountID.toString()) && settings.pendingAction !== CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE,
30+
);
2931

3032
if (policyID) {
3133
const preferredMatch = eligibleEntries.find(([, settings]) => getPreferredPolicyFromExpensifyCardSettings(settings)?.toUpperCase() === policyID.toUpperCase());
@@ -52,7 +54,9 @@ function useDefaultFundID(policyID: string | undefined) {
5254
[getDomainFundID],
5355
);
5456

55-
if (lastSelectedExpensifyCardFeed && lastSelectedSettings?.paymentBankAccountID) {
57+
const isFeedPendingDelete = lastSelectedCardSettings?.pendingAction === CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE;
58+
59+
if (lastSelectedExpensifyCardFeed && lastSelectedSettings?.paymentBankAccountID && !isFeedPendingDelete) {
5660
return lastSelectedExpensifyCardFeed;
5761
}
5862

src/libs/ExpensifyCardFeedSelectorUtils.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import type {OnyxCollection, OnyxEntry} from 'react-native-onyx';
2+
import CONST from '@src/CONST';
23
import ONYXKEYS from '@src/ONYXKEYS';
34
import type {ExpensifyCardSettings, Policy} from '@src/types/onyx';
45
import {
@@ -26,14 +27,17 @@ function isExpensifyCardFeedVisibleToAdmin(settings: ExpensifyCardSettings, poli
2627
}
2728
const linkedPolicyIDs = getLinkedPolicyIDsFromExpensifyCardSettings(settings);
2829
if (linkedPolicyIDs?.length) {
29-
return linkedPolicyIDs.some((linkedPolicyID) => isPolicyAdmin(policies?.[`${ONYXKEYS.COLLECTION.POLICY}${linkedPolicyID.toUpperCase()}`]));
30+
return linkedPolicyIDs.some((linkedPolicyID) => {
31+
const policy = policies?.[`${ONYXKEYS.COLLECTION.POLICY}${linkedPolicyID.toUpperCase()}`];
32+
return isPolicyAdmin(policy) && policy?.pendingAction !== CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE;
33+
});
3034
}
3135
const preferredPolicy = getPreferredPolicyFromExpensifyCardSettings(settings);
3236
if (!preferredPolicy) {
3337
return false;
3438
}
3539
const policy = policies?.[`${ONYXKEYS.COLLECTION.POLICY}${preferredPolicy.toUpperCase()}`];
36-
return isPolicyAdmin(policy);
40+
return isPolicyAdmin(policy) && policy?.pendingAction !== CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE;
3741
}
3842

3943
function isFeedLinkedToPolicy(entry: ExpensifyCardFeedEntry, policyID: string): boolean {

src/libs/actions/Policy/Policy.ts

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ import type {
125125
Transaction,
126126
TransactionViolations,
127127
} from '@src/types/onyx';
128+
import type {CompanyCardFeedWithDomainID, FundID} from '@src/types/onyx/CardFeeds';
128129
import type {Participant} from '@src/types/onyx/IOU';
129130
import type {ErrorFields, Errors, PendingAction} from '@src/types/onyx/OnyxCommon';
130131
import type {
@@ -367,6 +368,8 @@ type DeleteWorkspaceActionParams = {
367368
policyName: string;
368369
lastAccessedWorkspacePolicyID: string | undefined;
369370
policyCardFeeds: CardFeeds | undefined;
371+
lastSelectedFeed: CompanyCardFeedWithDomainID | undefined;
372+
lastSelectedExpensifyCardFeed: FundID | undefined;
370373
reportsToArchive: Report[];
371374
transactionViolations: OnyxCollection<TransactionViolations> | undefined;
372375
reimbursementAccountError: Errors | undefined;
@@ -388,6 +391,8 @@ function deleteWorkspace(params: DeleteWorkspaceActionParams) {
388391
policyName,
389392
lastAccessedWorkspacePolicyID,
390393
policyCardFeeds,
394+
lastSelectedFeed,
395+
lastSelectedExpensifyCardFeed,
391396
reportsToArchive,
392397
transactionViolations,
393398
reimbursementAccountError,
@@ -407,6 +412,9 @@ function deleteWorkspace(params: DeleteWorkspaceActionParams) {
407412
OnyxUpdate<
408413
| typeof ONYXKEYS.COLLECTION.POLICY
409414
| typeof ONYXKEYS.COLLECTION.SHARED_NVP_PRIVATE_DOMAIN_MEMBER
415+
| typeof ONYXKEYS.COLLECTION.PRIVATE_EXPENSIFY_CARD_SETTINGS
416+
| typeof ONYXKEYS.COLLECTION.LAST_SELECTED_FEED
417+
| typeof ONYXKEYS.COLLECTION.LAST_SELECTED_EXPENSIFY_CARD_FEED
410418
| typeof ONYXKEYS.REIMBURSEMENT_ACCOUNT
411419
| typeof ONYXKEYS.NVP_ACTIVE_POLICY_ID
412420
| typeof ONYXKEYS.COLLECTION.REPORT
@@ -431,6 +439,21 @@ function deleteWorkspace(params: DeleteWorkspaceActionParams) {
431439
key: `${ONYXKEYS.COLLECTION.SHARED_NVP_PRIVATE_DOMAIN_MEMBER}${workspaceAccountID}`,
432440
value: null,
433441
},
442+
{
443+
onyxMethod: Onyx.METHOD.MERGE,
444+
key: `${ONYXKEYS.COLLECTION.PRIVATE_EXPENSIFY_CARD_SETTINGS}${workspaceAccountID}`,
445+
value: {pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE},
446+
},
447+
{
448+
onyxMethod: Onyx.METHOD.SET,
449+
key: `${ONYXKEYS.COLLECTION.LAST_SELECTED_FEED}${policyID}`,
450+
value: null,
451+
},
452+
{
453+
onyxMethod: Onyx.METHOD.SET,
454+
key: `${ONYXKEYS.COLLECTION.LAST_SELECTED_EXPENSIFY_CARD_FEED}${policyID}`,
455+
value: null,
456+
},
434457
...(!hasActiveChatEnabledPolicies(filteredPolicies, true)
435458
? [
436459
{
@@ -450,6 +473,9 @@ function deleteWorkspace(params: DeleteWorkspaceActionParams) {
450473
| typeof ONYXKEYS.REIMBURSEMENT_ACCOUNT
451474
| typeof ONYXKEYS.COLLECTION.POLICY
452475
| typeof ONYXKEYS.COLLECTION.SHARED_NVP_PRIVATE_DOMAIN_MEMBER
476+
| typeof ONYXKEYS.COLLECTION.PRIVATE_EXPENSIFY_CARD_SETTINGS
477+
| typeof ONYXKEYS.COLLECTION.LAST_SELECTED_FEED
478+
| typeof ONYXKEYS.COLLECTION.LAST_SELECTED_EXPENSIFY_CARD_FEED
453479
| typeof ONYXKEYS.NVP_ACTIVE_POLICY_ID
454480
| typeof ONYXKEYS.COLLECTION.REPORT
455481
| typeof ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS
@@ -478,6 +504,21 @@ function deleteWorkspace(params: DeleteWorkspaceActionParams) {
478504
key: `${ONYXKEYS.COLLECTION.SHARED_NVP_PRIVATE_DOMAIN_MEMBER}${workspaceAccountID}`,
479505
value: policyCardFeeds ?? null,
480506
},
507+
{
508+
onyxMethod: Onyx.METHOD.MERGE,
509+
key: `${ONYXKEYS.COLLECTION.PRIVATE_EXPENSIFY_CARD_SETTINGS}${workspaceAccountID}`,
510+
value: {pendingAction: null},
511+
},
512+
{
513+
onyxMethod: Onyx.METHOD.SET,
514+
key: `${ONYXKEYS.COLLECTION.LAST_SELECTED_FEED}${policyID}`,
515+
value: lastSelectedFeed ?? null,
516+
},
517+
{
518+
onyxMethod: Onyx.METHOD.SET,
519+
key: `${ONYXKEYS.COLLECTION.LAST_SELECTED_EXPENSIFY_CARD_FEED}${policyID}`,
520+
value: lastSelectedExpensifyCardFeed ?? null,
521+
},
481522
];
482523

483524
if (policyID === activePolicyID) {

src/pages/workspace/WorkspaceOverviewPage.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,8 @@ function WorkspaceOverviewPage({policyDraft, policy: policyProp, route}: Workspa
117117
// We need this to update translation for deleting a workspace when it has third party card feeds or expensify card assigned.
118118
const workspaceAccountID = policy?.workspaceAccountID ?? CONST.DEFAULT_NUMBER_ID;
119119
const [cardFeeds, , defaultCardFeeds] = useCardFeeds(policyID);
120+
const [lastSelectedFeed] = useOnyx(`${ONYXKEYS.COLLECTION.LAST_SELECTED_FEED}${policyID}`);
121+
const [lastSelectedExpensifyCardFeed] = useOnyx(`${ONYXKEYS.COLLECTION.LAST_SELECTED_EXPENSIFY_CARD_FEED}${policyID}`);
120122
const [cardsList] = useOnyx(`${ONYXKEYS.COLLECTION.WORKSPACE_CARDS_LIST}${workspaceAccountID}_${CONST.EXPENSIFY_CARD.BANK}`, {
121123
selector: filterInactiveCards,
122124
});
@@ -265,6 +267,8 @@ function WorkspaceOverviewPage({policyDraft, policy: policyProp, route}: Workspa
265267
policyName,
266268
lastAccessedWorkspacePolicyID,
267269
policyCardFeeds: defaultCardFeeds,
270+
lastSelectedFeed,
271+
lastSelectedExpensifyCardFeed,
268272
reportsToArchive,
269273
transactionViolations,
270274
reimbursementAccountError,

src/pages/workspace/WorkspacesListPage.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,8 @@ function WorkspacesListPage() {
187187
// We need this to update translation for deleting a workspace when it has third party card feeds or expensify card assigned.
188188
const workspaceAccountID = policyToDelete?.workspaceAccountID ?? CONST.DEFAULT_NUMBER_ID;
189189
const [cardFeeds, , defaultCardFeeds] = useCardFeeds(policyIDToDelete);
190+
const [lastSelectedFeed] = useOnyx(`${ONYXKEYS.COLLECTION.LAST_SELECTED_FEED}${policyIDToDelete}`);
191+
const [lastSelectedExpensifyCardFeed] = useOnyx(`${ONYXKEYS.COLLECTION.LAST_SELECTED_EXPENSIFY_CARD_FEED}${policyIDToDelete}`);
190192
const [cardsList] = useOnyx(`${ONYXKEYS.COLLECTION.WORKSPACE_CARDS_LIST}${workspaceAccountID}_${CONST.EXPENSIFY_CARD.BANK}`, {
191193
selector: filterInactiveCards,
192194
});
@@ -235,6 +237,8 @@ function WorkspacesListPage() {
235237
policyName: policyNameToDelete,
236238
lastAccessedWorkspacePolicyID,
237239
policyCardFeeds: defaultCardFeeds,
240+
lastSelectedFeed,
241+
lastSelectedExpensifyCardFeed,
238242
reportsToArchive,
239243
transactionViolations,
240244
reimbursementAccountError,

src/pages/workspace/expensifyCard/WorkspaceExpensifyCardFeedSelectorPage.tsx

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -114,22 +114,26 @@ function WorkspaceExpensifyCardFeedSelectorPage({route}: WorkspaceExpensifyCardF
114114
Navigation.navigate(ROUTES.WORKSPACE_EXPENSIFY_CARD_BANK_ACCOUNT.getRoute(policyID));
115115
};
116116

117-
const toListItem = (entry: ExpensifyCardFeedEntry, isOtherWorkspaceSection: boolean): ExpensifyFeedListItem => ({
118-
value: entry.fundID,
119-
text: getExpensifyCardFeedDescription(entry.settings, policies),
120-
keyForList: entry.fundID.toString(),
121-
isSelected: entry.fundID === lastSelectedExpensifyCardFeedID,
122-
isDisabled: isOtherWorkspaceSection && isOffline,
123-
errors: feedWithError?.fundID === entry.fundID ? feedWithError.error : undefined,
124-
leftElement: (
125-
<Icon
126-
src={illustrations.ExpensifyCardImage}
127-
height={variables.cardIconHeight}
128-
width={variables.cardIconWidth}
129-
additionalStyles={[styles.mr3, styles.cardIcon]}
130-
/>
131-
),
132-
});
117+
const toListItem = (entry: ExpensifyCardFeedEntry, isOtherWorkspaceSection: boolean): ExpensifyFeedListItem => {
118+
const isFeedPendingDelete = entry.settings.pendingAction === CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE;
119+
return {
120+
value: entry.fundID,
121+
text: getExpensifyCardFeedDescription(entry.settings, policies),
122+
keyForList: entry.fundID.toString(),
123+
isSelected: entry.fundID === lastSelectedExpensifyCardFeedID,
124+
isDisabled: isFeedPendingDelete || (isOtherWorkspaceSection && isOffline),
125+
pendingAction: entry.settings.pendingAction,
126+
errors: feedWithError?.fundID === entry.fundID ? feedWithError.error : undefined,
127+
leftElement: (
128+
<Icon
129+
src={illustrations.ExpensifyCardImage}
130+
height={variables.cardIconHeight}
131+
width={variables.cardIconWidth}
132+
additionalStyles={[styles.mr3, styles.cardIcon]}
133+
/>
134+
),
135+
};
136+
};
133137

134138
const goBack = () => Navigation.goBack(ROUTES.WORKSPACE_EXPENSIFY_CARD.getRoute(policyID));
135139

tests/actions/IOUTest/ReportWorkflowTest.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -597,6 +597,8 @@ describe('actions/IOU/ReportWorkflow', () => {
597597
policyName: policy.name,
598598
lastAccessedWorkspacePolicyID: undefined,
599599
policyCardFeeds: undefined,
600+
lastSelectedFeed: undefined,
601+
lastSelectedExpensifyCardFeed: undefined,
600602
reportsToArchive: reportToArchive,
601603
transactionViolations: undefined,
602604
reimbursementAccountError: undefined,

tests/actions/PolicyTest.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3355,6 +3355,8 @@ describe('actions/Policy', () => {
33553355
policyName: fakePolicy.name,
33563356
lastAccessedWorkspacePolicyID: undefined,
33573357
policyCardFeeds: undefined,
3358+
lastSelectedFeed: undefined,
3359+
lastSelectedExpensifyCardFeed: undefined,
33583360
reportsToArchive: [fakeReport],
33593361
transactionViolations: undefined,
33603362
reimbursementAccountError: {},
@@ -3449,6 +3451,8 @@ describe('actions/Policy', () => {
34493451
policyName: 'test',
34503452
lastAccessedWorkspacePolicyID: undefined,
34513453
policyCardFeeds: undefined,
3454+
lastSelectedFeed: undefined,
3455+
lastSelectedExpensifyCardFeed: undefined,
34523456
reportsToArchive: [expenseChatReport],
34533457
transactionViolations: {
34543458
// eslint-disable-next-line @typescript-eslint/naming-convention
@@ -3513,6 +3517,8 @@ describe('actions/Policy', () => {
35133517
policyName: randomGroupPolicy.name,
35143518
lastAccessedWorkspacePolicyID: undefined,
35153519
policyCardFeeds: undefined,
3520+
lastSelectedFeed: undefined,
3521+
lastSelectedExpensifyCardFeed: undefined,
35163522
reportsToArchive: [],
35173523
transactionViolations: undefined,
35183524
reimbursementAccountError: undefined,
@@ -3552,6 +3558,8 @@ describe('actions/Policy', () => {
35523558
policyName: policyToDelete.name,
35533559
lastAccessedWorkspacePolicyID,
35543560
policyCardFeeds: undefined,
3561+
lastSelectedFeed: undefined,
3562+
lastSelectedExpensifyCardFeed: undefined,
35553563
reportsToArchive: [],
35563564
transactionViolations: undefined,
35573565
reimbursementAccountError: undefined,
@@ -3593,6 +3601,8 @@ describe('actions/Policy', () => {
35933601
policyName: policyToDelete.name,
35943602
lastAccessedWorkspacePolicyID,
35953603
policyCardFeeds: undefined,
3604+
lastSelectedFeed: undefined,
3605+
lastSelectedExpensifyCardFeed: undefined,
35963606
reportsToArchive: [],
35973607
transactionViolations: undefined,
35983608
reimbursementAccountError: undefined,
@@ -3639,6 +3649,8 @@ describe('actions/Policy', () => {
36393649
policyName: fakePolicy.name,
36403650
lastAccessedWorkspacePolicyID: undefined,
36413651
policyCardFeeds: undefined,
3652+
lastSelectedFeed: undefined,
3653+
lastSelectedExpensifyCardFeed: undefined,
36423654
reportsToArchive: [fakeReport],
36433655
transactionViolations: undefined,
36443656
reimbursementAccountError: undefined,
@@ -3679,6 +3691,8 @@ describe('actions/Policy', () => {
36793691
policyName: fakePolicy.name,
36803692
lastAccessedWorkspacePolicyID: undefined,
36813693
policyCardFeeds: undefined,
3694+
lastSelectedFeed: undefined,
3695+
lastSelectedExpensifyCardFeed: undefined,
36823696
reportsToArchive: [fakeReport],
36833697
transactionViolations: undefined,
36843698
reimbursementAccountError: undefined,
@@ -3720,6 +3734,8 @@ describe('actions/Policy', () => {
37203734
policyName: fakePolicy.name,
37213735
lastAccessedWorkspacePolicyID: undefined,
37223736
policyCardFeeds: undefined,
3737+
lastSelectedFeed: undefined,
3738+
lastSelectedExpensifyCardFeed: undefined,
37233739
reportsToArchive: [fakeReport],
37243740
transactionViolations: undefined,
37253741
reimbursementAccountError: undefined,

0 commit comments

Comments
 (0)