Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: the user is navigated without showing the Not Found Page when deleting a money request or IOU report #33041

Merged
merged 13 commits into from
Dec 20, 2023
35 changes: 32 additions & 3 deletions src/pages/home/ReportScreen.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ function ReportScreen({
const [listHeight, setListHeight] = useState(0);
const [scrollPosition, setScrollPosition] = useState({});

const wasReportAccessibleRef = useRef(false);
if (firstRenderRef.current) {
Timing.start(CONST.TIMING.CHAT_RENDER);
Performance.markStart(CONST.TIMING.CHAT_RENDER);
Expand Down Expand Up @@ -197,6 +198,13 @@ function ReportScreen({
const isTopMostReportId = currentReportID === getReportID(route);
const didSubscribeToReportLeavingEvents = useRef(false);

useEffect(() => {
if (!report || !report.reportID || shouldHideReport) {
return;
}
wasReportAccessibleRef.current = true;
}, [shouldHideReport, report]);

const goBack = useCallback(() => {
Navigation.goBack(ROUTES.HOME, false, true);
}, []);
Expand Down Expand Up @@ -341,7 +349,8 @@ function ReportScreen({
prevOnyxReportID === routeReportID &&
!onyxReportID &&
prevReport.statusNum === CONST.REPORT.STATUS.OPEN &&
(report.statusNum === CONST.REPORT.STATUS.CLOSED || (!report.statusNum && !prevReport.parentReportID && prevReport.chatType === CONST.REPORT.CHAT_TYPE.POLICY_ROOM)))
(report.statusNum === CONST.REPORT.STATUS.CLOSED || (!report.statusNum && !prevReport.parentReportID && prevReport.chatType === CONST.REPORT.CHAT_TYPE.POLICY_ROOM))) ||
((ReportUtils.isMoneyRequest(prevReport) || ReportUtils.isMoneyRequestReport(prevReport)) && _.isEmpty(report))
) {
Navigation.dismissModal();
if (Navigation.getTopmostReportId() === prevOnyxReportID) {
Expand All @@ -366,7 +375,19 @@ function ReportScreen({

fetchReportIfNeeded();
ComposerActions.setShouldShowComposeInput(true);
}, [route, report, errors, fetchReportIfNeeded, prevReport.reportID, prevUserLeavingStatus, userLeavingStatus, prevReport.statusNum, prevReport.parentReportID, prevReport.chatType]);
}, [
route,
report,
errors,
fetchReportIfNeeded,
prevReport.reportID,
prevUserLeavingStatus,
userLeavingStatus,
prevReport.statusNum,
prevReport.parentReportID,
prevReport.chatType,
prevReport,
]);

useEffect(() => {
if (!ReportUtils.isValidReportIDFromPath(reportID)) {
Expand Down Expand Up @@ -395,7 +416,15 @@ function ReportScreen({

// eslint-disable-next-line rulesdir/no-negated-variables
const shouldShowNotFoundPage = useMemo(
() => (!firstRenderRef.current && !report.reportID && !isOptimisticDelete && !reportMetadata.isLoadingInitialReportActions && !isLoading && !userLeavingStatus) || shouldHideReport,
() =>
(!wasReportAccessibleRef.current &&
!firstRenderRef.current &&
!report.reportID &&
!isOptimisticDelete &&
!reportMetadata.isLoadingInitialReportActions &&
!isLoading &&
!userLeavingStatus) ||
shouldHideReport,
[report, reportMetadata, isLoading, shouldHideReport, isOptimisticDelete, userLeavingStatus],
);

Expand Down
Loading