Skip to content

Commit 8b49cee

Browse files
author
MargeBot
committed
Merge branch 'VPNB2B-137--disable-spotlight-after-toggle' into 'main'
[VPNB2B-137] Disable spotlight after toggle See merge request web/clients!25511
2 parents 4eafe45 + ec4aeaf commit 8b49cee

1 file changed

Lines changed: 26 additions & 18 deletions

File tree

packages/vpn/src/hooks/useB2BAdminSidebarFeature.ts

Lines changed: 26 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -22,21 +22,30 @@ import { constants } from '../../constants';
2222
import { resolveNavigation } from '../definitions/routes';
2323
import { isB2BAdmin } from '../functions/isB2BAdmin';
2424

25-
const off = false;
26-
const on = true;
25+
const SIDEBAR_OPEN_BY_DEFAULT = true;
2726

28-
const useSidebarState = () => {
29-
const [status, setState] = useLocalState<boolean>(on, constants.AdminSidebarStorageKey);
27+
type SidebarControls = { status: boolean; toggle: () => void };
28+
type SpotlightControls = { isOn: boolean; setOff: () => void };
3029

31-
const toggle = () => setState((previous) => !previous);
32-
return { status, toggle };
33-
};
30+
const useSidebarFeature = (): { sidebar: SidebarControls; spotlight: SpotlightControls } => {
31+
const [status, setStatus] = useLocalState<boolean>(SIDEBAR_OPEN_BY_DEFAULT, constants.AdminSidebarStorageKey);
32+
const [spotlight, setSpotlight] = useDeclarativeLocalState<boolean>(constants.AdminSidebarSpotlightKey);
3433

35-
const useKillableFeature = (key: string) => {
36-
const [isOn, setState] = useDeclarativeLocalState<boolean>(key);
34+
const dismissSpotlight = () => setSpotlight(false);
3735

38-
const setOff = () => setState(off);
39-
return { isOn: isOn !== off, setOff };
36+
return {
37+
sidebar: {
38+
status,
39+
toggle: () => {
40+
setStatus((previous) => !previous);
41+
dismissSpotlight();
42+
},
43+
},
44+
spotlight: {
45+
isOn: spotlight !== false,
46+
setOff: dismissSpotlight,
47+
},
48+
};
4049
};
4150

4251
type Args = {
@@ -52,8 +61,8 @@ export const useB2BAdminSidebarFeature = ({
5261
enabled: true;
5362
routes: SidebarTree;
5463
settings: ReturnType<typeof defineSearchOptions>;
55-
sidebar: ReturnType<typeof useSidebarState>;
56-
spotlight: ReturnType<typeof useKillableFeature>;
64+
sidebar: SidebarControls;
65+
spotlight: SpotlightControls;
5766
loading: false;
5867
}
5968
| { enabled: false; routes: undefined; loading: boolean } => {
@@ -70,8 +79,7 @@ export const useB2BAdminSidebarFeature = ({
7079
const [isSessionRecoveryAvailable] = useIsSessionRecoveryAvailable();
7180
const [permissions] = useOrgPermissions();
7281

73-
const sidebarFeature = useSidebarState();
74-
const spotlightFeature = useKillableFeature(constants.AdminSidebarSpotlightKey);
82+
const { sidebar, spotlight } = useSidebarFeature();
7583

7684
const B2BLogsVPN = useFlag('B2BLogsVPN');
7785
const SsoForPbs = useFlag('SsoForPbs');
@@ -86,7 +94,7 @@ export const useB2BAdminSidebarFeature = ({
8694
user: user.ID,
8795
...(organization ? { organization: organization.ID } : undefined),
8896
isEnabled: true,
89-
isActive: isEnabled && sidebarFeature.status,
97+
isActive: isEnabled && sidebar.status,
9098
};
9199

92100
telemetry.sendCustomEvent('b2b-admin-sidebar-viewed', trackingData);
@@ -125,7 +133,7 @@ export const useB2BAdminSidebarFeature = ({
125133
loading: false,
126134
routes: defineSidebar(prefixedNavigation),
127135
settings: defineSearchOptions(prefixedNavigation),
128-
sidebar: sidebarFeature,
129-
spotlight: spotlightFeature,
136+
sidebar,
137+
spotlight,
130138
};
131139
};

0 commit comments

Comments
 (0)