From 7649dedce189a1b9559fdd64d96bf6a3cd89e36a Mon Sep 17 00:00:00 2001 From: VickyStash Date: Thu, 14 Nov 2024 09:33:14 +0100 Subject: [PATCH] Use one approach for all feed updates --- src/libs/actions/CompanyCards.ts | 20 ++++++-------------- 1 file changed, 6 insertions(+), 14 deletions(-) diff --git a/src/libs/actions/CompanyCards.ts b/src/libs/actions/CompanyCards.ts index ba1385e6483b..4614a9dd2053 100644 --- a/src/libs/actions/CompanyCards.ts +++ b/src/libs/actions/CompanyCards.ts @@ -154,7 +154,7 @@ function setWorkspaceCompanyCardTransactionLiability(workspaceAccountID: number, function deleteWorkspaceCompanyCardFeed(policyID: string, workspaceAccountID: number, bankName: CompanyCardFeed) { const authToken = NetworkStore.getAuthToken(); const isCustomFeed = CardUtils.isCustomFeed(bankName); - const feedUpdates = isCustomFeed ? {companyCards: {[bankName]: null}} : {oAuthAccountDetails: {[bankName]: null}}; + const feedUpdates = {[bankName]: null}; const onyxData: OnyxData = { optimisticData: [ @@ -163,7 +163,7 @@ function deleteWorkspaceCompanyCardFeed(policyID: string, workspaceAccountID: nu key: `${ONYXKEYS.COLLECTION.SHARED_NVP_PRIVATE_DOMAIN_MEMBER}${workspaceAccountID}`, value: { settings: { - ...feedUpdates, + ...(isCustomFeed ? {companyCards: feedUpdates} : {oAuthAccountDetails: feedUpdates}), companyCardNicknames: { [bankName]: null, }, @@ -293,6 +293,8 @@ function unassignWorkspaceCompanyCard(workspaceAccountID: number, bankName: stri function updateWorkspaceCompanyCard(workspaceAccountID: number, cardID: string, bankName: CompanyCardFeed) { const authToken = NetworkStore.getAuthToken(); const isCustomFeed = CardUtils.isCustomFeed(bankName); + const optimisticFeedUpdates = {[bankName]: {errors: null}}; + const failureFeedUpdates = {[bankName]: {errors: {error: CONST.COMPANY_CARDS.CONNECTION_ERROR}}}; const optimisticData: OnyxUpdate[] = [ { @@ -329,7 +331,7 @@ function updateWorkspaceCompanyCard(workspaceAccountID: number, cardID: string, onyxMethod: Onyx.METHOD.MERGE, key: `${ONYXKEYS.COLLECTION.SHARED_NVP_PRIVATE_DOMAIN_MEMBER}${workspaceAccountID}`, value: { - settings: isCustomFeed ? {companyCards: {[bankName]: {errors: null}}} : {oAuthAccountDetails: {[bankName]: {errors: null}}}, + settings: isCustomFeed ? {companyCards: optimisticFeedUpdates} : {oAuthAccountDetails: optimisticFeedUpdates}, }, }, ]; @@ -396,17 +398,7 @@ function updateWorkspaceCompanyCard(workspaceAccountID: number, cardID: string, onyxMethod: Onyx.METHOD.MERGE, key: `${ONYXKEYS.COLLECTION.SHARED_NVP_PRIVATE_DOMAIN_MEMBER}${workspaceAccountID}`, value: { - settings: isCustomFeed - ? { - companyCards: { - [bankName]: {errors: {error: CONST.COMPANY_CARDS.CONNECTION_ERROR}}, - }, - } - : { - oAuthAccountDetails: { - [bankName]: {errors: {error: CONST.COMPANY_CARDS.CONNECTION_ERROR}}, - }, - }, + settings: isCustomFeed ? {companyCards: failureFeedUpdates} : {oAuthAccountDetails: failureFeedUpdates}, }, }, ];