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
30 changes: 30 additions & 0 deletions src/libs/ReportUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3135,6 +3135,35 @@ 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)) {
const participantAccountIDs = report?.participantAccountIDs ?? [];

if (isSelfDM(report)) {
Navigation.goBack(ROUTES.PROFILE.getRoute(currentUserAccountID ?? 0));
return;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

We don't need this.

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 updated.


if (isOneOnOneChat(report)) {
Navigation.goBack(ROUTES.PROFILE.getRoute(participantAccountIDs[0]));
return;
}

if (report?.reportID) {
Navigation.goBack(ROUTES.REPORT_WITH_ID_DETAILS.getRoute(report?.reportID));
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 @@ -6317,6 +6346,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