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
25 changes: 25 additions & 0 deletions src/libs/ReportUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3337,6 +3337,30 @@
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 ?? [];

Check failure on line 3349 in src/libs/ReportUtils.ts

View workflow job for this annotation

GitHub Actions / typecheck

Property 'participantAccountIDs' does not exist on type '{ avatarUrl?: string | undefined; chatType?: ValueOf<{ readonly POLICY_ANNOUNCE: "policyAnnounce"; readonly POLICY_ADMINS: "policyAdmins"; readonly GROUP: "group"; readonly DOMAIN_ALL: "domainAll"; ... 4 more ...; readonly SYSTEM: "system"; }> | undefined; ... 69 more ...; permissions?: ValueOf<...>[] | undefined; }...'.

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 @@ -6799,6 +6823,7 @@
getWorkspaceChats,
getWorkspaceIcon,
goBackToDetailsPage,
goBackFromPrivateNotes,
getInvoicePayerName,
getInvoicesChatName,
getPayeeName,
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