From 3056dc09a6d3f731ec32e07ef82e5de0c0c95654 Mon Sep 17 00:00:00 2001 From: Agata Kosior Date: Wed, 6 Nov 2024 18:56:23 +0700 Subject: [PATCH 1/5] fix: change offline pattern for unassigning cards --- .../API/parameters/UnassignCompanyCard.ts | 2 +- src/libs/actions/CompanyCards.ts | 53 ++++++++++++++++++- .../WorkspaceCompanyCardDetailsPage.tsx | 2 +- 3 files changed, 53 insertions(+), 4 deletions(-) diff --git a/src/libs/API/parameters/UnassignCompanyCard.ts b/src/libs/API/parameters/UnassignCompanyCard.ts index 10e04aa13f82..d433d9e537c3 100644 --- a/src/libs/API/parameters/UnassignCompanyCard.ts +++ b/src/libs/API/parameters/UnassignCompanyCard.ts @@ -1,6 +1,6 @@ type UnassignCompanyCard = { authToken?: string | null; - cardID: string; + cardID: number; }; export default UnassignCompanyCard; diff --git a/src/libs/actions/CompanyCards.ts b/src/libs/actions/CompanyCards.ts index 2955a62f28c7..7812c6d62f40 100644 --- a/src/libs/actions/CompanyCards.ts +++ b/src/libs/actions/CompanyCards.ts @@ -17,6 +17,7 @@ import * as PolicyUtils from '@libs/PolicyUtils'; import * as ReportUtils from '@libs/ReportUtils'; import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; +import type {Card} from '@src/types/onyx'; import type {AssignCard, AssignCardData} from '@src/types/onyx/AssignCard'; import type {AddNewCardFeedData, AddNewCardFeedStep, CompanyCardFeed} from '@src/types/onyx/CardFeeds'; import type {OnyxData} from '@src/types/onyx/Request'; @@ -232,8 +233,9 @@ function assignWorkspaceCompanyCard(policyID: string, data?: Partial { setIsUnassignModalVisible(false); - CompanyCards.unassignWorkspaceCompanyCard(workspaceAccountID, cardID, bank); + CompanyCards.unassignWorkspaceCompanyCard(workspaceAccountID, bank, card); Navigation.goBack(); }; From c1999bf2861e42b729109fdc1af29b10ecfc9235 Mon Sep 17 00:00:00 2001 From: Agata Kosior Date: Wed, 6 Nov 2024 18:57:59 +0700 Subject: [PATCH 2/5] fix: update cardID param for consistency --- src/libs/API/parameters/UpdateCompanyCard.ts | 2 +- src/libs/actions/CompanyCards.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libs/API/parameters/UpdateCompanyCard.ts b/src/libs/API/parameters/UpdateCompanyCard.ts index 3d5eb3c580cb..113f0e1d7511 100644 --- a/src/libs/API/parameters/UpdateCompanyCard.ts +++ b/src/libs/API/parameters/UpdateCompanyCard.ts @@ -1,6 +1,6 @@ type UpdateCompanyCard = { authToken?: string | null; - cardID: string; + cardID: number; }; export default UpdateCompanyCard; diff --git a/src/libs/actions/CompanyCards.ts b/src/libs/actions/CompanyCards.ts index 7812c6d62f40..fb7940f7f2eb 100644 --- a/src/libs/actions/CompanyCards.ts +++ b/src/libs/actions/CompanyCards.ts @@ -427,7 +427,7 @@ function updateWorkspaceCompanyCard(workspaceAccountID: number, cardID: string, const parameters = { authToken, - cardID, + cardID: Number(cardID), }; API.write(WRITE_COMMANDS.UPDATE_COMPANY_CARD, parameters, {optimisticData, finallyData, failureData}); From 9e2771a55b7fb451641b3f4fa8c24e35e695f73f Mon Sep 17 00:00:00 2001 From: Agata Kosior Date: Wed, 6 Nov 2024 20:39:38 +0700 Subject: [PATCH 3/5] fix: disable Update card when offline --- .../workspace/companyCards/WorkspaceCompanyCardDetailsPage.tsx | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/pages/workspace/companyCards/WorkspaceCompanyCardDetailsPage.tsx b/src/pages/workspace/companyCards/WorkspaceCompanyCardDetailsPage.tsx index dbf408486231..b7f27baa42d4 100644 --- a/src/pages/workspace/companyCards/WorkspaceCompanyCardDetailsPage.tsx +++ b/src/pages/workspace/companyCards/WorkspaceCompanyCardDetailsPage.tsx @@ -14,6 +14,7 @@ import OfflineWithFeedback from '@components/OfflineWithFeedback'; import ScreenWrapper from '@components/ScreenWrapper'; import ScrollView from '@components/ScrollView'; import useLocalize from '@hooks/useLocalize'; +import useNetwork from '@hooks/useNetwork'; import usePolicy from '@hooks/usePolicy'; import useTheme from '@hooks/useTheme'; import useThemeStyles from '@hooks/useThemeStyles'; @@ -48,6 +49,7 @@ function WorkspaceCompanyCardDetailsPage({route}: WorkspaceCompanyCardDetailsPag const {translate} = useLocalize(); const styles = useThemeStyles(); const theme = useTheme(); + const {isOffline} = useNetwork(); const accountingIntegrations = Object.values(CONST.POLICY.CONNECTIONS.NAME); const connectedIntegration = getConnectedIntegration(policy, accountingIntegrations) ?? connectionSyncProgress?.connectionName; @@ -168,6 +170,7 @@ function WorkspaceCompanyCardDetailsPage({route}: WorkspaceCompanyCardDetailsPag > Date: Wed, 6 Nov 2024 20:57:15 +0700 Subject: [PATCH 4/5] fix: minor fix --- src/libs/actions/CompanyCards.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/libs/actions/CompanyCards.ts b/src/libs/actions/CompanyCards.ts index fb7940f7f2eb..eb563ef83843 100644 --- a/src/libs/actions/CompanyCards.ts +++ b/src/libs/actions/CompanyCards.ts @@ -276,19 +276,19 @@ function unassignWorkspaceCompanyCard(workspaceAccountID: number, bankName: stri }, }, }, + ], + + successData: [ { onyxMethod: Onyx.METHOD.MERGE, - key: ONYXKEYS.CARD_LIST, + key: `${ONYXKEYS.COLLECTION.WORKSPACE_CARDS_LIST}${workspaceAccountID}_${bankName}`, value: { [cardID]: null, }, }, - ], - - successData: [ { onyxMethod: Onyx.METHOD.MERGE, - key: `${ONYXKEYS.COLLECTION.WORKSPACE_CARDS_LIST}${workspaceAccountID}_${bankName}`, + key: ONYXKEYS.CARD_LIST, value: { [cardID]: null, }, From 39b17d149cfc3f53514bba21ac6cd5f8a308422a Mon Sep 17 00:00:00 2001 From: Agata Kosior Date: Wed, 6 Nov 2024 23:32:18 +0700 Subject: [PATCH 5/5] fix: remove unnecessary code --- src/libs/actions/CompanyCards.ts | 17 ----------------- 1 file changed, 17 deletions(-) diff --git a/src/libs/actions/CompanyCards.ts b/src/libs/actions/CompanyCards.ts index eb563ef83843..b66967cb603f 100644 --- a/src/libs/actions/CompanyCards.ts +++ b/src/libs/actions/CompanyCards.ts @@ -277,23 +277,6 @@ function unassignWorkspaceCompanyCard(workspaceAccountID: number, bankName: stri }, }, ], - - successData: [ - { - onyxMethod: Onyx.METHOD.MERGE, - key: `${ONYXKEYS.COLLECTION.WORKSPACE_CARDS_LIST}${workspaceAccountID}_${bankName}`, - value: { - [cardID]: null, - }, - }, - { - onyxMethod: Onyx.METHOD.MERGE, - key: ONYXKEYS.CARD_LIST, - value: { - [cardID]: null, - }, - }, - ], }; const parameters = {