Skip to content
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
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