Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions src/components/KYCWall/BaseKYCWall.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import getClickedTargetLocation from '@libs/getClickedTargetLocation';
import Log from '@libs/Log';
import Navigation from '@libs/Navigation/Navigation';
import {hasExpensifyPaymentMethod} from '@libs/PaymentUtils';
import {isExpenseReport as isExpenseReportReportUtils, isIOUReport} from '@libs/ReportUtils';
import {getBankAccountRoute, isExpenseReport as isExpenseReportReportUtils, isIOUReport} from '@libs/ReportUtils';
import {kycWallRef} from '@userActions/PaymentMethods';
import {createWorkspaceFromIOUPayment} from '@userActions/Policy/Policy';
import {setKYCWallSource} from '@userActions/Wallet';
Expand Down Expand Up @@ -52,6 +52,7 @@ function KYCWall({
const [fundList] = useOnyx(ONYXKEYS.FUND_LIST, {canBeMissing: true});
const [bankAccountList = getEmptyObject<BankAccountList>()] = useOnyx(ONYXKEYS.BANK_ACCOUNT_LIST, {canBeMissing: true});
const [reimbursementAccount] = useOnyx(ONYXKEYS.REIMBURSEMENT_ACCOUNT, {canBeMissing: true});
const [chatReport] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${chatReportID}`, {canBeMissing: true});

const anchorRef = useRef<HTMLDivElement | View>(null);
const transferBalanceButtonRef = useRef<HTMLDivElement | View | null>(null);
Expand Down Expand Up @@ -122,10 +123,11 @@ function KYCWall({

return;
}
Navigation.navigate(addBankAccountRoute);
const bankAccountRoute = addBankAccountRoute ?? getBankAccountRoute(chatReport);
Navigation.navigate(bankAccountRoute);
}
},
[addBankAccountRoute, addDebitCardRoute, iouReport, onSelectPaymentMethod],
[addBankAccountRoute, addDebitCardRoute, chatReport, iouReport, onSelectPaymentMethod],
);

/**
Expand Down
2 changes: 1 addition & 1 deletion src/components/KYCWall/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ type PaymentMethod = ValueOf<typeof CONST.PAYMENT_METHODS>;

type KYCWallProps = {
/** Route for the Add Bank Account screen for a given navigation stack */
addBankAccountRoute: Route;
addBankAccountRoute?: Route;

/** Route for the Add Debit Card screen for a given navigation stack */
addDebitCardRoute?: Route;
Expand Down
5 changes: 0 additions & 5 deletions src/components/MoneyReportHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ import {getSecondaryReportActions} from '@libs/ReportSecondaryActionUtils';
import {
changeMoneyRequestHoldStatus,
getArchiveReason,
getBankAccountRoute,
getIntegrationIcon,
getIntegrationNameFromExportMessage as getIntegrationNameFromExportMessageUtils,
getNextApproverAccountID,
Expand Down Expand Up @@ -313,7 +312,6 @@ function MoneyReportHeader({
const optimisticNextStep = isSubmitterSameAsNextApprover && policy?.preventSelfApproval ? buildOptimisticNextStepForPreventSelfApprovalsEnabled() : nextStep;

const shouldShowNextStep = isFromPaidPolicy && !isInvoiceReport && !shouldShowStatusBar;
const bankAccountRoute = getBankAccountRoute(chatReport);
const {nonHeldAmount, fullAmount, hasValidNonHeldAmount} = getNonHeldAndFullAmount(moneyRequestReport, shouldShowPayButton);
const isAnyTransactionOnHold = hasHeldExpensesReportUtils(moneyRequestReport?.reportID);
const {isDelegateAccessRestricted, showDelegateNoAccessModal} = useContext(DelegateNoAccessContext);
Expand Down Expand Up @@ -477,7 +475,6 @@ function MoneyReportHeader({
const {formattedAmount: totalAmount} = hasOnlyHeldExpenses ? getAmount(CONST.REPORT.REPORT_PREVIEW_ACTIONS.REVIEW) : getAmount(CONST.REPORT.PRIMARY_ACTIONS.PAY);

const paymentButtonOptions = usePaymentOptions({
addBankAccountRoute: bankAccountRoute,
currency: moneyRequestReport?.currency,
iouReport: moneyRequestReport,
chatReportID: chatReport?.reportID,
Expand Down Expand Up @@ -557,7 +554,6 @@ function MoneyReportHeader({
iouReport={moneyRequestReport}
onPress={confirmPayment}
enablePaymentsRoute={ROUTES.ENABLE_PAYMENTS}
addBankAccountRoute={bankAccountRoute}
shouldHidePaymentOptions={!shouldShowPayButton}
shouldShowApproveButton={shouldShowApproveButton}
shouldDisableApproveButton={shouldDisableApproveButton}
Expand Down Expand Up @@ -927,7 +923,6 @@ function MoneyReportHeader({
<KYCWall
onSuccessfulKYC={(payment) => confirmPayment(payment)}
enablePaymentsRoute={ROUTES.ENABLE_PAYMENTS}
addBankAccountRoute={bankAccountRoute}
isDisabled={isOffline}
source={CONST.KYC_WALL_SOURCE.REPORT}
chatReportID={chatReport?.reportID}
Expand Down
10 changes: 2 additions & 8 deletions src/components/MoneyRequestConfirmationList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ import CONST from '@src/CONST';
import type {TranslationPaths} from '@src/languages/types';
import ONYXKEYS from '@src/ONYXKEYS';
import ROUTES from '@src/ROUTES';
import type {Route} from '@src/ROUTES';
import type * as OnyxTypes from '@src/types/onyx';
import type {Attendee, Participant} from '@src/types/onyx/IOU';
import type {PaymentMethodType} from '@src/types/onyx/OriginalMessage';
Expand Down Expand Up @@ -125,9 +124,6 @@ type MoneyRequestConfirmationListProps = {
/** Number of expenses to be created */
expensesNumber?: number;

/** Depending on expense report or personal IOU report, respective bank account route */
bankAccountRoute?: Route;

/** The policyID of the request */
policyID?: string;

Expand Down Expand Up @@ -209,7 +205,6 @@ function MoneyRequestConfirmationList({
selectedParticipants: selectedParticipantsProp,
payeePersonalDetails: payeePersonalDetailsProp,
isReadOnly = false,
bankAccountRoute = '',
policyID,
reportID = '',
receiptPath = '',
Expand Down Expand Up @@ -994,7 +989,7 @@ function MoneyRequestConfirmationList({
pressOnEnter
onPress={confirm}
enablePaymentsRoute={ROUTES.IOU_SEND_ENABLE_PAYMENTS}
addBankAccountRoute={bankAccountRoute}
chatReportID={reportID}
shouldShowPersonalBankAccountOption
currency={iouCurrencyCode}
policyID={policyID}
Expand Down Expand Up @@ -1064,7 +1059,6 @@ function MoneyRequestConfirmationList({
isReadOnly,
iouType,
confirm,
bankAccountRoute,
iouCurrencyCode,
policyID,
isConfirmed,
Expand All @@ -1080,6 +1074,7 @@ function MoneyRequestConfirmationList({
shouldShowProductTrainingTooltip,
renderProductTrainingTooltip,
isConfirming,
reportID,
]);

const listFooterContent = (
Expand Down Expand Up @@ -1175,7 +1170,6 @@ export default memo(
deepEqual(prevProps.selectedParticipants, nextProps.selectedParticipants) &&
deepEqual(prevProps.payeePersonalDetails, nextProps.payeePersonalDetails) &&
prevProps.isReadOnly === nextProps.isReadOnly &&
prevProps.bankAccountRoute === nextProps.bankAccountRoute &&
prevProps.policyID === nextProps.policyID &&
prevProps.reportID === nextProps.reportID &&
prevProps.receiptPath === nextProps.receiptPath &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ import {getConnectedIntegration} from '@libs/PolicyUtils';
import {getReportPreviewAction} from '@libs/ReportPreviewActionUtils';
import {
areAllRequestsBeingSmartScanned as areAllRequestsBeingSmartScannedReportUtils,
getBankAccountRoute,
getDisplayNameForParticipant,
getInvoicePayerName,
getMoneyReportPreviewName,
Expand Down Expand Up @@ -283,8 +282,6 @@ function MoneyRequestReportPreviewContent({
managerID,
]);

const bankAccountRoute = getBankAccountRoute(chatReport);

/*
Show subtitle if at least one of the expenses is not being smart scanned, and either:
- There is more than one expense – in this case, the "X expenses, Y scanning" subtitle is shown;
Expand Down Expand Up @@ -527,7 +524,6 @@ function MoneyRequestReportPreviewContent({
onPaymentOptionsHide={onPaymentOptionsHide}
confirmApproval={confirmApproval}
enablePaymentsRoute={ROUTES.ENABLE_PAYMENTS}
addBankAccountRoute={bankAccountRoute}
shouldHidePaymentOptions={!shouldShowPayButton}
kycWallAnchorAlignment={{
horizontal: CONST.MODAL.ANCHOR_ORIGIN_HORIZONTAL.LEFT,
Expand Down
3 changes: 0 additions & 3 deletions src/components/SettlementButton/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import type SettlementButtonProps from './types';

function SettlementButton({
addDebitCardRoute = ROUTES.IOU_SEND_ADD_DEBIT_CARD,
addBankAccountRoute = '',
kycWallAnchorAlignment = {
horizontal: CONST.MODAL.ANCHOR_ORIGIN_HORIZONTAL.LEFT, // button is at left, so horizontal anchor is at LEFT
vertical: CONST.MODAL.ANCHOR_ORIGIN_VERTICAL.TOP, // we assume that popover menu opens below the button, anchor is at TOP
Expand Down Expand Up @@ -69,7 +68,6 @@ function SettlementButton({
const {isAccountLocked, showLockedAccountModal} = useContext(LockedAccountContext);

const paymentButtonOptions = usePaymentOptions({
addBankAccountRoute,
currency,
iouReport,
chatReportID,
Expand Down Expand Up @@ -100,7 +98,6 @@ function SettlementButton({
<KYCWall
onSuccessfulKYC={(paymentType) => onPress(paymentType)}
enablePaymentsRoute={enablePaymentsRoute}
addBankAccountRoute={addBankAccountRoute}
addDebitCardRoute={addDebitCardRoute}
isDisabled={isOffline}
source={CONST.KYC_WALL_SOURCE.REPORT}
Expand Down
3 changes: 0 additions & 3 deletions src/components/SettlementButton/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,6 @@ type SettlementButtonProps = {
/** The size of button size */
buttonSize?: ButtonSizeValue;

/** Route for the Add Bank Account screen for a given navigation stack */
addBankAccountRoute?: Route;

/** Route for the Add Debit Card screen for a given navigation stack */
addDebitCardRoute?: Route;

Expand Down
13 changes: 9 additions & 4 deletions src/hooks/usePaymentOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {formatPaymentMethods} from '@libs/PaymentUtils';
import getPolicyEmployeeAccountIDs from '@libs/PolicyEmployeeListUtils';
import {
doesReportBelongToWorkspace,
getBankAccountRoute,
isExpenseReport as isExpenseReportUtil,
isIndividualInvoiceRoom as isIndividualInvoiceRoomUtil,
isInvoiceReport as isInvoiceReportUtil,
Expand All @@ -26,7 +27,6 @@ type CurrencyType = TupleToUnion<typeof CONST.DIRECT_REIMBURSEMENT_CURRENCIES>;

type UsePaymentOptionsProps = Pick<
SettlementButtonProps,
| 'addBankAccountRoute'
| 'currency'
| 'iouReport'
| 'chatReportID'
Expand All @@ -45,7 +45,6 @@ type UsePaymentOptionsProps = Pick<
* It dynamically generates payment or approval options to ensure the user interface reflects the correct actions possible for the user's current situation.
*/
function usePaymentOptions({
addBankAccountRoute = '',
currency = CONST.CURRENCY.USD,
iouReport,
chatReportID = '',
Expand Down Expand Up @@ -174,7 +173,10 @@ function usePaymentOptions({
{
text: translate('workspace.invoices.paymentMethods.addBankAccount'),
icon: Expensicons.Bank,
onSelected: () => Navigation.navigate(addBankAccountRoute),
onSelected: () => {
const bankAccountRoute = getBankAccountRoute(chatReport);
Navigation.navigate(bankAccountRoute);
},
},
],
});
Expand All @@ -190,7 +192,10 @@ function usePaymentOptions({
{
text: translate('workspace.invoices.paymentMethods.addBankAccount'),
icon: Expensicons.Bank,
onSelected: () => Navigation.navigate(addBankAccountRoute),
onSelected: () => {
const bankAccountRoute = getBankAccountRoute(chatReport);
Navigation.navigate(bankAccountRoute);
},
},
{
text: translate('iou.payElsewhere', {formattedAmount: ''}),
Expand Down
11 changes: 5 additions & 6 deletions src/pages/iou/MoneyRequestAmountForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import Navigation from '@libs/Navigation/Navigation';
import variables from '@styles/variables';
import type {BaseTextInputRef} from '@src/components/TextInput/BaseTextInput/types';
import CONST from '@src/CONST';
import type {Route} from '@src/ROUTES';
import ROUTES from '@src/ROUTES';
import type {SelectedTabRequest} from '@src/types/onyx';
import type {PaymentMethodType} from '@src/types/onyx/OriginalMessage';
Expand Down Expand Up @@ -51,9 +50,6 @@ type MoneyRequestAmountFormProps = {
/** The policyID of the request */
policyID?: string;

/** Depending on expense report or personal IOU report, respective bank account route */
bankAccountRoute?: Route;

/** Whether the currency symbol is pressable */
isCurrencyPressable?: boolean;

Expand All @@ -68,6 +64,9 @@ type MoneyRequestAmountFormProps = {

/** Whether the user input should be kept or not */
shouldKeepUserInput?: boolean;

/** The chatReportID of the request */
chatReportID?: string;
};

const isAmountInvalid = (amount: string) => !amount.length || parseFloat(amount) < 0.01;
Expand All @@ -88,11 +87,11 @@ function MoneyRequestAmountForm(
skipConfirmation = false,
iouType = CONST.IOU.TYPE.SUBMIT,
policyID = '',
bankAccountRoute = '',
onCurrencyButtonPress,
onSubmitButtonPress,
selectedTab = CONST.TAB_REQUEST.MANUAL,
shouldKeepUserInput = false,
chatReportID,
}: MoneyRequestAmountFormProps,
forwardedRef: ForwardedRef<BaseTextInputRef>,
) {
Expand Down Expand Up @@ -309,7 +308,6 @@ function MoneyRequestAmountForm(
pressOnEnter
onPress={submitAndNavigateToNextPage}
enablePaymentsRoute={ROUTES.IOU_SEND_ENABLE_PAYMENTS}
addBankAccountRoute={bankAccountRoute}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I missed this last time. SettlementButton does not get chatReportID prop here so it cannot know the correct route. We can pass the reportID from IOURequestStepAmount to MoneyRequestAmountForm and then to SettlementButton.

addDebitCardRoute={ROUTES.IOU_SEND_ADD_DEBIT_CARD}
currency={currency ?? CONST.CURRENCY.USD}
policyID={policyID}
Expand All @@ -325,6 +323,7 @@ function MoneyRequestAmountForm(
}}
shouldShowPersonalBankAccountOption
enterKeyEventListenerPriority={1}
chatReportID={chatReportID}
/>
) : (
<Button
Expand Down
4 changes: 2 additions & 2 deletions src/pages/iou/request/step/IOURequestStepAmount.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {navigateToParticipantPage} from '@libs/IOUUtils';
import Navigation from '@libs/Navigation/Navigation';
import {getParticipantsOption, getReportOption} from '@libs/OptionsListUtils';
import {isPaidGroupPolicy} from '@libs/PolicyUtils';
import {getBankAccountRoute, getPolicyExpenseChat, getTransactionDetails, isArchivedReport, isPolicyExpenseChat} from '@libs/ReportUtils';
import {getPolicyExpenseChat, getTransactionDetails, isArchivedReport, isPolicyExpenseChat} from '@libs/ReportUtils';
import {shouldRestrictUserBillableActions} from '@libs/SubscriptionUtils';
import {calculateTaxAmount, getAmount, getCurrency, getDefaultTaxCode, getRequestType, getTaxValue} from '@libs/TransactionUtils';
import MoneyRequestAmountForm from '@pages/iou/MoneyRequestAmountForm';
Expand Down Expand Up @@ -318,14 +318,14 @@ function IOURequestStepAmount({
skipConfirmation={shouldSkipConfirmation ?? false}
iouType={iouType}
policyID={policy?.id}
bankAccountRoute={getBankAccountRoute(report)}
ref={(e) => {
textInput.current = e;
}}
shouldKeepUserInput={transaction?.shouldShowOriginalAmount}
onCurrencyButtonPress={navigateToCurrencySelectionPage}
onSubmitButtonPress={saveAmountAndCurrency}
selectedTab={iouRequestType}
chatReportID={reportID}
/>
</StepScreenWrapper>
);
Expand Down
3 changes: 1 addition & 2 deletions src/pages/iou/request/step/IOURequestStepConfirmation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import Navigation from '@libs/Navigation/Navigation';
import {rand64} from '@libs/NumberUtils';
import {getParticipantsOption, getReportOption} from '@libs/OptionsListUtils';
import Performance from '@libs/Performance';
import {generateReportID, getBankAccountRoute, getReportOrDraftReport, isProcessingReport, isReportOutstanding, isSelectedManagerMcTest} from '@libs/ReportUtils';
import {generateReportID, getReportOrDraftReport, isProcessingReport, isReportOutstanding, isSelectedManagerMcTest} from '@libs/ReportUtils';
import {getAttendees, getDefaultTaxCode, getRateID, getRequestType, getValidWaypoints, hasReceipt, isScanRequest} from '@libs/TransactionUtils';
import type {FileObject} from '@pages/media/AttachmentModalScreen/types';
import type {GpsPoint} from '@userActions/IOU';
Expand Down Expand Up @@ -1094,7 +1094,6 @@ function IOURequestStepConfirmation({
shouldDisplayReceipt={!isMovingTransactionFromTrackExpense && !isDistanceRequest && !isPerDiemRequest}
isPolicyExpenseChat={isPolicyExpenseChat}
policyID={getIOURequestPolicyID(transaction, report)}
bankAccountRoute={getBankAccountRoute(report)}
iouMerchant={transaction?.merchant}
iouCreated={transaction?.created}
isDistanceRequest={isDistanceRequest}
Expand Down
Loading
Loading