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/ONYXKEYS.ts
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,9 @@ const ONYXKEYS = {
/** The policyID of the last workspace whose settings were accessed by the user */
LAST_ACCESSED_WORKSPACE_POLICY_ID: 'lastAccessedWorkspacePolicyID',

/** The policyID of the last workspace whose were accessed by the user via workspace switcher */

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
/** The policyID of the last workspace whose were accessed by the user via workspace switcher */
/** The policyID of the last workspace that was accessed by the user via workspace switcher */

LAST_ACCESSED_WORKSPACE_SWITCHER_ID: 'lastAccessedWorkspaceSwitcherID',

/** Whether we should show the compose input or not */
SHOULD_SHOW_COMPOSE_INPUT: 'shouldShowComposeInput',

Expand Down Expand Up @@ -1030,6 +1033,7 @@ type OnyxValuesMapping = {
[ONYXKEYS.HAS_LOADED_APP]: boolean;
[ONYXKEYS.WALLET_TRANSFER]: OnyxTypes.WalletTransfer;
[ONYXKEYS.LAST_ACCESSED_WORKSPACE_POLICY_ID]: string;
[ONYXKEYS.LAST_ACCESSED_WORKSPACE_SWITCHER_ID]: string;
[ONYXKEYS.SHOULD_SHOW_COMPOSE_INPUT]: boolean;
[ONYXKEYS.IS_BETA]: boolean;
[ONYXKEYS.IS_CHECKING_PUBLIC_ROOM]: boolean;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import type {CommonActions, RouterConfigOptions, StackActionType, StackNavigationState} from '@react-navigation/native';
import {StackActions} from '@react-navigation/native';
import type {ParamListBase, Router} from '@react-navigation/routers';
import Onyx from 'react-native-onyx';
import type {OnyxEntry} from 'react-native-onyx';
import Log from '@libs/Log';
import getPolicyIDFromState from '@libs/Navigation/helpers/getPolicyIDFromState';
import type {RootNavigatorParamList, State} from '@libs/Navigation/types';
import * as SearchQueryUtils from '@libs/SearchQueryUtils';
import NAVIGATORS from '@src/NAVIGATORS';
import ONYXKEYS from '@src/ONYXKEYS';
import SCREENS from '@src/SCREENS';
import type {OpenWorkspaceSplitActionType, PushActionType, ReplaceActionType, SwitchPolicyIdActionType} from './types';

Expand All @@ -28,6 +31,12 @@ const MODAL_ROUTES_TO_DISMISS: string[] = [
const workspaceSplitsWithoutEnteringAnimation = new Set();
const reportsSplitsWithEnteringAnimation = new Set();

let lastAccessedWorkspaceSwitcherID: OnyxEntry<string>;
Onyx.connect({
key: ONYXKEYS.LAST_ACCESSED_WORKSPACE_SWITCHER_ID,
callback: (value) => (lastAccessedWorkspaceSwitcherID = value),
});

/**
* Handles the OPEN_WORKSPACE_SPLIT action.
* If the user is on other tab than settings and the workspace split is "remembered", this action will be called after pressing the settings tab.
Expand Down Expand Up @@ -153,11 +162,16 @@ function handlePushReportSplitAction(
const haveParamsPolicyID = action.payload.params && 'policyID' in action.payload.params;
let policyID;

const policyIDFromState = getPolicyIDFromState(state as State<RootNavigatorParamList>);

if (haveParamsPolicyID) {
policyID = (action.payload.params as Record<string, string | undefined>)?.policyID;
setActiveWorkspaceID(policyID);
} else if (policyIDFromState) {
policyID = policyIDFromState;
} else {
policyID = getPolicyIDFromState(state as State<RootNavigatorParamList>);
policyID = lastAccessedWorkspaceSwitcherID;
setActiveWorkspaceID(policyID);
}

const modifiedAction = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import type {CommonActions, RouterConfigOptions, StackActionType, StackNavigatio
import {findFocusedRoute, StackRouter} from '@react-navigation/native';
import type {ParamListBase} from '@react-navigation/routers';
import useActiveWorkspace from '@hooks/useActiveWorkspace';
import {updateLastAccessedWorkspaceSwitcher} from '@libs/actions/Policy/Policy';
import * as Localize from '@libs/Localize';
import {isOnboardingFlowName} from '@libs/Navigation/helpers/isNavigatorName';
import isSideModalNavigator from '@libs/Navigation/helpers/isSideModalNavigator';
Expand Down Expand Up @@ -78,7 +79,11 @@ function isNavigatingToModalFromModal(state: StackNavigationState<ParamListBase>

function RootStackRouter(options: RootStackNavigatorRouterOptions) {
const stackRouter = StackRouter(options);
const {setActiveWorkspaceID} = useActiveWorkspace();
const {setActiveWorkspaceID: setActiveWorkspaceIDUtils} = useActiveWorkspace();
const setActiveWorkspaceID = (workspaceID: string | undefined) => {
setActiveWorkspaceIDUtils?.(workspaceID);
updateLastAccessedWorkspaceSwitcher(workspaceID);
};

return {
...stackRouter,
Expand Down
8 changes: 8 additions & 0 deletions src/libs/actions/Policy/Policy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,13 @@ function updateLastAccessedWorkspace(policyID: OnyxEntry<string>) {
Onyx.set(ONYXKEYS.LAST_ACCESSED_WORKSPACE_POLICY_ID, policyID ?? null);
}

/**
* Stores in Onyx the policy ID of the last workspace that was accessed by the user via workspace switcher
*/
function updateLastAccessedWorkspaceSwitcher(policyID: OnyxEntry<string>) {
Onyx.set(ONYXKEYS.LAST_ACCESSED_WORKSPACE_SWITCHER_ID, policyID ?? null);
}

/**
* Checks if the currency is supported for direct reimbursement
* USD currency is the only one supported in NewDot for now
Expand Down Expand Up @@ -5161,6 +5168,7 @@ export {
updateDefaultPolicy,
getAssignedSupportData,
downgradeToTeam,
updateLastAccessedWorkspaceSwitcher,
};

export type {NewCustomUnit};