Skip to content
Open
Show file tree
Hide file tree
Changes from 7 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
5 changes: 0 additions & 5 deletions src/components/Modal/Global/HoldMenuModalWrapper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import type {ActionHandledType} from '@hooks/useHoldMenuSubmit';
import useLocalize from '@hooks/useLocalize';
import useOnyx from '@hooks/useOnyx';
import useResponsiveLayout from '@hooks/useResponsiveLayout';
import useTransactionsAndViolationsForReport from '@hooks/useTransactionsAndViolationsForReport';
import ONYXKEYS from '@src/ONYXKEYS';
import type {PaymentMethodType} from '@src/types/onyx/OriginalMessage';
import type {ModalProps} from './ModalContext';
Expand Down Expand Up @@ -45,9 +44,6 @@ function HoldMenuModalWrapper({
const [moneyRequestReport] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${reportID}`);
const [chatReport] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${chatReportID}`);

const {transactions: reportTransactions} = useTransactionsAndViolationsForReport(moneyRequestReport?.reportID);
const transactions = Object.values(reportTransactions);

const {onSubmit, isApprove} = useHoldMenuSubmit({
moneyRequestReport,
chatReport,
Expand All @@ -56,7 +52,6 @@ function HoldMenuModalWrapper({
methodID,
onClose: () => setIsVisible(false),
onConfirm,
transactions,
});

return (
Expand Down
19 changes: 3 additions & 16 deletions src/components/MoneyReportHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import {useMemoizedLazyExpensifyIcons} from '@hooks/useLazyAsset';
import useLocalize from '@hooks/useLocalize';
import useMobileSelectionMode from '@hooks/useMobileSelectionMode';
import useNetwork from '@hooks/useNetwork';
import useNonReimbursablePaymentModal from '@hooks/useNonReimbursablePaymentModal';
import useOnyx from '@hooks/useOnyx';
import usePaginatedReportActions from '@hooks/usePaginatedReportActions';
import useParticipantsInvoiceReport from '@hooks/useParticipantsInvoiceReport';
Expand Down Expand Up @@ -80,7 +79,6 @@ import {
getNextApproverAccountID,
getPolicyExpenseChat,
hasHeldExpenses as hasHeldExpensesReportUtils,
hasOnlyNonReimbursableTransactions,
hasUpdatedTotal,
hasViolations as hasViolationsReportUtils,
isAllowedToApproveExpenseReport,
Expand Down Expand Up @@ -466,7 +464,6 @@ function MoneyReportHeaderContent({reportID: reportIDProp, shouldDisplayBackButt

const shouldDisplayNarrowMoreButton = !shouldDisplayNarrowVersion || isWideRHPDisplayedOnWideLayout || isSuperWideRHPDisplayedOnWideLayout;

const {showNonReimbursablePaymentErrorModal, shouldBlockDirectPayment} = useNonReimbursablePaymentModal(moneyRequestReport, transactions);
const {openHoldMenu, openPDFDownload, openHoldEducational, openRejectModal} = useMoneyReportHeaderModals();

const showExportProgressModal = useCallback(() => {
Expand Down Expand Up @@ -529,15 +526,11 @@ function MoneyReportHeaderContent({reportID: reportIDProp, shouldDisplayBackButt
});

const canIOUBePaid = useMemo(() => getCanIOUBePaid(), [getCanIOUBePaid]);
const reportHasOnlyNonReimbursableTransactions = hasOnlyNonReimbursableTransactions(moneyRequestReport?.reportID, transactions);
const onlyShowPayElsewhere = useMemo(() => {
if (reportHasOnlyNonReimbursableTransactions) {
return false;
}
return !canIOUBePaid && getCanIOUBePaid(true);
}, [canIOUBePaid, getCanIOUBePaid, reportHasOnlyNonReimbursableTransactions]);
}, [canIOUBePaid, getCanIOUBePaid]);

const shouldShowPayButton = isPaidAnimationRunning || canIOUBePaid || onlyShowPayElsewhere || (reportHasOnlyNonReimbursableTransactions && (moneyRequestReport?.total ?? 0) !== 0);
const shouldShowPayButton = isPaidAnimationRunning || canIOUBePaid || onlyShowPayElsewhere;

const shouldShowApproveButton = useMemo(
() => (canApproveIOU(moneyRequestReport, policy, reportMetadata, transactions) && !hasOnlyPendingTransactions) || isApprovedAnimationRunning,
Expand Down Expand Up @@ -567,10 +560,6 @@ function MoneyReportHeaderContent({reportID: reportIDProp, shouldDisplayBackButt
if (!type || !chatReport) {
return;
}
if (shouldBlockDirectPayment(type)) {
showNonReimbursablePaymentErrorModal();
return;
}
const isFromSelectionMode = isSelectionModePaymentRef.current;
if (isDelegateAccessRestricted) {
showDelegateNoAccessModal();
Expand Down Expand Up @@ -659,8 +648,6 @@ function MoneyReportHeaderContent({reportID: reportIDProp, shouldDisplayBackButt
isAnyTransactionOnHold,
isInvoiceReport,
showDelegateNoAccessModal,
showNonReimbursablePaymentErrorModal,
shouldBlockDirectPayment,
openHoldMenu,
startAnimation,
moneyRequestReport,
Expand Down Expand Up @@ -933,7 +920,7 @@ function MoneyReportHeaderContent({reportID: reportIDProp, shouldDisplayBackButt
]);

const getAmount = (actionType: ValueOf<typeof CONST.REPORT.REPORT_PREVIEW_ACTIONS>) => ({
formattedAmount: getTotalAmountForIOUReportPreviewButton(moneyRequestReport, policy, actionType, nonPendingDeleteTransactions),
formattedAmount: getTotalAmountForIOUReportPreviewButton(moneyRequestReport, policy, actionType),
});

const {formattedAmount: totalAmount} = getAmount(CONST.REPORT.PRIMARY_ACTIONS.PAY);
Expand Down
5 changes: 2 additions & 3 deletions src/components/MoneyReportHeaderModals.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import useOnyx from '@hooks/useOnyx';
import useTransactionsAndViolationsForReport from '@hooks/useTransactionsAndViolationsForReport';
import getNonEmptyStringOnyxID from '@libs/getNonEmptyStringOnyxID';
import getPlatform from '@libs/getPlatform';
import {getNonHeldAndFullAmount, hasOnlyHeldExpenses as hasOnlyHeldExpensesReportUtils, hasOnlyNonReimbursableTransactions} from '@libs/ReportUtils';
import {getNonHeldAndFullAmount, hasOnlyHeldExpenses as hasOnlyHeldExpensesReportUtils} from '@libs/ReportUtils';
import {canIOUBePaid as canIOUBePaidAction} from '@userActions/IOU';
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
Expand Down Expand Up @@ -42,8 +42,7 @@ function MoneyReportHeaderModals({reportID, children}: MoneyReportHeaderModalsPr
// Derive data for hold menu
const canIOUBePaid = canIOUBePaidAction(moneyRequestReport, chatReport, policy, bankAccountList);
const onlyShowPayElsewhere = !canIOUBePaid && canIOUBePaidAction(moneyRequestReport, chatReport, policy, bankAccountList, undefined, true);
const reportHasOnlyNonReimbursableTransactions = hasOnlyNonReimbursableTransactions(moneyRequestReport?.reportID, transactions);
const shouldShowPayButton = canIOUBePaid || onlyShowPayElsewhere || reportHasOnlyNonReimbursableTransactions;
const shouldShowPayButton = canIOUBePaid || onlyShowPayElsewhere;
const {nonHeldAmount, fullAmount, hasValidNonHeldAmount} = getNonHeldAndFullAmount(moneyRequestReport, shouldShowPayButton);
const hasOnlyHeldExpenses = hasOnlyHeldExpensesReportUtils(moneyRequestReport?.reportID);
const transactionIDs = transactions.map((t) => t.transactionID);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import AnimatedSettlementButton from '@components/SettlementButton/AnimatedSettl
import type {PaymentActionParams} from '@components/SettlementButton/types';
import useCurrentUserPersonalDetails from '@hooks/useCurrentUserPersonalDetails';
import useNetwork from '@hooks/useNetwork';
import useNonReimbursablePaymentModal from '@hooks/useNonReimbursablePaymentModal';
import useOnyx from '@hooks/useOnyx';
import useParticipantsInvoiceReport from '@hooks/useParticipantsInvoiceReport';
import usePolicy from '@hooks/usePolicy';
Expand All @@ -16,13 +15,7 @@ import useTransactionsAndViolationsForReport from '@hooks/useTransactionsAndViol
import {search} from '@libs/actions/Search';
import getNonEmptyStringOnyxID from '@libs/getNonEmptyStringOnyxID';
import {getTotalAmountForIOUReportPreviewButton} from '@libs/MoneyRequestReportUtils';
import {
hasHeldExpenses as hasHeldExpensesReportUtils,
hasOnlyNonReimbursableTransactions,
hasUpdatedTotal,
isAllowedToApproveExpenseReport,
isInvoiceReport as isInvoiceReportUtil,
} from '@libs/ReportUtils';
import {hasHeldExpenses as hasHeldExpensesReportUtils, hasUpdatedTotal, isAllowedToApproveExpenseReport, isInvoiceReport as isInvoiceReportUtil} from '@libs/ReportUtils';
import {isExpensifyCardTransaction, isPending} from '@libs/TransactionUtils';
import {canApproveIOU, canIOUBePaid as canIOUBePaidAction, payInvoice, payMoneyRequest} from '@userActions/IOU';
import CONST from '@src/CONST';
Expand Down Expand Up @@ -73,12 +66,9 @@ function PayPrimaryAction({reportID, chatReportID, isPaidAnimationRunning, isApp
const hasOnlyPendingTransactions = transactions.length > 0 && transactions.every((t) => isExpensifyCardTransaction(t) && isPending(t));

const canIOUBePaid = canIOUBePaidAction(moneyRequestReport, chatReport, policy, bankAccountList, transaction ? [transaction] : undefined, false, undefined, invoiceReceiverPolicy);
const reportHasOnlyNonReimbursableTransactions = hasOnlyNonReimbursableTransactions(moneyRequestReport?.reportID, transactions);
const {showNonReimbursablePaymentErrorModal, shouldBlockDirectPayment} = useNonReimbursablePaymentModal(moneyRequestReport, transactions);
const onlyShowPayElsewhere = reportHasOnlyNonReimbursableTransactions
? false
: !canIOUBePaid && canIOUBePaidAction(moneyRequestReport, chatReport, policy, bankAccountList, transaction ? [transaction] : undefined, true, undefined, invoiceReceiverPolicy);
const shouldShowPayButton = isPaidAnimationRunning || canIOUBePaid || onlyShowPayElsewhere || (reportHasOnlyNonReimbursableTransactions && (moneyRequestReport?.total ?? 0) !== 0);
const onlyShowPayElsewhere =
!canIOUBePaid && canIOUBePaidAction(moneyRequestReport, chatReport, policy, bankAccountList, transaction ? [transaction] : undefined, true, undefined, invoiceReceiverPolicy);
const shouldShowPayButton = isPaidAnimationRunning || canIOUBePaid || onlyShowPayElsewhere;
const shouldShowApproveButton = (canApproveIOU(moneyRequestReport, policy, reportMetadata, transactions) && !hasOnlyPendingTransactions) || isApprovedAnimationRunning;
const shouldDisableApproveButton = shouldShowApproveButton && !isAllowedToApproveExpenseReport(moneyRequestReport);
const canAllowSettlement = hasUpdatedTotal(moneyRequestReport, policy);
Expand All @@ -96,10 +86,6 @@ function PayPrimaryAction({reportID, chatReportID, isPaidAnimationRunning, isApp
if (!type || !chatReport) {
return;
}
if (shouldBlockDirectPayment(type)) {
showNonReimbursablePaymentErrorModal();
return;
}
if (isDelegateAccessRestricted) {
showDelegateNoAccessModal();
} else if (isAnyTransactionOnHold) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1064,7 +1064,6 @@ function MoneyRequestReportActionsList({reportID: reportIDProp, onLayout}: Money
hasNonHeldExpenses={!hasOnlyHeldExpenses}
onConfirm={handleHoldMenuConfirm}
transactionCount={transactions.length}
transactions={transactionsWithoutPendingDelete}
/>
)}
</>
Expand Down
5 changes: 0 additions & 5 deletions src/components/ProcessMoneyReportHoldMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,6 @@ type ProcessMoneyReportHoldMenuProps = {

/** Whether the report has non held expenses */
hasNonHeldExpenses?: boolean;

/** Transactions associated with report */
transactions?: OnyxTypes.Transaction[];
};

function ProcessMoneyReportHoldMenu({
Expand All @@ -62,7 +59,6 @@ function ProcessMoneyReportHoldMenu({
transactionCount,
onConfirm,
hasNonHeldExpenses,
transactions,
}: ProcessMoneyReportHoldMenuProps) {
const {translate} = useLocalize();
// We need to use isSmallScreenWidth instead of shouldUseNarrowLayout to apply the correct modal type
Expand All @@ -77,7 +73,6 @@ function ProcessMoneyReportHoldMenu({
methodID,
onClose,
onConfirm,
transactions,
});

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import StatusBadge from '@components/StatusBadge';
import Text from '@components/Text';
import {useMemoizedLazyExpensifyIcons} from '@hooks/useLazyAsset';
import useLocalize from '@hooks/useLocalize';
import useNonReimbursablePaymentModal from '@hooks/useNonReimbursablePaymentModal';
import useOnyx from '@hooks/useOnyx';
import usePaymentAnimations from '@hooks/usePaymentAnimations';
import useResponsiveLayout from '@hooks/useResponsiveLayout';
Expand Down Expand Up @@ -157,7 +156,6 @@ function MoneyRequestReportPreviewContent({

const [isHoldMenuVisible, setIsHoldMenuVisible] = useState(false);
const [requestType, setRequestType] = useState<ActionHandledType>();
const {showNonReimbursablePaymentErrorModal} = useNonReimbursablePaymentModal(iouReport, transactions);
const [paymentType, setPaymentType] = useState<PaymentMethodType>();
const [shouldShowPayButton, setShouldShowPayButton] = useState(false);
const hasOnlyHeldExpenses = hasOnlyHeldExpensesReportUtils(iouReport?.reportID);
Expand Down Expand Up @@ -710,7 +708,6 @@ function MoneyRequestReportPreviewContent({
onPaymentOptionsHide={onPaymentOptionsHide}
openReportFromPreview={openReportFromPreview}
onHoldMenuOpen={handleHoldMenuOpen}
onNonReimbursablePaymentError={showNonReimbursablePaymentErrorModal}
transactionPreviewCarouselWidth={reportPreviewStyles.transactionPreviewCarouselStyle.width}
/>
{transactions.length > 1 && !shouldShowAccessPlaceHolder && (
Expand Down Expand Up @@ -747,7 +744,6 @@ function MoneyRequestReportPreviewContent({
chatReport={chatReport}
moneyRequestReport={iouReport}
transactionCount={numberOfRequests}
transactions={transactions}
hasNonHeldExpenses={!hasOnlyHeldExpenses}
onConfirm={() => {
if (requestType === CONST.IOU.REPORT_ACTION_TYPE.APPROVE) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,7 @@ import usePermissions from '@hooks/usePermissions';
import usePolicy from '@hooks/usePolicy';
import useReportTransactionsCollection from '@hooks/useReportTransactionsCollection';
import {getTotalAmountForIOUReportPreviewButton} from '@libs/MoneyRequestReportUtils';
import {
hasHeldExpenses as hasHeldExpensesReportUtils,
hasOnlyNonReimbursableTransactions,
hasUpdatedTotal,
hasViolations as hasViolationsReportUtils,
isInvoiceReport as isInvoiceReportUtils,
} from '@libs/ReportUtils';
import {hasHeldExpenses as hasHeldExpensesReportUtils, hasUpdatedTotal, hasViolations as hasViolationsReportUtils, isInvoiceReport as isInvoiceReportUtils} from '@libs/ReportUtils';
import {approveMoneyRequest, canIOUBePaid as canIOUBePaidIOUActions, payInvoice, payMoneyRequest} from '@userActions/IOU';
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
Expand All @@ -38,7 +32,6 @@ type PayActionButtonProps = {
onPaymentOptionsShow?: () => void;
onPaymentOptionsHide?: () => void;
onHoldMenuOpen: (requestType: string, paymentType?: PaymentMethodType, canPay?: boolean) => void;
onNonReimbursablePaymentError?: () => void;
buttonMaxWidth: {maxWidth?: number};
reportPreviewAction: ValueOf<typeof CONST.REPORT.REPORT_PREVIEW_ACTIONS>;
};
Expand All @@ -54,7 +47,6 @@ function PayActionButton({
onPaymentOptionsShow,
onPaymentOptionsHide,
onHoldMenuOpen,
onNonReimbursablePaymentError,
buttonMaxWidth,
reportPreviewAction,
}: PayActionButtonProps) {
Expand Down Expand Up @@ -97,15 +89,12 @@ function PayActionButton({
const hasViolations = hasViolationsReportUtils(iouReport?.reportID, transactionViolations, currentUserAccountID, currentUserEmail);

const canIOUBePaid = canIOUBePaidIOUActions(iouReport, chatReport, policy, bankAccountList, transactions, false, undefined, invoiceReceiverPolicy);
const reportHasOnlyNonReimbursableTransactions = hasOnlyNonReimbursableTransactions(iouReport?.reportID, transactions);
const onlyShowPayElsewhere = reportHasOnlyNonReimbursableTransactions
? false
: !canIOUBePaid && canIOUBePaidIOUActions(iouReport, chatReport, policy, bankAccountList, transactions, true, undefined, invoiceReceiverPolicy);
const shouldShowPayButton = isPaidAnimationRunning || canIOUBePaid || onlyShowPayElsewhere || (reportHasOnlyNonReimbursableTransactions && (iouReport?.total ?? 0) !== 0);
const onlyShowPayElsewhere = !canIOUBePaid && canIOUBePaidIOUActions(iouReport, chatReport, policy, bankAccountList, transactions, true, undefined, invoiceReceiverPolicy);
const shouldShowPayButton = isPaidAnimationRunning || canIOUBePaid || onlyShowPayElsewhere;
const shouldShowOnlyPayElsewhere = !canIOUBePaid && onlyShowPayElsewhere;
const canIOUBePaidAndApproved = canIOUBePaid;

const formattedAmount = getTotalAmountForIOUReportPreviewButton(iouReport, policy, reportPreviewAction, transactions);
const formattedAmount = getTotalAmountForIOUReportPreviewButton(iouReport, policy, reportPreviewAction);

const confirmApproval = () => {
if (isDelegateAccessRestricted) {
Expand Down Expand Up @@ -136,10 +125,6 @@ function PayActionButton({
if (!type) {
return;
}
if (!isInvoiceReportUtils(iouReport) && reportHasOnlyNonReimbursableTransactions && type !== CONST.IOU.PAYMENT_TYPE.ELSEWHERE) {
onNonReimbursablePaymentError?.();
return;
}
if (isDelegateAccessRestricted) {
showDelegateNoAccessModal();
} else if (hasHeldExpensesReportUtils(iouReport?.reportID)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ type ReportPreviewActionButtonProps = {
startSubmittingAnimation: () => void;
onPaymentOptionsShow?: () => void;
onPaymentOptionsHide?: () => void;
onNonReimbursablePaymentError?: () => void;
openReportFromPreview: () => void;
onHoldMenuOpen: (requestType: string, paymentType?: PaymentMethodType, canPay?: boolean) => void;
transactionPreviewCarouselWidth: number;
Expand All @@ -57,7 +56,6 @@ function ReportPreviewActionButton({
startSubmittingAnimation,
onPaymentOptionsShow,
onPaymentOptionsHide,
onNonReimbursablePaymentError,
openReportFromPreview,
onHoldMenuOpen,
transactionPreviewCarouselWidth,
Expand Down Expand Up @@ -156,7 +154,6 @@ function ReportPreviewActionButton({
onPaymentOptionsShow={onPaymentOptionsShow}
onPaymentOptionsHide={onPaymentOptionsHide}
onHoldMenuOpen={onHoldMenuOpen}
onNonReimbursablePaymentError={onNonReimbursablePaymentError}
buttonMaxWidth={buttonMaxWidth}
reportPreviewAction={reportPreviewAction}
/>
Expand Down
11 changes: 0 additions & 11 deletions src/components/Search/SearchBulkActionsButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,11 @@ function SearchBulkActionsButton({queryJSON}: SearchBulkActionsButtonProps) {
confirmPayment,
isOfflineModalVisible,
isDownloadErrorModalVisible,
isNonReimbursablePaymentErrorModalVisible,
isHoldEducationalModalVisible,
rejectModalAction,
emptyReportsCount,
handleOfflineModalClose,
handleDownloadErrorModalClose,
handleNonReimbursablePaymentErrorModalClose,
dismissModalAndUpdateUseHold,
dismissRejectModalBasedOnAction,
isDuplicateOptionVisible,
Expand Down Expand Up @@ -243,15 +241,6 @@ function SearchBulkActionsButton({queryJSON}: SearchBulkActionsButtonProps) {
isVisible={isDownloadErrorModalVisible}
onClose={handleDownloadErrorModalClose}
/>
<DecisionModal
title={translate('iou.error.nonReimbursablePayment')}
prompt={translate('iou.error.nonReimbursablePaymentDescription', selectedItemsCount > 1)}
isSmallScreenWidth={isSmallScreenWidth}
onSecondOptionSubmit={handleNonReimbursablePaymentErrorModalClose}
secondOptionText={translate('common.buttonConfirm')}
isVisible={isNonReimbursablePaymentErrorModalVisible}
onClose={handleNonReimbursablePaymentErrorModalClose}
/>
{!!rejectModalAction && (
<HoldOrRejectEducationalModal
onClose={dismissRejectModalBasedOnAction}
Expand Down
Loading
Loading