Skip to content

Commit e67e19d

Browse files
committed
fix wrong redirect when creating report from unreported expenses page
1 parent 11385b8 commit e67e19d

File tree

6 files changed

+12
-16
lines changed

6 files changed

+12
-16
lines changed

src/ROUTES.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -2419,8 +2419,8 @@ const ROUTES = {
24192419
getRoute: (policyID: string) => `settings/workspaces/${policyID}/accounting/sage-intacct/advanced/payment-account` as const,
24202420
},
24212421
ADD_UNREPORTED_EXPENSE: {
2422-
route: 'search/r/:reportID/add-unreported-expense',
2423-
getRoute: (reportID: string | undefined) => `search/r/${reportID}/add-unreported-expense` as const,
2422+
route: 'search/r/:reportID/add-unreported-expense/:backToReport?',
2423+
getRoute: (reportID: string | undefined, backToReport?: string) => `search/r/${reportID}/add-unreported-expense/${backToReport ?? ''}` as const,
24242424
},
24252425
DEBUG_REPORT: {
24262426
route: 'debug/report/:reportID',

src/components/ReportActionItem/MoneyRequestReportPreview/MoneyRequestReportPreviewContent.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -484,11 +484,11 @@ function MoneyRequestReportPreviewContent({
484484
text: translate('iou.addUnreportedExpense'),
485485
icon: Expensicons.ReceiptPlus,
486486
onSelected: () => {
487-
openUnreportedExpense(iouReport?.reportID);
487+
openUnreportedExpense(iouReport?.reportID, iouReport?.parentReportID);
488488
},
489489
},
490490
],
491-
[chatReportID, iouReport?.reportID, translate],
491+
[chatReportID, iouReport?.parentReportID, iouReport?.reportID, translate],
492492
);
493493

494494
const isReportDeleted = action?.pendingAction === CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE;

src/components/ReportActionItem/ReportPreview.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -529,11 +529,11 @@ function ReportPreview({
529529
text: translate('iou.addUnreportedExpense'),
530530
icon: Expensicons.ReceiptPlus,
531531
onSelected: () => {
532-
openUnreportedExpense(iouReport?.reportID);
532+
openUnreportedExpense(iouReport?.reportID, iouReport?.parentReportID);
533533
},
534534
},
535535
],
536-
[chatReportID, iouReport?.reportID, translate],
536+
[chatReportID, iouReport?.parentReportID, iouReport?.reportID, translate],
537537
);
538538

539539
const reportPreviewAction = useMemo(() => {

src/libs/Navigation/types.ts

+1
Original file line numberDiff line numberDiff line change
@@ -1977,6 +1977,7 @@ type MissingPersonalDetailsParamList = {
19771977
type AddUnreportedExpensesParamList = {
19781978
[SCREENS.ADD_UNREPORTED_EXPENSES_ROOT]: {
19791979
reportID: string;
1980+
backToReport?: string;
19801981
};
19811982
};
19821983

src/libs/actions/Report.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -466,11 +466,11 @@ function getReportChannelName(reportID: string): string {
466466
return `${CONST.PUSHER.PRIVATE_REPORT_CHANNEL_PREFIX}${reportID}${CONFIG.PUSHER.SUFFIX}`;
467467
}
468468

469-
function openUnreportedExpense(reportID: string | undefined) {
469+
function openUnreportedExpense(reportID: string | undefined, backToReport?: string) {
470470
if (!reportID) {
471471
return;
472472
}
473-
Navigation.navigate(ROUTES.ADD_UNREPORTED_EXPENSE.getRoute(reportID));
473+
Navigation.navigate(ROUTES.ADD_UNREPORTED_EXPENSE.getRoute(reportID, backToReport));
474474
}
475475

476476
/**

src/pages/AddUnreportedExpense.tsx

+3-8
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import type {ListItem, SectionListDataType, SelectionListHandle} from '@componen
1111
import useLocalize from '@hooks/useLocalize';
1212
import useThemeStyles from '@hooks/useThemeStyles';
1313
import interceptAnonymousUser from '@libs/interceptAnonymousUser';
14+
import type {AddUnreportedExpensesParamList} from '@libs/Navigation/types';
1415
import Navigation from '@navigation/Navigation';
1516
import type {PlatformStackScreenProps} from '@navigation/PlatformStackNavigation/types';
1617
import {startMoneyRequest} from '@userActions/IOU';
@@ -24,12 +25,6 @@ import UnreportedExpenseListItem from './UnreportedExpenseListItem';
2425

2526
type AddUnreportedExpensePageType = PlatformStackScreenProps<AddUnreportedExpensesParamList, typeof SCREENS.ADD_UNREPORTED_EXPENSES_ROOT>;
2627

27-
type AddUnreportedExpensesParamList = {
28-
[SCREENS.ADD_UNREPORTED_EXPENSES_ROOT]: {
29-
reportID: string;
30-
};
31-
};
32-
3328
function AddUnreportedExpense({route}: AddUnreportedExpensePageType) {
3429
const {translate} = useLocalize();
3530
const [errorMessage, setErrorMessage] = useState<string>('');
@@ -58,7 +53,7 @@ function AddUnreportedExpense({route}: AddUnreportedExpensePageType) {
5853

5954
const thereIsNoUnreportedTransaction = !((sections.at(0)?.data.length ?? 0) > 0);
6055

61-
const reportID = route.params.reportID;
56+
const {reportID, backToReport} = route.params;
6257
const selectedIds = new Set<string>();
6358
const [report] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${reportID}`, {canBeMissing: true});
6459
return (
@@ -91,7 +86,7 @@ function AddUnreportedExpense({route}: AddUnreportedExpensePageType) {
9186
buttonText: translate('iou.createExpense'),
9287
buttonAction: () => {
9388
interceptAnonymousUser(() => {
94-
startMoneyRequest(CONST.IOU.TYPE.SUBMIT, reportID);
89+
startMoneyRequest(CONST.IOU.TYPE.SUBMIT, reportID, undefined, false, backToReport);
9590
});
9691
},
9792
success: true,

0 commit comments

Comments
 (0)