Skip to content

Commit

Permalink
Merge pull request #46570 from koko57/feat/44309-be-integration-creat…
Browse files Browse the repository at this point in the history
…eExpensifyCard

Feat/44309 be integration create expensify card
  • Loading branch information
mountiny authored Aug 13, 2024
2 parents 55ded55 + f63c718 commit 59741d8
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 5 deletions.
10 changes: 10 additions & 0 deletions src/libs/API/parameters/CreateExpensifyCardParams.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
type CreateExpensifyCardParams = {
policyID: string;
assigneeEmail: string;
limit: number;
limitType: string;
cardTitle: string;
feedCountry: string;
};

export default CreateExpensifyCardParams;
1 change: 1 addition & 0 deletions src/libs/API/parameters/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -271,3 +271,4 @@ export type {default as UpdateExpensifyCardLimitParams} from './UpdateExpensifyC
export type {CreateWorkspaceApprovalParams, UpdateWorkspaceApprovalParams, RemoveWorkspaceApprovalParams} from './WorkspaceApprovalParams';
export type {default as StartIssueNewCardFlowParams} from './StartIssueNewCardFlowParams';
export type {default as ConfigureExpensifyCardsForPolicyParams} from './ConfigureExpensifyCardsForPolicyParams';
export type {default as CreateExpensifyCardParams} from './CreateExpensifyCardParams';
4 changes: 4 additions & 0 deletions src/libs/API/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,8 @@ const WRITE_COMMANDS = {
UPDATE_WORKSPACE_APPROVAL: 'UpdateWorkspaceApproval',
REMOVE_WORKSPACE_APPROVAL: 'RemoveWorkspaceApproval',
CONFIGURE_EXPENSIFY_CARDS_FOR_POLICY: 'ConfigureExpensifyCardsForPolicy',
CREATE_EXPENSIFY_CARD: 'CreateExpensifyCard',
CREATE_ADMIN_ISSUED_VIRTUAL_CARD: 'CreateAdminIssuedVirtualCard',
} as const;

type WriteCommand = ValueOf<typeof WRITE_COMMANDS>;
Expand Down Expand Up @@ -658,6 +660,8 @@ type WriteCommandParameters = {
[WRITE_COMMANDS.UPDATE_WORKSPACE_APPROVAL]: Parameters.UpdateWorkspaceApprovalParams;
[WRITE_COMMANDS.REMOVE_WORKSPACE_APPROVAL]: Parameters.RemoveWorkspaceApprovalParams;
[WRITE_COMMANDS.CONFIGURE_EXPENSIFY_CARDS_FOR_POLICY]: Parameters.ConfigureExpensifyCardsForPolicyParams;
[WRITE_COMMANDS.CREATE_EXPENSIFY_CARD]: Parameters.CreateExpensifyCardParams;
[WRITE_COMMANDS.CREATE_ADMIN_ISSUED_VIRTUAL_CARD]: Omit<Parameters.CreateExpensifyCardParams, 'feedCountry'>;
};

const READ_COMMANDS = {
Expand Down
25 changes: 25 additions & 0 deletions src/libs/actions/Card.ts
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,30 @@ function configureExpensifyCardsForPolicy(policyID: string, bankAccountID?: numb
API.write(WRITE_COMMANDS.CONFIGURE_EXPENSIFY_CARDS_FOR_POLICY, parameters);
}

function issueExpensifyCard(policyID: string, feedCountry: string, data?: IssueNewCardData) {
if (!data) {
return;
}

const {assigneeEmail, limit, limitType, cardTitle, cardType} = data;

const parameters = {
policyID,
assigneeEmail,
limit,
limitType,
cardTitle,
};

if (cardType === CONST.EXPENSIFY_CARD.CARD_TYPE.PHYSICAL) {
API.write(WRITE_COMMANDS.CREATE_EXPENSIFY_CARD, {...parameters, feedCountry});
return;
}

// eslint-disable-next-line rulesdir/no-multiple-api-calls
API.write(WRITE_COMMANDS.CREATE_ADMIN_ISSUED_VIRTUAL_CARD, parameters);
}

export {
requestReplacementExpensifyCard,
activatePhysicalExpensifyCard,
Expand All @@ -407,5 +431,6 @@ export {
updateSettlementAccount,
startIssueNewCardFlow,
configureExpensifyCardsForPolicy,
issueExpensifyCard,
};
export type {ReplacementReason};
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,12 @@ import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import type {IssueNewCardStep} from '@src/types/onyx/Card';

function ConfirmationStep() {
type ConfirmationStepProps = {
// ID of the policy that the card will be issued under
policyID: string;
};

function ConfirmationStep({policyID}: ConfirmationStepProps) {
const {translate} = useLocalize();
const styles = useThemeStyles();
const {isOffline} = useNetwork();
Expand All @@ -30,7 +35,7 @@ function ConfirmationStep() {
const data = issueNewCard?.data;

const submit = () => {
// TODO: the logic will be created when CreateExpensifyCard is ready
Card.issueExpensifyCard(policyID, CONST.COUNTRY.US, data);
Navigation.goBack();
Card.clearIssueNewCardFlow();
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,12 @@ function IssueNewCardPage({policy}: WithPolicyAndFullscreenLoadingProps) {

const {currentStep} = issueNewCard ?? {};

const policyID = policy?.id ?? '-1';

// TODO: add logic to skip Assignee step when the flow is started from the member's profile page
useEffect(() => {
Card.startIssueNewCardFlow(policy?.id ?? '-1');
}, [policy?.id]);
Card.startIssueNewCardFlow(policyID);
}, [policyID]);

switch (currentStep) {
case CONST.EXPENSIFY_CARD.STEP.ASSIGNEE:
Expand All @@ -34,7 +36,7 @@ function IssueNewCardPage({policy}: WithPolicyAndFullscreenLoadingProps) {
case CONST.EXPENSIFY_CARD.STEP.CARD_NAME:
return <CardNameStep />;
case CONST.EXPENSIFY_CARD.STEP.CONFIRMATION:
return <ConfirmationStep />;
return <ConfirmationStep policyID={policyID} />;
default:
return <AssigneeStep policy={policy} />;
}
Expand Down

0 comments on commit 59741d8

Please sign in to comment.