Skip to content

Commit 261a18d

Browse files
authored
Merge pull request Expensify#62003 from software-mansion-labs/korytko/fix-amount-disappearing-from-pay-button
Fix "Pay" & "Approve" buttons inside the report & when expenses are held
2 parents e4f62dd + b0f959d commit 261a18d

4 files changed

Lines changed: 14 additions & 73 deletions

File tree

src/components/MoneyReportHeader.tsx

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@ import useTheme from '@hooks/useTheme';
1717
import useThemeStyles from '@hooks/useThemeStyles';
1818
import {turnOffMobileSelectionMode} from '@libs/actions/MobileSelectionMode';
1919
import {downloadReportPDF, exportReportToCSV, exportReportToPDF, exportToIntegration, markAsManuallyExported, openUnreportedExpense} from '@libs/actions/Report';
20-
import {convertToDisplayString} from '@libs/CurrencyUtils';
21-
import {getThreadReportIDsForTransactions} from '@libs/MoneyRequestReportUtils';
20+
import {getThreadReportIDsForTransactions, getTotalAmountForIOUReportPreviewButton} from '@libs/MoneyRequestReportUtils';
2221
import Navigation from '@libs/Navigation/Navigation';
2322
import {buildOptimisticNextStepForPreventSelfApprovalsEnabled} from '@libs/NextStepUtils';
2423
import {getConnectedIntegration} from '@libs/PolicyUtils';
@@ -31,7 +30,6 @@ import {
3130
getBankAccountRoute,
3231
getIntegrationIcon,
3332
getIntegrationNameFromExportMessage as getIntegrationNameFromExportMessageUtils,
34-
getMoneyRequestSpendBreakdown,
3533
getNonHeldAndFullAmount,
3634
getTransactionsWithReceipts,
3735
hasHeldExpenses as hasHeldExpensesReportUtils,
@@ -179,7 +177,6 @@ function MoneyReportHeader({policy, report: moneyRequestReport, transactionThrea
179177
const theme = useTheme();
180178
const {translate} = useLocalize();
181179
const {isOffline} = useNetwork();
182-
const {reimbursableSpend} = getMoneyRequestSpendBreakdown(moneyRequestReport);
183180
const isOnHold = isOnHoldTransactionUtils(transaction);
184181

185182
const [isHoldMenuVisible, setIsHoldMenuVisible] = useState(false);
@@ -285,10 +282,8 @@ function MoneyReportHeader({policy, report: moneyRequestReport, transactionThrea
285282

286283
const shouldShowNextStep = isFromPaidPolicy && !!optimisticNextStep?.message?.length && !shouldShowStatusBar;
287284
const bankAccountRoute = getBankAccountRoute(chatReport);
288-
const formattedAmount = convertToDisplayString(reimbursableSpend, moneyRequestReport?.currency);
289285
const {nonHeldAmount, fullAmount, hasValidNonHeldAmount} = getNonHeldAndFullAmount(moneyRequestReport, shouldShowPayButton);
290286
const isAnyTransactionOnHold = hasHeldExpensesReportUtils(moneyRequestReport?.reportID);
291-
const displayedAmount = isAnyTransactionOnHold && canAllowSettlement && hasValidNonHeldAmount ? nonHeldAmount : formattedAmount;
292287
const {isDelegateAccessRestricted} = useDelegateUserDetails();
293288
const [isNoDelegateAccessMenuVisible, setIsNoDelegateAccessMenuVisible] = useState(false);
294289
const [isLoadingReportData] = useOnyx(ONYXKEYS.IS_LOADING_REPORT_DATA, {canBeMissing: true});
@@ -460,6 +455,10 @@ function MoneyReportHeader({policy, report: moneyRequestReport, transactionThrea
460455
[moneyRequestReport?.reportID, translate],
461456
);
462457

458+
const getAmount = (actionType: ValueOf<typeof CONST.REPORT.REPORT_PREVIEW_ACTIONS>) => ({
459+
formattedAmount: getTotalAmountForIOUReportPreviewButton(moneyRequestReport, policy, actionType),
460+
});
461+
463462
const primaryActionsImplementation = {
464463
[CONST.REPORT.PRIMARY_ACTIONS.SUBMIT]: (
465464
<Button
@@ -477,7 +476,7 @@ function MoneyReportHeader({policy, report: moneyRequestReport, transactionThrea
477476
<Button
478477
success
479478
onPress={confirmApproval}
480-
text={translate('iou.approve')}
479+
text={translate('iou.approve', getAmount(CONST.REPORT.PRIMARY_ACTIONS.APPROVE))}
481480
/>
482481
),
483482
[CONST.REPORT.PRIMARY_ACTIONS.PAY]: (
@@ -498,7 +497,7 @@ function MoneyReportHeader({policy, report: moneyRequestReport, transactionThrea
498497
shouldHidePaymentOptions={!shouldShowPayButton}
499498
shouldShowApproveButton={shouldShowApproveButton}
500499
shouldDisableApproveButton={shouldDisableApproveButton}
501-
formattedAmount={!hasOnlyHeldExpenses ? displayedAmount : ''}
500+
formattedAmount={getAmount(CONST.REPORT.PRIMARY_ACTIONS.PAY).formattedAmount}
502501
isDisabled={isOffline && !canAllowSettlement}
503502
isLoading={!isOffline && !canAllowSettlement}
504503
/>
@@ -626,7 +625,7 @@ function MoneyReportHeader({policy, report: moneyRequestReport, transactionThrea
626625
},
627626
},
628627
[CONST.REPORT.SECONDARY_ACTIONS.APPROVE]: {
629-
text: translate('iou.approve'),
628+
text: translate('iou.approve', getAmount(CONST.REPORT.SECONDARY_ACTIONS.APPROVE)),
630629
icon: Expensicons.ThumbsUp,
631630
value: CONST.REPORT.SECONDARY_ACTIONS.APPROVE,
632631
onSelected: () => {

src/components/ReportActionItem/MoneyRequestReportPreview/MoneyRequestReportPreviewContent.tsx

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ import {
5959
isTripRoom as isTripRoomReportUtils,
6060
isWaitingForSubmissionFromCurrentUser as isWaitingForSubmissionFromCurrentUserReportUtils,
6161
} from '@libs/ReportUtils';
62-
import {getMerchant, hasPendingUI, isCardTransaction, isPartialMerchant, isPending} from '@libs/TransactionUtils';
62+
import {hasPendingUI, isCardTransaction, isPending} from '@libs/TransactionUtils';
6363
import colors from '@styles/theme/colors';
6464
import variables from '@styles/variables';
6565
import {approveMoneyRequest, canIOUBePaid as canIOUBePaidIOUActions, payInvoice, payMoneyRequest, startMoneyRequest, submitReport} from '@userActions/IOU';
@@ -185,12 +185,6 @@ function MoneyRequestReportPreviewContent({
185185
const hasReceipts = transactionsWithReceipts.length > 0;
186186
const isScanning = hasReceipts && areAllRequestsBeingSmartScanned;
187187

188-
let formattedMerchant = numberOfRequests === 1 ? getMerchant(lastTransaction) : undefined;
189-
190-
if (isPartialMerchant(formattedMerchant ?? '')) {
191-
formattedMerchant = undefined;
192-
}
193-
194188
// The submit button should be success green color only if the user is submitter and the policy does not have Scheduled Submit turned on
195189
const isWaitingForSubmissionFromCurrentUser = useMemo(() => isWaitingForSubmissionFromCurrentUserReportUtils(chatReport, policy), [chatReport, policy]);
196190
const [isNoDelegateAccessMenuVisible, setIsNoDelegateAccessMenuVisible] = useState(false);
@@ -495,7 +489,7 @@ function MoneyRequestReportPreviewContent({
495489
),
496490
[CONST.REPORT.REPORT_PREVIEW_ACTIONS.APPROVE]: (
497491
<Button
498-
text={translate('iou.approve')}
492+
text={translate('iou.approve', {formattedAmount: getTotalAmountForIOUReportPreviewButton(iouReport, policy, reportPreviewAction)})}
499493
success
500494
onPress={() => confirmApproval()}
501495
/>

src/libs/MoneyRequestReportUtils.ts

Lines changed: 0 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -91,60 +91,6 @@ function shouldDisplayReportTableView(report: OnyxEntry<Report>, transactions: T
9191
return !isReportTransactionThread(report) && !isSingleTransactionReport(report, transactions);
9292
}
9393

94-
/* This function is a legacy used for old version of MoneyReportHeader & ReportPreview, do not use it in new versions or anywhere else */
95-
/**
96-
* Determines the appropriate button type for the IOU Report Preview based on the given flags.
97-
*
98-
* @param flags - An object containing boolean flags indicating button visibility options.
99-
* @param flags.shouldShowSubmitButton - Flag indicating if the submit button should be shown.
100-
* @param flags.shouldShowExportIntegrationButton - Flag indicating if the export integration button should be shown.
101-
* @param flags.shouldShowRBR - Flag indicating if the RBR button should be shown.
102-
* @param flags.shouldShowSettlementButton - Flag indicating if the settlement button should be shown.
103-
* @param flags.shouldShowPayButton - Flag indicating if the pay button should be shown.
104-
* @param flags.shouldShowApproveButton - Flag indicating if the approve button should be shown.
105-
* @returns - Returns the type of button that should be displayed based on the input flags.
106-
*/
107-
const getIOUReportPreviewButtonType = ({
108-
shouldShowSubmitButton,
109-
shouldShowExportIntegrationButton,
110-
shouldShowApproveButton,
111-
shouldShowSettlementButton,
112-
shouldShowPayButton,
113-
shouldShowRBR,
114-
}: {
115-
shouldShowSubmitButton: boolean;
116-
shouldShowExportIntegrationButton: boolean;
117-
shouldShowRBR: boolean;
118-
shouldShowSettlementButton: boolean;
119-
shouldShowPayButton: boolean;
120-
shouldShowApproveButton: boolean;
121-
}): ValueOf<typeof CONST.REPORT.REPORT_PREVIEW_ACTIONS> => {
122-
const shouldShowSettlementWithoutRBR = shouldShowSettlementButton && !shouldShowRBR;
123-
const shouldShowSettlementOrRBR = shouldShowSettlementButton || shouldShowRBR;
124-
const shouldShowSettlementOrExport = shouldShowSettlementButton || shouldShowExportIntegrationButton;
125-
126-
if (shouldShowSettlementWithoutRBR && shouldShowPayButton) {
127-
return CONST.REPORT.REPORT_PREVIEW_ACTIONS.PAY;
128-
}
129-
if (shouldShowSettlementWithoutRBR && shouldShowApproveButton) {
130-
return CONST.REPORT.REPORT_PREVIEW_ACTIONS.APPROVE;
131-
}
132-
133-
if (!shouldShowSettlementOrRBR && shouldShowExportIntegrationButton) {
134-
return CONST.REPORT.REPORT_PREVIEW_ACTIONS.EXPORT_TO_ACCOUNTING;
135-
}
136-
137-
if (shouldShowRBR && !shouldShowSubmitButton && shouldShowSettlementOrExport) {
138-
return CONST.REPORT.REPORT_PREVIEW_ACTIONS.REVIEW;
139-
}
140-
141-
if (shouldShowSubmitButton) {
142-
return CONST.REPORT.REPORT_PREVIEW_ACTIONS.SUBMIT;
143-
}
144-
145-
return CONST.REPORT.REPORT_PREVIEW_ACTIONS.REVIEW;
146-
};
147-
14894
/**
14995
* Determines the total amount to be displayed based on the selected button type in the IOU Report Preview.
15096
*
@@ -186,7 +132,6 @@ export {
186132
getThreadReportIDsForTransactions,
187133
getTotalAmountForIOUReportPreviewButton,
188134
selectAllTransactionsForReport,
189-
getIOUReportPreviewButtonType,
190135
isSingleTransactionReport,
191136
shouldDisplayReportTableView,
192137
};

src/libs/ReportPrimaryActionUtils.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import {
1919
getMoneyRequestSpendBreakdown,
2020
getParentReport,
2121
hasExportError as hasExportErrorUtil,
22+
hasOnlyHeldExpenses,
2223
isArchivedReport,
2324
isClosedReport as isClosedReportUtils,
2425
isCurrentUserSubmitter,
@@ -269,6 +270,8 @@ function getReportPrimaryAction(
269270
reportNameValuePairs?: ReportNameValuePairs,
270271
reportActions?: ReportAction[],
271272
): ValueOf<typeof CONST.REPORT.PRIMARY_ACTIONS> | '' {
273+
const isPayActionWithAllExpensesHeld = isPayAction(report, policy, reportNameValuePairs) && hasOnlyHeldExpenses(report?.reportID);
274+
272275
if (isAddExpenseAction(report, reportTransactions)) {
273276
return CONST.REPORT.PRIMARY_ACTIONS.ADD_EXPENSE;
274277
}
@@ -281,7 +284,7 @@ function getReportPrimaryAction(
281284
return CONST.REPORT.PRIMARY_ACTIONS.REVIEW_DUPLICATES;
282285
}
283286

284-
if (isRemoveHoldAction(report, reportTransactions)) {
287+
if (isRemoveHoldAction(report, reportTransactions) || isPayActionWithAllExpensesHeld) {
285288
return CONST.REPORT.PRIMARY_ACTIONS.REMOVE_HOLD;
286289
}
287290

0 commit comments

Comments
 (0)