Skip to content

Commit

Permalink
Use one approach for all feed updates
Browse files Browse the repository at this point in the history
  • Loading branch information
VickyStash committed Nov 14, 2024
1 parent 07cb200 commit 7649ded
Showing 1 changed file with 6 additions and 14 deletions.
20 changes: 6 additions & 14 deletions src/libs/actions/CompanyCards.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: [
Expand All @@ -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,
},
Expand Down Expand Up @@ -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[] = [
{
Expand Down Expand Up @@ -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},
},
},
];
Expand Down Expand Up @@ -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},
},
},
];
Expand Down

0 comments on commit 7649ded

Please sign in to comment.