Skip to content

Commit

Permalink
Merge pull request #56153 from M00rish/Exp#55251
Browse files Browse the repository at this point in the history
Fix not here page shows up briefly when deleting the expense while it is highlighted
  • Loading branch information
roryabraham authored Feb 5, 2025
2 parents 91ced52 + 6f20fd0 commit dca94b3
Showing 1 changed file with 23 additions and 9 deletions.
32 changes: 23 additions & 9 deletions src/pages/home/ReportScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,14 @@ function ReportScreen({route, navigation}: ReportScreenProps) {
() => !!linkedAction && !shouldReportActionBeVisible(linkedAction, linkedAction.reportActionID, canUserPerformWriteAction(report)),
[linkedAction, report],
);

const prevIsLinkedActionDeleted = usePrevious(linkedAction ? isLinkedActionDeleted : undefined);

// eslint-disable-next-line react-compiler/react-compiler
const lastReportActionIDFromRoute = usePrevious(!firstRenderRef.current ? reportActionIDFromRoute : undefined);

const [isNavigatingToDeletedAction, setIsNavigatingToDeletedAction] = useState(false);

const isLinkedActionInaccessibleWhisper = useMemo(
() => !!linkedAction && isWhisperAction(linkedAction) && !(linkedAction?.whisperedToAccountIDs ?? []).includes(currentUserAccountID),
[currentUserAccountID, linkedAction],
Expand Down Expand Up @@ -416,11 +423,9 @@ function ReportScreen({route, navigation}: ReportScreenProps) {
(!!deleteTransactionNavigateBackUrl && getReportIDFromLink(deleteTransactionNavigateBackUrl) === report?.reportID) ||
(!reportMetadata.isOptimisticReport && isLoading);

const isLinkedActionBecomesDeleted = prevIsLinkedActionDeleted !== undefined && !prevIsLinkedActionDeleted && isLinkedActionDeleted;

// eslint-disable-next-line rulesdir/no-negated-variables
const shouldShowNotFoundLinkedAction =
(!isLinkedActionInaccessibleWhisper && isLinkedActionDeleted && !isLinkedActionBecomesDeleted) ||
(!isLinkedActionInaccessibleWhisper && isLinkedActionDeleted && isNavigatingToDeletedAction) ||
(shouldShowSkeleton &&
!reportMetadata.isLoadingInitialReportActions &&
!!reportActionIDFromRoute &&
Expand Down Expand Up @@ -735,13 +740,23 @@ function ReportScreen({route, navigation}: ReportScreenProps) {
}, [fetchReport]);

useEffect(() => {
// If the linked action is previously available but now deleted,
// remove the reportActionID from the params to not link to the deleted action.
if (!isLinkedActionBecomesDeleted) {
// Only handle deletion cases when there's a deleted action
if (!isLinkedActionDeleted) {
setIsNavigatingToDeletedAction(false);
return;
}
Navigation.setParams({reportActionID: ''});
}, [isLinkedActionBecomesDeleted]);

// we want to do this destinguish between normal navigation and delete behavior
if (lastReportActionIDFromRoute !== reportActionIDFromRoute) {
setIsNavigatingToDeletedAction(true);
return;
}

// Clear params when Action gets deleted while heighlighted
if (!isNavigatingToDeletedAction && prevIsLinkedActionDeleted === false) {
Navigation.setParams({reportActionID: ''});
}
}, [isLinkedActionDeleted, prevIsLinkedActionDeleted, lastReportActionIDFromRoute, reportActionIDFromRoute, isNavigatingToDeletedAction]);

// If user redirects to an inaccessible whisper via a deeplink, on a report they have access to,
// then we set reportActionID as empty string, so we display them the report and not the "Not found page".
Expand Down Expand Up @@ -775,7 +790,6 @@ function ReportScreen({route, navigation}: ReportScreenProps) {
!isDeletedAction(mostRecentReportAction);

const lastRoute = usePrevious(route);
const lastReportActionIDFromRoute = usePrevious(reportActionIDFromRoute);

const onComposerFocus = useCallback(() => setIsComposerFocus(true), []);
const onComposerBlur = useCallback(() => setIsComposerFocus(false), []);
Expand Down

0 comments on commit dca94b3

Please sign in to comment.