From d63e14bd375fa282df449c4b890eb14ba8da81c7 Mon Sep 17 00:00:00 2001 From: Agata Kosior Date: Mon, 22 Jul 2024 16:01:32 +0200 Subject: [PATCH] feat: startIssueNewCardFlow api call --- .../API/parameters/StartIssueNewCardFlowParams.ts | 5 +++++ src/libs/API/parameters/index.ts | 1 + src/libs/API/types.ts | 2 ++ src/libs/actions/Card.ts | 12 +++++++++++- .../workspace/card/issueNew/IssueNewCardPage.tsx | 7 +++++-- 5 files changed, 24 insertions(+), 3 deletions(-) create mode 100644 src/libs/API/parameters/StartIssueNewCardFlowParams.ts diff --git a/src/libs/API/parameters/StartIssueNewCardFlowParams.ts b/src/libs/API/parameters/StartIssueNewCardFlowParams.ts new file mode 100644 index 000000000000..8ed04b756a10 --- /dev/null +++ b/src/libs/API/parameters/StartIssueNewCardFlowParams.ts @@ -0,0 +1,5 @@ +type StartIssueNewCardFlowParams = { + policyID: string; +}; + +export default StartIssueNewCardFlowParams; diff --git a/src/libs/API/parameters/index.ts b/src/libs/API/parameters/index.ts index 53705e1f502d..b220ced122a5 100644 --- a/src/libs/API/parameters/index.ts +++ b/src/libs/API/parameters/index.ts @@ -265,3 +265,4 @@ export type {default as UpdateNetSuiteCustomersJobsParams} from './UpdateNetSuit export type {default as CopyExistingPolicyConnectionParams} from './CopyExistingPolicyConnectionParams'; export type {default as ExportSearchItemsToCSVParams} from './ExportSearchItemsToCSVParams'; export type {default as UpdateExpensifyCardLimitParams} from './UpdateExpensifyCardLimitParams'; +export type {default as StartIssueNewCardFlowParams} from './StartIssueNewCardFlowParams'; diff --git a/src/libs/API/types.ts b/src/libs/API/types.ts index df844793d579..0061609ba978 100644 --- a/src/libs/API/types.ts +++ b/src/libs/API/types.ts @@ -691,6 +691,7 @@ const READ_COMMANDS = { SEARCH: 'Search', OPEN_SUBSCRIPTION_PAGE: 'OpenSubscriptionPage', OPEN_DRAFT_DISTANCE_EXPENSE: 'OpenDraftDistanceExpense', + START_ISSUE_NEW_CARD_FLOW: 'StartIssueNewCardFlow', } as const; type ReadCommand = ValueOf; @@ -746,6 +747,7 @@ type ReadCommandParameters = { [READ_COMMANDS.SEARCH]: Parameters.SearchParams; [READ_COMMANDS.OPEN_SUBSCRIPTION_PAGE]: null; [READ_COMMANDS.OPEN_DRAFT_DISTANCE_EXPENSE]: null; + [READ_COMMANDS.START_ISSUE_NEW_CARD_FLOW]: Parameters.StartIssueNewCardFlowParams; }; const SIDE_EFFECT_REQUEST_COMMANDS = { diff --git a/src/libs/actions/Card.ts b/src/libs/actions/Card.ts index b775be2fd031..d20130085aa3 100644 --- a/src/libs/actions/Card.ts +++ b/src/libs/actions/Card.ts @@ -7,9 +7,10 @@ import type { ReportVirtualExpensifyCardFraudParams, RequestReplacementExpensifyCardParams, RevealExpensifyCardDetailsParams, + StartIssueNewCardFlowParams, UpdateExpensifyCardLimitParams, } from '@libs/API/parameters'; -import {SIDE_EFFECT_REQUEST_COMMANDS, WRITE_COMMANDS} from '@libs/API/types'; +import {READ_COMMANDS, SIDE_EFFECT_REQUEST_COMMANDS, WRITE_COMMANDS} from '@libs/API/types'; import * as ErrorUtils from '@libs/ErrorUtils'; import * as NetworkStore from '@libs/Network/NetworkStore'; import CONST from '@src/CONST'; @@ -372,6 +373,14 @@ function updateExpensifyCardLimit(policyID: string, cardID: number, newLimit: nu API.write(WRITE_COMMANDS.UPDATE_EXPENSIFY_CARD_LIMIT, parameters, {optimisticData, successData, failureData}); } +function startIssueNewCardFlow(policyID: string) { + const parameters: StartIssueNewCardFlowParams = { + policyID, + }; + + API.read(READ_COMMANDS.START_ISSUE_NEW_CARD_FLOW, parameters); +} + export { requestReplacementExpensifyCard, activatePhysicalExpensifyCard, @@ -383,5 +392,6 @@ export { setIssueNewCardStepAndData, clearIssueNewCardFlow, updateExpensifyCardLimit, + startIssueNewCardFlow, }; export type {ReplacementReason}; diff --git a/src/pages/workspace/card/issueNew/IssueNewCardPage.tsx b/src/pages/workspace/card/issueNew/IssueNewCardPage.tsx index e12835a4a1e0..b16f6ef1dafc 100644 --- a/src/pages/workspace/card/issueNew/IssueNewCardPage.tsx +++ b/src/pages/workspace/card/issueNew/IssueNewCardPage.tsx @@ -1,7 +1,8 @@ -import React from 'react'; +import React, {useEffect} from 'react'; import {useOnyx} from 'react-native-onyx'; import type {WithPolicyAndFullscreenLoadingProps} from '@pages/workspace/withPolicyAndFullscreenLoading'; import withPolicyAndFullscreenLoading from '@pages/workspace/withPolicyAndFullscreenLoading'; +import * as Card from '@userActions/Card'; import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; import AssigneeStep from './AssigneeStep'; @@ -17,7 +18,9 @@ function IssueNewCardPage({policy}: WithPolicyAndFullscreenLoadingProps) { const {currentStep} = issueNewCard ?? {}; // TODO: add logic to skip Assignee step when the flow is started from the member's profile page - // TODO: StartIssueNewCardFlow call to API + useEffect(() => { + Card.startIssueNewCardFlow(policy?.id ?? '-1'); + }, [policy?.id]); switch (currentStep) { case CONST.EXPENSIFY_CARD.STEP.ASSIGNEE: