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

Navigate back to correct page from private note edit page #40951

Merged
merged 12 commits into from
May 28, 2024
16 changes: 16 additions & 0 deletions src/libs/ReportUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3134,6 +3134,21 @@ function goBackToDetailsPage(report: OnyxEntry<Report>) {
Navigation.goBack(ROUTES.REPORT_SETTINGS.getRoute(report?.reportID ?? ''));
}

/**
* Go back to the previous page from the edit private page of a given report
*/
function goBackFromPrivateNotes(report: OnyxEntry<Report>, session: OnyxEntry<Session>) {
if (isEmpty(report) || isEmpty(session) || !session.accountID) {
return;
}
const currentUserPrivateNote = report.privateNotes?.[session.accountID]?.note ?? '';
if (isEmpty(currentUserPrivateNote)) {
goBackToDetailsPage(report);
Copy link
Contributor

Choose a reason for hiding this comment

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

As I said earlier, this will not work correctly.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@shubham1206agra I think this function is missing the selfDM case that appears in navigateToDetailsPage. So I think we can add this case in this function instead of modified a new version of navigateToDetailsPage. WDYT?

Copy link
Contributor

Choose a reason for hiding this comment

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

No the goback page is also wrong here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

What's wrong here. Can you detail? Thanks.

Copy link
Contributor

Choose a reason for hiding this comment

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

It goes to ROUTES.REPORT_SETTINGS instead of ROUTES.REPORT_WITH_ID_DETAILS

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@shubham1206agra Got it. I updated.

return;
}
Navigation.goBack(ROUTES.PRIVATE_NOTES_LIST.getRoute(report.reportID));
}

/**
* Generate a random reportID up to 53 bits aka 9,007,199,254,740,991 (Number.MAX_SAFE_INTEGER).
* There were approximately 98,000,000 reports with sequential IDs generated before we started using this approach, those make up roughly one billionth of the space for these numbers,
Expand Down Expand Up @@ -6289,6 +6304,7 @@ export {
getWorkspaceChats,
getWorkspaceIcon,
goBackToDetailsPage,
goBackFromPrivateNotes,
hasActionsWithErrors,
hasAutomatedExpensifyAccountIDs,
hasExpensifyGuidesEmails,
Expand Down
4 changes: 2 additions & 2 deletions src/pages/PrivateNotes/PrivateNotesEditPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ type PrivateNotesEditPageProps = WithReportAndPrivateNotesOrNotFoundProps &
report: Report;
};

function PrivateNotesEditPage({route, personalDetailsList, report}: PrivateNotesEditPageProps) {
function PrivateNotesEditPage({route, personalDetailsList, report, session}: PrivateNotesEditPageProps) {
const styles = useThemeStyles();
const {translate} = useLocalize();

Expand Down Expand Up @@ -117,7 +117,7 @@ function PrivateNotesEditPage({route, personalDetailsList, report}: PrivateNotes
>
<HeaderWithBackButton
title={translate('privateNotes.title')}
onBackButtonPress={() => Navigation.goBack(ROUTES.PRIVATE_NOTES_LIST.getRoute(report.reportID))}
onBackButtonPress={() => ReportUtils.goBackFromPrivateNotes(report, session)}
shouldShowBackButton
onCloseButtonPress={() => Navigation.dismissModal()}
/>
Expand Down
Loading