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 here page shows up briefly when deleting the expense while it is highlighted #56153

Merged
merged 7 commits into from
Feb 5, 2025
Merged
Changes from 3 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
33 changes: 23 additions & 10 deletions src/pages/home/ReportScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,13 @@ function ReportScreen({route, navigation}: ReportScreenProps) {
() => !!linkedAction && !shouldReportActionBeVisible(linkedAction, linkedAction.reportActionID, canUserPerformWriteAction(report)),
[linkedAction, report],
);
const prevIsLinkedActionDeleted = usePrevious(linkedAction ? isLinkedActionDeleted : undefined);

const previsLinkedActionDeleted = usePrevious(linkedAction ? isLinkedActionDeleted : undefined);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed!


const lastReportActionIDFromRoute = usePrevious(reportActionIDFromRoute);

const [isNavigatingToAction, setIsNavigatingToAction] = useState(false);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isNavigatingToAction sounds more broad than it really is I think? it's only true if we're navigating to a deleted action. So I think a more accurate variable name would be isNavigatingToDeletedAction

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you're right, it's updated to isNavigatingToDeletedAction, makes more sense.


const isLinkedActionInaccessibleWhisper = useMemo(
() => !!linkedAction && isWhisperAction(linkedAction) && !(linkedAction?.whisperedToAccountIDs ?? []).includes(currentUserAccountID),
[currentUserAccountID, linkedAction],
Expand Down Expand Up @@ -416,11 +422,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 && isNavigatingToAction) ||
(shouldShowSkeleton &&
!reportMetadata.isLoadingInitialReportActions &&
!!reportActionIDFromRoute &&
Expand Down Expand Up @@ -735,13 +739,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) {
setIsNavigatingToAction(false);
return;
}
Navigation.setParams({reportActionID: ''});
}, [isLinkedActionBecomesDeleted]);

// Set navigation state when user clicks a deleted Action link
if (lastReportActionIDFromRoute !== reportActionIDFromRoute) {
setIsNavigatingToAction(true);
return;
}

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

// 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 +789,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
Loading