Skip to content
Merged
Show file tree
Hide file tree
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
4 changes: 4 additions & 0 deletions src/hooks/useRestoreWorkspacesTabOnNavigate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import NAVIGATORS from '@src/NAVIGATORS';
import ONYXKEYS from '@src/ONYXKEYS';
import type SCREENS from '@src/SCREENS';

import {authTokenTypeSelector} from '@selectors/Session';

import useCurrentUserPersonalDetails from './useCurrentUserPersonalDetails';
import useOnyx from './useOnyx';
import useResponsiveLayout from './useResponsiveLayout';
Expand All @@ -30,6 +32,7 @@ function useRestoreWorkspacesTabOnNavigate() {
const {login: currentUserLogin} = useCurrentUserPersonalDetails();
const [allPolicies] = useOnyx(ONYXKEYS.COLLECTION.POLICY);
const [allDomains] = useOnyx(ONYXKEYS.COLLECTION.DOMAIN);
const [session] = useOnyx(ONYXKEYS.SESSION, {selector: authTokenTypeSelector});

return () => {
// Find the last route the user had open in the Workspaces tab (workspace, domain, or list).
Expand Down Expand Up @@ -74,6 +77,7 @@ function useRestoreWorkspacesTabOnNavigate() {
domain: lastViewedDomain,
lastWorkspacesTabNavigatorRoute,
lastTabNavigatorRoute,
session,
});
};
}
Expand Down
5 changes: 5 additions & 0 deletions src/hooks/useSidebarOrderedReports.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import arraysEqual from '@src/utils/arraysEqual';

import type {ValueOf} from 'type-fest';

import {authTokenTypeSelector} from '@selectors/Session';
import React, {createContext, useCallback, useContext, useEffect, useMemo, useRef, useState} from 'react';

import useCollectionDelta from './useCollectionDelta';
Expand Down Expand Up @@ -121,6 +122,7 @@ function SidebarOrderedReportsContextProvider({
const [guideAccountIDs] = useOnyx(ONYXKEYS.DERIVED.GUIDE_ACCOUNT_IDS);
const prevGuideAccountIDs = usePrevious(guideAccountIDs);
const [conciergeReportID] = useOnyx(ONYXKEYS.CONCIERGE_REPORT_ID);
const [session] = useOnyx(ONYXKEYS.SESSION, {selector: authTokenTypeSelector});
const reportAttributes = useReportAttributes();
const prevReportAttributes = usePrevious(reportAttributes);
const reportAttributesUpdates = useMemo(() => getReportAttributesUpdates(reportAttributes, prevReportAttributes), [reportAttributes, prevReportAttributes]);
Expand Down Expand Up @@ -262,6 +264,7 @@ function SidebarOrderedReportsContextProvider({
currentUserAccountID: accountID,
conciergeReportID,
guideAccountIDs,
session,
});
} else {
Log.info('[useSidebarOrderedReports] building reportsToDisplay from scratch');
Expand All @@ -280,6 +283,7 @@ function SidebarOrderedReportsContextProvider({
reportAttributes,
conciergeReportID,
guideAccountIDs,
session,
});
}

Expand All @@ -303,6 +307,7 @@ function SidebarOrderedReportsContextProvider({
conciergeReportID,
guideAccountIDs,
prevGuideAccountIDs,
session,
]);

// Derive a stable boolean map indicating which reports have drafts.
Expand Down
8 changes: 5 additions & 3 deletions src/libs/Navigation/helpers/navigateToWorkspacesPage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ import {isPendingDeletePolicy, shouldShowPolicy as shouldShowPolicyUtil} from '@
import NAVIGATORS from '@src/NAVIGATORS';
import ROUTES from '@src/ROUTES';
import SCREENS from '@src/SCREENS';
import type {Domain, Policy} from '@src/types/onyx';
import type {Domain, Policy, Session} from '@src/types/onyx';

import type {NavigationState, PartialState} from '@react-navigation/native';
import type {OnyxEntry} from 'react-native-onyx';

import {findFocusedRoute, StackActions, TabActions} from '@react-navigation/native';

Expand All @@ -32,9 +33,10 @@ type Params = {
domain?: Domain;
lastWorkspacesTabNavigatorRoute?: RouteType;
lastTabNavigatorRoute?: RouteType;
session: OnyxEntry<Session>;
};

const navigateToWorkspacesPage = ({currentUserLogin, shouldUseNarrowLayout, policy, domain, lastWorkspacesTabNavigatorRoute, lastTabNavigatorRoute}: Params) => {
const navigateToWorkspacesPage = ({currentUserLogin, shouldUseNarrowLayout, policy, domain, lastWorkspacesTabNavigatorRoute, lastTabNavigatorRoute, session}: Params) => {
const rootState = navigationRef.getRootState();
const focusedRoute = rootState ? findFocusedRoute(rootState) : undefined;
const isOnWorkspacesList = focusedRoute?.name === SCREENS.WORKSPACES_LIST;
Expand Down Expand Up @@ -121,7 +123,7 @@ const navigateToWorkspacesPage = ({currentUserLogin, shouldUseNarrowLayout, poli

// Fallback: any other state, go to the list.
Navigation.navigate(ROUTES.WORKSPACES_LIST.route);
});
}, session);
};

export default navigateToWorkspacesPage;
11 changes: 10 additions & 1 deletion src/libs/SidebarUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import type PriorityMode from '@src/types/onyx/PriorityMode';
import type Report from '@src/types/onyx/Report';
import type ReportAction from '@src/types/onyx/ReportAction';
import type Rule from '@src/types/onyx/Rule';
import type Session from '@src/types/onyx/Session';

