Skip to content

Commit

Permalink
Merge pull request #26602 from b4s36t4/fix/thread-not-found-page
Browse files Browse the repository at this point in the history
fix not found page on thread leave
  • Loading branch information
luacmartins authored Sep 18, 2023
2 parents ee26eaf + 07e0a5a commit 9b56a76
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion src/pages/home/ReportScreen.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import ReportScreenContext from './ReportScreenContext';
import TaskHeaderActionButton from '../../components/TaskHeaderActionButton';
import DragAndDropProvider from '../../components/DragAndDrop/Provider';
import usePrevious from '../../hooks/usePrevious';
import CONST from '../../CONST';
import withCurrentReportID, {withCurrentReportIDPropTypes, withCurrentReportIDDefaultProps} from '../../components/withCurrentReportID';

const propTypes = {
Expand Down Expand Up @@ -107,6 +108,15 @@ const defaultProps = {
...withCurrentReportIDDefaultProps,
};

/**
*
* Function to check weather the report available in props is default
*
* @param {Object} report
* @returns {Boolean}
*/
const checkDefaultReport = (report) => report === defaultProps.report;

/**
* Get the currently viewed report ID as number
*
Expand Down Expand Up @@ -151,6 +161,8 @@ function ReportScreen({
// There are no reportActions at all to display and we are still in the process of loading the next set of actions.
const isLoadingInitialReportActions = _.isEmpty(reportActions) && report.isLoadingReportActions;

const isOptimisticDelete = lodashGet(report, 'statusNum') === CONST.REPORT.STATUS.CLOSED;

const shouldHideReport = !ReportUtils.canAccessReport(report, policies, betas);

const isLoading = !reportID || !isSidebarLoaded || _.isEmpty(personalDetails) || firstRenderRef.current;
Expand All @@ -163,6 +175,8 @@ function ReportScreen({

const isTopMostReportId = currentReportID === getReportID(route);

const isDefaultReport = checkDefaultReport(report);

let headerView = (
<HeaderView
reportID={reportID}
Expand Down Expand Up @@ -289,6 +303,12 @@ function ReportScreen({
ComposerActions.setShouldShowComposeInput(true);
}, [route, report, errors, fetchReportIfNeeded, prevReport.reportID]);

// eslint-disable-next-line rulesdir/no-negated-variables
const shouldShowNotFoundPage = useMemo(
() => (!_.isEmpty(report) && !isDefaultReport && !report.reportID && !isOptimisticDelete && !report.isLoadingReportActions && !isLoading) || shouldHideReport,
[report, isLoading, shouldHideReport, isDefaultReport, isOptimisticDelete],
);

return (
<ReportScreenContext.Provider
value={{
Expand All @@ -302,7 +322,7 @@ function ReportScreen({
shouldDisableFocusTrap
>
<FullPageNotFoundView
shouldShow={(!report.reportID && !report.isLoadingReportActions && !isLoading) || shouldHideReport}
shouldShow={shouldShowNotFoundPage}
subtitleKey="notFound.noAccess"
shouldShowCloseButton={false}
shouldShowBackButton={isSmallScreenWidth}
Expand Down

0 comments on commit 9b56a76

Please sign in to comment.