Skip to content
Open
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
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
17 changes: 2 additions & 15 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
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,18 +15,13 @@ 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';
import ONYXKEYS from '@src/ONYXKEYS';
import ROUTES from '@src/ROUTES';
import type {Transaction} from '@src/types/onyx';
import useConfirmApproval from './useConfirmApproval';
import useTransactionThreadData from './useTransactionThreadData';

Expand Down Expand Up @@ -71,18 +65,16 @@ function PayPrimaryAction({reportID, chatReportID, isPaidAnimationRunning, isApp
const {transactions: reportTransactionsMap} = useTransactionsAndViolationsForReport(moneyRequestReport?.reportID);
const transactions = Object.values(reportTransactionsMap);
const hasOnlyPendingTransactions = transactions.length > 0 && transactions.every((t) => isExpensifyCardTransaction(t) && isPending(t));
const nonPendingDeleteTransactions = transactions.filter((t): t is Transaction => !!t && (isOffline || t.pendingAction !== CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE));

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);
const totalAmount = getTotalAmountForIOUReportPreviewButton(moneyRequestReport, policy, CONST.REPORT.PRIMARY_ACTIONS.PAY);
const totalAmount = getTotalAmountForIOUReportPreviewButton(moneyRequestReport, policy, CONST.REPORT.PRIMARY_ACTIONS.PAY, nonPendingDeleteTransactions);
const isAnyTransactionOnHold = hasHeldExpensesReportUtils(moneyRequestReport?.reportID);

const {currentSearchQueryJSON, currentSearchKey, currentSearchResults} = useSearchStateContext();
Expand All @@ -96,10 +88,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,11 +89,8 @@ 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;

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
Loading
Loading