import type {Locale as DateFnsLocale} from 'date-fns';
import type {OnyxCollection, OnyxEntry} from 'react-native-onyx';
Expand Down Expand Up @@ -155,6 +156,7 @@ type ShouldDisplayReportInLHNParams = {
currentUserAccountID: number;
hasGuidesEmails: boolean;
conciergeReportID: string | undefined;
session: OnyxEntry<Session>;
};

function shouldDisplayReportInLHN({
Expand All @@ -173,6 +175,7 @@ function shouldDisplayReportInLHN({
currentUserLogin,
conciergeReportID,
hasGuidesEmails,
session,
}: ShouldDisplayReportInLHNParams) {
if (!report) {
return {shouldDisplay: false};
Expand Down Expand Up @@ -218,7 +221,7 @@ function shouldDisplayReportInLHN({
// An anonymous user can only access public rooms, and such a room's notification preference
// defaults to `hidden`. Without this, opening a thread inside the room (which steals focus)
// drops the room from the LHN, leaving the anon user unable to return to it. See #92672.
(isPublicRoom(report) && isAnonymousUser()) ||
(isPublicRoom(report) && isAnonymousUser(session)) ||
isSystemChat ||
!!report.isPinned ||
requiresAttention ||
Expand Down Expand Up @@ -300,6 +303,7 @@ function getReportsToDisplayInLHN({
reportAttributes,
conciergeReportID,
guideAccountIDs,
session,
}: {
currentReportId: string | undefined;
reports: OnyxCollection<Report>;
Expand All @@ -315,6 +319,7 @@ function getReportsToDisplayInLHN({
reportAttributes?: ReportAttributesDerivedValue['reports'];
guideAccountIDs?: GuideAccountIDsDerivedValue;
conciergeReportID: string | undefined;
session: OnyxEntry<Session>;
}) {
rememberLHNUnreadStateBeforeFocus(currentReportId);

Expand Down Expand Up @@ -346,6 +351,7 @@ function getReportsToDisplayInLHN({
hasGuidesEmails: hasExpensifyGuidesEmails(Object.keys(report.participants ?? {}).map(Number), guideAccountIDs),
currentUserAccountID,
conciergeReportID,
session,
});

if (shouldDisplay) {
Expand Down Expand Up @@ -377,6 +383,7 @@ type UpdateReportsToDisplayInLHNProps = {
currentUserAccountID: number;
guideAccountIDs?: GuideAccountIDsDerivedValue;
conciergeReportID: string | undefined;
session: OnyxEntry<Session>;
};

function updateReportsToDisplayInLHN({
Expand All @@ -396,6 +403,7 @@ function updateReportsToDisplayInLHN({
currentUserAccountID,
conciergeReportID,
guideAccountIDs,
session,
}: UpdateReportsToDisplayInLHNProps) {
rememberLHNUnreadStateBeforeFocus(currentReportId);

Expand Down Expand Up @@ -438,6 +446,7 @@ function updateReportsToDisplayInLHN({
hasGuidesEmails: hasExpensifyGuidesEmails(Object.keys(report.participants ?? {}).map(Number), guideAccountIDs),
currentUserAccountID,
conciergeReportID,
session,
});

if (shouldDisplay) {
Expand Down
2 changes: 1 addition & 1 deletion src/libs/interceptAnonymousUser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import * as Session from './actions/Session';
* Checks if user is anonymous. If true, shows the sign in modal, else,
* executes the callback.
*/
// Session is optional while some utility callers (e.g. navigateToWorkspacesPage, SearchUIUtils) still omit it. Refactor issue: https://github.com/Expensify/App/issues/67782
// Session is optional while some utility callers (e.g. SearchUIUtils, tabScreenListeners) still omit it. Refactor issue: https://github.com/Expensify/App/issues/67782
const interceptAnonymousUser = (callback: () => void, session?: OnyxEntry<SessionType>) => {
const isAnonymousUser = Session.isAnonymousUser(session);
if (isAnonymousUser) {
Expand Down
2 changes: 1 addition & 1 deletion src/selectors/Session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ export {
accountIDSelector,
sessionEmailAndAccountIDSelector,
authTokenSelector,
authTokenTypeSelector,
authTokenTypeAndAccountIDSelector,
hasNonAnonymousSessionSelector,
isSupportalSessionSelector,
isDelegateSessionSelector,
isAnonymousSessionSelector,
authTokenTypeSelector,
};
2 changes: 2 additions & 0 deletions tests/actions/IOUTest/TrackExpenseTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ describe('actions/IOU/TrackExpense', () => {
reportAttributes: undefined,
guideAccountIDs: [],
conciergeReportID: undefined,
session: undefined,
});

await Onyx.set(`${ONYXKEYS.COLLECTION.TRANSACTION_DRAFT}${distanceTransaction.transactionID}`, distanceTransaction);
Expand Down Expand Up @@ -235,6 +236,7 @@ describe('actions/IOU/TrackExpense', () => {
reportAttributes: undefined,
guideAccountIDs: [],
conciergeReportID: undefined,
session: undefined,
});

expect(hiddenReportsToDisplay).not.toHaveProperty(selfDMReportKey);
Expand Down
2 changes: 2 additions & 0 deletions tests/perf-local/SidebarUtils.perf-local.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ describe('SidebarUtils', () => {
reportNameValuePairs: {},
guideAccountIDs: [],
conciergeReportID: undefined,
session: undefined,
}),
);
});
Expand All @@ -137,6 +138,7 @@ describe('SidebarUtils', () => {
reportNameValuePairs: {},
guideAccountIDs: [],
conciergeReportID: undefined,
session: undefined,
}),
);
});
Expand Down
Loading
Loading