From 3afbbdc1332bfd51b251494e802beaafad4a301d Mon Sep 17 00:00:00 2001 From: VickyStash Date: Thu, 26 Sep 2024 09:36:20 +0200 Subject: [PATCH 01/36] Implement AssignCard API call --- .../API/parameters/AssignCompanyCardParams.ts | 10 +++++++++ src/libs/API/parameters/index.ts | 1 + src/libs/API/types.ts | 2 ++ src/libs/actions/Policy/Policy.ts | 21 +++++++++++++++++++ .../assignCard/AssignCardFeedPage.tsx | 4 ++-- .../assignCard/CardSelectionStep.tsx | 20 +++++++++--------- .../assignCard/ConfirmationStep.tsx | 9 +++++++- src/types/onyx/AssignCard.ts | 6 +++--- 8 files changed, 57 insertions(+), 16 deletions(-) create mode 100644 src/libs/API/parameters/AssignCompanyCardParams.ts diff --git a/src/libs/API/parameters/AssignCompanyCardParams.ts b/src/libs/API/parameters/AssignCompanyCardParams.ts new file mode 100644 index 000000000000..6139bd5708f6 --- /dev/null +++ b/src/libs/API/parameters/AssignCompanyCardParams.ts @@ -0,0 +1,10 @@ +type AssignCompanyCardParams = { + policyID: string; + bankName: string; + encryptedCardNumber: string; + email: string; + startDate: string; + // reportActionID: string; +}; + +export default AssignCompanyCardParams; diff --git a/src/libs/API/parameters/index.ts b/src/libs/API/parameters/index.ts index e5cde1b77be7..32a4286f1755 100644 --- a/src/libs/API/parameters/index.ts +++ b/src/libs/API/parameters/index.ts @@ -321,6 +321,7 @@ export type {default as UpdateCardSettlementAccountParams} from './UpdateCardSet export type {default as SetCompanyCardFeedName} from './SetCompanyCardFeedName'; export type {default as DeleteCompanyCardFeed} from './DeleteCompanyCardFeed'; export type {default as SetCompanyCardTransactionLiability} from './SetCompanyCardTransactionLiability'; +export type {default as AssignCompanyCardParams} from './AssignCompanyCardParams'; export type {default as UnassignCompanyCard} from './UnassignCompanyCard'; export type {default as UpdateCompanyCard} from './UpdateCompanyCard'; export type {default as UpdateCompanyCardNameParams} from './UpdateCompanyCardNameParams'; diff --git a/src/libs/API/types.ts b/src/libs/API/types.ts index 8e35a0cb1984..9a2da64c115c 100644 --- a/src/libs/API/types.ts +++ b/src/libs/API/types.ts @@ -402,6 +402,7 @@ const WRITE_COMMANDS = { SET_COMPANY_CARD_FEED_NAME: 'SetFeedName', DELETE_COMPANY_CARD_FEED: 'RemoveFeed', SET_COMPANY_CARD_TRANSACTION_LIABILITY: 'SetFeedTransactionLiability', + ASSIGN_COMPANY_CARD: 'AssignCard', UNASSIGN_COMPANY_CARD: 'UnassignCard', UPDATE_COMPANY_CARD: 'SyncCard', UPDATE_COMPANY_CARD_NAME: 'SetCardName', @@ -466,6 +467,7 @@ type WriteCommandParameters = { [WRITE_COMMANDS.UPDATE_PERSONAL_DETAILS_FOR_WALLET]: Parameters.UpdatePersonalDetailsForWalletParams; [WRITE_COMMANDS.SET_COMPANY_CARD_FEED_NAME]: Parameters.SetCompanyCardFeedName; [WRITE_COMMANDS.DELETE_COMPANY_CARD_FEED]: Parameters.DeleteCompanyCardFeed; + [WRITE_COMMANDS.ASSIGN_COMPANY_CARD]: Parameters.AssignCompanyCardParams; [WRITE_COMMANDS.UNASSIGN_COMPANY_CARD]: Parameters.UnassignCompanyCard; [WRITE_COMMANDS.UPDATE_COMPANY_CARD]: Parameters.UpdateCompanyCard; [WRITE_COMMANDS.UPDATE_COMPANY_CARD_NAME]: Parameters.UpdateCompanyCardNameParams; diff --git a/src/libs/actions/Policy/Policy.ts b/src/libs/actions/Policy/Policy.ts index 2123f2a47764..e1f0d1b8b045 100644 --- a/src/libs/actions/Policy/Policy.ts +++ b/src/libs/actions/Policy/Policy.ts @@ -8,6 +8,7 @@ import type {ReportExportType} from '@components/ButtonWithDropdownMenu/types'; import * as API from '@libs/API'; import type { AddBillingCardAndRequestWorkspaceOwnerChangeParams, + AssignCompanyCardParams, CreateWorkspaceFromIOUPaymentParams, CreateWorkspaceParams, DeleteWorkspaceAvatarParams, @@ -88,6 +89,7 @@ import type { TaxRatesWithDefault, Transaction, } from '@src/types/onyx'; +import type {AssignCardData} from '@src/types/onyx/AssignCard'; import type {Errors} from '@src/types/onyx/OnyxCommon'; import type {Attributes, CompanyAddress, CustomUnit, NetSuiteCustomList, NetSuiteCustomSegment, Rate, TaxRate} from '@src/types/onyx/Policy'; import type {OnyxData} from '@src/types/onyx/Request'; @@ -4540,6 +4542,24 @@ function deleteWorkspaceCompanyCardFeed(policyID: string, workspaceAccountID: nu API.write(WRITE_COMMANDS.DELETE_COMPANY_CARD_FEED, parameters, onyxData); } +function assignWorkspaceCompanyCard(policyID: string, data?: Partial) { + if (!data) { + return; + } + const {bankName = '', email = '', encryptedCardNumber = '', startDate = ''} = data; + + const parameters: AssignCompanyCardParams = { + policyID, + bankName, + encryptedCardNumber, + email, + startDate, + // reportActionID, + }; + + API.write(WRITE_COMMANDS.ASSIGN_COMPANY_CARD, parameters); +} + function unassignWorkspaceCompanyCard(workspaceAccountID: number, cardID: string, bankName: string) { const authToken = NetworkStore.getAuthToken(); @@ -4879,6 +4899,7 @@ export { deleteWorkspaceCompanyCardFeed, setWorkspaceCompanyCardTransactionLiability, openPolicyCompanyCardsPage, + assignWorkspaceCompanyCard, unassignWorkspaceCompanyCard, updateWorkspaceCompanyCard, updateCompanyCardName, diff --git a/src/pages/workspace/companyCards/assignCard/AssignCardFeedPage.tsx b/src/pages/workspace/companyCards/assignCard/AssignCardFeedPage.tsx index 66ceaaf914c4..03e9d58a71ab 100644 --- a/src/pages/workspace/companyCards/assignCard/AssignCardFeedPage.tsx +++ b/src/pages/workspace/companyCards/assignCard/AssignCardFeedPage.tsx @@ -25,7 +25,7 @@ function AssignCardFeedPage({route, policy}: AssignCardFeedPageProps) { const feed = route.params?.feed; useEffect(() => { - CompanyCards.setAssignCardStepAndData({data: {feed}}); + CompanyCards.setAssignCardStepAndData({data: {bankName: feed}}); }, [feed]); switch (currentStep) { @@ -36,7 +36,7 @@ function AssignCardFeedPage({route, policy}: AssignCardFeedPageProps) { case CONST.COMPANY_CARD.STEP.TRANSACTION_START_DATE: return ; case CONST.COMPANY_CARD.STEP.CONFIRMATION: - return ; + return ; default: return ; } diff --git a/src/pages/workspace/companyCards/assignCard/CardSelectionStep.tsx b/src/pages/workspace/companyCards/assignCard/CardSelectionStep.tsx index b31780d54fa2..5947d382029f 100644 --- a/src/pages/workspace/companyCards/assignCard/CardSelectionStep.tsx +++ b/src/pages/workspace/companyCards/assignCard/CardSelectionStep.tsx @@ -23,21 +23,21 @@ import ROUTES from '@src/ROUTES'; type MockedCard = { key: string; - cardNumber: string; + encryptedCardNumber: string; }; const mockedCardList = [ { key: '1', - cardNumber: '123412XXXXXX1234', + encryptedCardNumber: '123412XXXXXX1234', }, { key: '2', - cardNumber: '123412XXXXXX1235', + encryptedCardNumber: '123412XXXXXX1235', }, { key: '3', - cardNumber: '123412XXXXXX1236', + encryptedCardNumber: '123412XXXXXX1236', }, ]; @@ -62,7 +62,7 @@ function CardSelectionStep({feed}: CardSelectionStepProps) { const isEditing = assignCard?.isEditing; const assignee = assignCard?.data?.email ?? ''; - const [cardSelected, setCardSelected] = useState(assignCard?.data?.cardName ?? ''); + const [cardSelected, setCardSelected] = useState(assignCard?.data?.encryptedCardNumber ?? ''); const [shouldShowError, setShouldShowError] = useState(false); const handleBackButtonPress = () => { @@ -88,7 +88,7 @@ function CardSelectionStep({feed}: CardSelectionStepProps) { } CompanyCards.setAssignCardStepAndData({ currentStep: isEditing ? CONST.COMPANY_CARD.STEP.CONFIRMATION : CONST.COMPANY_CARD.STEP.TRANSACTION_START_DATE, - data: {cardName: cardSelected}, + data: {encryptedCardNumber: cardSelected}, isEditing: false, }); }; @@ -97,10 +97,10 @@ function CardSelectionStep({feed}: CardSelectionStepProps) { const mockedCards = !Object.values(CONST.COMPANY_CARD.FEED_BANK_NAME).some((value) => value === feed) ? mockedCardListEmpty : mockedCardList; const cardListOptions = mockedCards.map((item) => ({ - keyForList: item?.cardNumber, - value: item?.cardNumber, - text: item?.cardNumber, - isSelected: cardSelected === item?.cardNumber, + keyForList: item?.encryptedCardNumber, + value: item?.encryptedCardNumber, + text: item?.encryptedCardNumber, + isSelected: cardSelected === item?.encryptedCardNumber, leftElement: ( { + Policy.assignWorkspaceCompanyCard(policyID, data); Navigation.goBack(); CompanyCards.clearAssignCardStepAndData(); }; diff --git a/src/types/onyx/AssignCard.ts b/src/types/onyx/AssignCard.ts index 0b2592d15079..690900fe5f74 100644 --- a/src/types/onyx/AssignCard.ts +++ b/src/types/onyx/AssignCard.ts @@ -6,14 +6,14 @@ type AssignCardStep = ValueOf; /** Data required to be sent to issue a new card */ type AssignCardData = { - /** The email address of the asignee */ + /** The email address of the assignee */ email: string; /** Number of the selected card */ - cardNumber: string; + encryptedCardNumber: string; /** The name of the feed */ - feed: string; + bankName: string; /** The name of the card */ cardName: string; From 8cea638bc766e0f362d1bbc31be1918860099e25 Mon Sep 17 00:00:00 2001 From: VickyStash Date: Thu, 26 Sep 2024 10:09:23 +0200 Subject: [PATCH 02/36] Resolve TODO --- .../companyCards/WorkspaceCompanyCardsListHeaderButtons.tsx | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/pages/workspace/companyCards/WorkspaceCompanyCardsListHeaderButtons.tsx b/src/pages/workspace/companyCards/WorkspaceCompanyCardsListHeaderButtons.tsx index b71f6583e25a..aeb75603ce20 100644 --- a/src/pages/workspace/companyCards/WorkspaceCompanyCardsListHeaderButtons.tsx +++ b/src/pages/workspace/companyCards/WorkspaceCompanyCardsListHeaderButtons.tsx @@ -57,8 +57,7 @@ function WorkspaceCompanyCardsListHeaderButtons({policyID, selectedFeed}: Worksp