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 not found page on thread leave #26602

Merged
merged 7 commits into from
Sep 18, 2023
Merged
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
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 @@ -288,6 +302,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 @@ -301,7 +321,7 @@ function ReportScreen({
shouldDisableFocusTrap
>
<FullPageNotFoundView
shouldShow={(!report.reportID && !report.isLoadingReportActions && !isLoading) || shouldHideReport}
shouldShow={shouldShowNotFoundPage}
subtitleKey="notFound.noAccess"
shouldShowCloseButton={false}
shouldShowBackButton={isSmallScreenWidth}
Expand Down
Loading