Skip to content

Commit

Permalink
fix: not redirect to workspace chat when pay iou with business account
Browse files Browse the repository at this point in the history
  • Loading branch information
gijoe0295 committed Jul 31, 2024
1 parent 881c548 commit e12f060
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
10 changes: 7 additions & 3 deletions src/components/KYCWall/BaseKYCWall.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import ONYXKEYS from '@src/ONYXKEYS';
import ROUTES from '@src/ROUTES';
import type {BankAccountList, FundList, ReimbursementAccount, UserWallet, WalletTerms} from '@src/types/onyx';
import type {PaymentMethodType} from '@src/types/onyx/OriginalMessage';
import {isEmptyObject} from '@src/types/utils/EmptyObject';
import viewRef from '@src/types/utils/viewRef';
import type {AnchorPosition, DomRect, KYCWallProps, PaymentMethod} from './types';

Expand Down Expand Up @@ -67,7 +68,7 @@ function KYCWall({
source,
userWallet,
walletTerms,
shouldShowPersonalBankAccountOption = false,
shouldShowPersonalBankAccountOption = true,
}: BaseKYCWallProps) {
const anchorRef = useRef<HTMLDivElement | View>(null);
const transferBalanceButtonRef = useRef<HTMLDivElement | View | null>(null);
Expand Down Expand Up @@ -127,7 +128,10 @@ function KYCWall({
Navigation.navigate(addDebitCardRoute);
} else if (paymentMethod === CONST.PAYMENT_METHODS.BUSINESS_BANK_ACCOUNT) {
if (iouReport && ReportUtils.isIOUReport(iouReport)) {
const policyID = Policy.createWorkspaceFromIOUPayment(iouReport);
const {policyID, workspaceChatReportID, reportPreviewReportActionID} = Policy.createWorkspaceFromIOUPayment(iouReport) ?? {};
if (workspaceChatReportID) {
Navigation.navigate(ROUTES.REPORT_WITH_ID.getRoute(workspaceChatReportID, reportPreviewReportActionID));
}

// Navigate to the bank account set up flow for this specific policy
Navigation.navigate(ROUTES.BANK_ACCOUNT_WITH_STEP_TO_OPEN.getRoute('', policyID));
Expand Down Expand Up @@ -172,7 +176,7 @@ function KYCWall({
// Check to see if user has a valid payment method on file and display the add payment popover if they don't
if (
(isExpenseReport && reimbursementAccount?.achData?.state !== CONST.BANK_ACCOUNT.STATE.OPEN) ||
(!isExpenseReport && bankAccountList !== null && !PaymentUtils.hasExpensifyPaymentMethod(paymentCardList, bankAccountList, shouldIncludeDebitCard))
(!isExpenseReport && isEmptyObject(bankAccountList) && !PaymentUtils.hasExpensifyPaymentMethod(paymentCardList, bankAccountList, shouldIncludeDebitCard))
) {
Log.info('[KYC Wallet] User does not have valid payment method');

Expand Down
10 changes: 8 additions & 2 deletions src/libs/actions/Policy/Policy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,12 @@ type NewCustomUnit = {
rates: Rate;
};

type WorkspaceFromIOUCreationData = {
policyID: string;
workspaceChatReportID: string;
reportPreviewReportActionID?: string;
};

const allPolicies: OnyxCollection<Policy> = {};
Onyx.connect({
key: ONYXKEYS.COLLECTION.POLICY,
Expand Down Expand Up @@ -2066,7 +2072,7 @@ function dismissAddedWithPrimaryLoginMessages(policyID: string) {
*
* @returns policyID of the workspace we have created
*/
function createWorkspaceFromIOUPayment(iouReport: OnyxEntry<Report>): string | undefined {
function createWorkspaceFromIOUPayment(iouReport: OnyxEntry<Report>): WorkspaceFromIOUCreationData | undefined {
// This flow only works for IOU reports
if (!ReportUtils.isIOUReportUsingReport(iouReport)) {
return;
Expand Down Expand Up @@ -2499,7 +2505,7 @@ function createWorkspaceFromIOUPayment(iouReport: OnyxEntry<Report>): string | u

API.write(WRITE_COMMANDS.CREATE_WORKSPACE_FROM_IOU_PAYMENT, params, {optimisticData, successData, failureData});

return policyID;
return {policyID, workspaceChatReportID: memberData.workspaceChatReportID, reportPreviewReportActionID: reportPreview?.reportActionID};
}

function enablePolicyConnections(policyID: string, enabled: boolean) {
Expand Down

0 comments on commit e12f060

Please sign in to comment.