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
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {getButtonRole} from '@components/Button/utils';
import DotIndicatorMessage from '@components/DotIndicatorMessage';
import OfflineWithFeedback from '@components/OfflineWithFeedback';
import PressableWithoutFeedback from '@components/Pressable/PressableWithoutFeedback';
import {showContextMenuForReport, useShowContextMenuActions, useShowContextMenuState} from '@components/ShowContextMenuContext';
Expand Down Expand Up @@ -79,6 +80,7 @@ function MoneyRequestReportPreviewBody({
const {isTransitionPending, isScanning, reportPreviewStyles} = useReportPreviewUIState();

const isReportDeleted = action?.pendingAction === CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE;
const isRejectedReport = iouReport?.stateNum === CONST.REPORT.STATE_NUM.OPEN && iouReport?.nextStep?.messageKey === CONST.NEXT_STEP.MESSAGE_KEY.REJECTED_REPORT;
const totalAmountStyle = shouldUseNarrowLayout ? [styles.flexColumnReverse, styles.alignItemsStretch] : [styles.flexRow, styles.alignItemsCenter];

return (
Expand Down Expand Up @@ -133,6 +135,12 @@ function MoneyRequestReportPreviewBody({
<View style={[reportPreviewStyles.contentContainerStyle, styles.gap4]}>
<ReportPreviewHeader />
<TransactionReportCarousel />
{isRejectedReport && (
<DotIndicatorMessage
type="error"
messages={{rejectedReport: translate('iou.rejectReport.rejectedReportMessage')}}
/>
)}
<View style={[styles.expenseAndReportPreviewTextContainer]}>
<View style={[totalAmountStyle, styles.justifyContentBetween, styles.gap4, StyleUtils.getMinimumHeight(variables.h28)]}>
<ReportPreviewActionButton />
Expand Down
5 changes: 1 addition & 4 deletions src/libs/SearchUIUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3132,10 +3132,7 @@ function getReportSections({
const reportIsArchived = isArchivedReport(getReportNameValuePairsFromKey(data, reportItem));
const avatarProps = getSearchReportAvatarProps(reportItem, formatPhoneNumber, translate, mergedPersonalDetails, policy, reportIsArchived);

const isRejectedReport =
reportItem.stateNum === CONST.REPORT.STATE_NUM.OPEN &&
reportItem.ownerAccountID === currentAccountID &&
reportItem.nextStep?.messageKey === CONST.NEXT_STEP.MESSAGE_KEY.REJECTED_REPORT;
const isRejectedReport = reportItem.stateNum === CONST.REPORT.STATE_NUM.OPEN && reportItem.nextStep?.messageKey === CONST.NEXT_STEP.MESSAGE_KEY.REJECTED_REPORT;
const shouldHidePayAsPrimaryAction = hasOnlyNonReimbursableTransactions(reportItem.reportID, allReportTransactions);
const primaryActionExclusions: SearchTransactionAction[] = [
...(shouldHidePayAsPrimaryAction ? [CONST.SEARCH.ACTION_TYPES.PAY] : []),
Expand Down
70 changes: 70 additions & 0 deletions tests/ui/MoneyRequestReportPreview.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,76 @@ describe('MoneyRequestReportPreview', () => {
expect(screen.getAllByText(TestHelper.translateLocal('violations.reviewRequired'))).toHaveLength(2);
});

it('renders the rejected report message when the report was rejected back to the submitter', async () => {
setReportPreviewData({
iouReport: {
...mockIOUReport,
stateNum: CONST.REPORT.STATE_NUM.OPEN,
statusNum: CONST.REPORT.STATUS_NUM.OPEN,
nextStep: {
messageKey: CONST.NEXT_STEP.MESSAGE_KEY.REJECTED_REPORT,
icon: CONST.NEXT_STEP.ICONS.HOURGLASS,
actorAccountID: mockIOUReport.ownerAccountID,
},
},
});

renderPage({});
await waitForBatchedUpdatesWithAct();
setCurrentWidth();
await act(async () => {
await Onyx.multiSet(mockOnyxTransactions);
});
await waitForBatchedUpdatesWithAct();

expect(screen.getByText(TestHelper.translateLocal('iou.rejectReport.rejectedReportMessage'))).toBeOnTheScreen();
});

it('does not render the rejected report message for a draft report that was never rejected', async () => {
setReportPreviewData({
iouReport: {
...mockIOUReport,
stateNum: CONST.REPORT.STATE_NUM.OPEN,
statusNum: CONST.REPORT.STATUS_NUM.OPEN,
},
});

renderPage({});
await waitForBatchedUpdatesWithAct();
setCurrentWidth();
await act(async () => {
await Onyx.multiSet(mockOnyxTransactions);
});
await waitForBatchedUpdatesWithAct();

expect(screen.queryByText(TestHelper.translateLocal('iou.rejectReport.rejectedReportMessage'))).not.toBeOnTheScreen();
});

it('does not render the rejected report message when the report was rejected to a previous approver', async () => {
setReportPreviewData({
iouReport: {
...mockIOUReport,
stateNum: CONST.REPORT.STATE_NUM.SUBMITTED,
statusNum: CONST.REPORT.STATUS_NUM.SUBMITTED,
nextStep: {
messageKey: CONST.NEXT_STEP.MESSAGE_KEY.WAITING_TO_APPROVE,
icon: CONST.NEXT_STEP.ICONS.HOURGLASS,
actorAccountID: mockIOUReport.managerID,
},
},
});

renderPage({});
await waitForBatchedUpdatesWithAct();
setCurrentWidth();
await act(async () => {
await Onyx.multiSet(mockOnyxTransactions);
});
await waitForBatchedUpdatesWithAct();

expect(screen.queryByText(TestHelper.translateLocal('iou.rejectReport.rejectedReportMessage'))).not.toBeOnTheScreen();
});

it('renders a skeleton if the transaction is empty', async () => {
renderPage({});
await waitForBatchedUpdatesWithAct();
Expand Down
29 changes: 29 additions & 0 deletions tests/unit/Search/SearchUIUtilsTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2801,6 +2801,35 @@ describe('SearchUIUtils', () => {
expect(Object.keys(distanceTransaction ?? {}).length).toBe(expectedPropertyCount);
});

it('should flag a rejected report for a viewer who is not the report owner', () => {
const data = {
...searchResults.data,
[`${ONYXKEYS.COLLECTION.REPORT}${reportID}`]: {
...report1,
nextStep: {messageKey: CONST.NEXT_STEP.MESSAGE_KEY.REJECTED_REPORT},
},
} as OnyxTypes.SearchResults['data'];

const result = getSectionsByType(
SearchUIUtils.getSections({
dateFnsLocale: undefined,
type: CONST.SEARCH.DATA_TYPES.EXPENSE_REPORT,
data,
currentAccountID: approverAccountID,
currentUserEmail: '',
translate: translateLocal,
formatPhoneNumber,
bankAccountList: {},
conciergeReportID: undefined,
convertToDisplayString,
reportAttributesDerivedValue: {},
}),
SearchUIUtils.isTransactionReportGroupListItemType,
)[0];

expect(result.find((group) => group.reportID === reportID)?.isRejectedReport).toBe(true);
});

it('should derive exportedTo from every export action of the report', () => {
const exportedReportID = 'exported-to-report';
const exportedTransactionID = 'exported-to-transaction';
Expand Down
Loading