1
- import {
2
- createContext ,
3
- type FC ,
4
- type PropsWithChildren ,
5
- useState ,
6
- } from "react" ;
1
+ import { createContext , type FC , type PropsWithChildren } from "react" ;
7
2
import { useQuery } from "react-query" ;
8
3
import { appearance } from "api/queries/appearance" ;
9
4
import { entitlements } from "api/queries/entitlements" ;
@@ -15,12 +10,14 @@ import type {
15
10
} from "api/typesGenerated" ;
16
11
import { Loader } from "components/Loader/Loader" ;
17
12
import { useAuthenticated } from "contexts/auth/RequireAuth" ;
18
- import { useEffectEvent } from "hooks/hookPolyfills" ;
19
13
import { useEmbeddedMetadata } from "hooks/useEmbeddedMetadata" ;
20
14
21
15
export interface DashboardValue {
16
+ /**
17
+ * @deprecated Do not add new usage of this value. It is being removed as part
18
+ * of the multi-org work.
19
+ */
22
20
organizationId : string ;
23
- setOrganizationId : ( id : string ) => void ;
24
21
entitlements : Entitlements ;
25
22
experiments : Experiments ;
26
23
appearance : AppearanceConfig ;
@@ -32,40 +29,22 @@ export const DashboardContext = createContext<DashboardValue | undefined>(
32
29
33
30
export const DashboardProvider : FC < PropsWithChildren > = ( { children } ) => {
34
31
const { metadata } = useEmbeddedMetadata ( ) ;
35
- const { user, organizationIds } = useAuthenticated ( ) ;
32
+ const { user } = useAuthenticated ( ) ;
36
33
const entitlementsQuery = useQuery ( entitlements ( metadata . entitlements ) ) ;
37
34
const experimentsQuery = useQuery ( experiments ( metadata . experiments ) ) ;
38
35
const appearanceQuery = useQuery ( appearance ( metadata . appearance ) ) ;
39
36
40
37
const isLoading =
41
38
! entitlementsQuery . data || ! appearanceQuery . data || ! experimentsQuery . data ;
42
39
43
- const lastUsedOrganizationId = localStorage . getItem (
44
- `user:${ user . id } .lastUsedOrganizationId` ,
45
- ) ;
46
- const [ activeOrganizationId , setActiveOrganizationId ] = useState ( ( ) =>
47
- lastUsedOrganizationId && organizationIds . includes ( lastUsedOrganizationId )
48
- ? lastUsedOrganizationId
49
- : organizationIds [ 0 ] ,
50
- ) ;
51
-
52
- const setOrganizationId = useEffectEvent ( ( id : string ) => {
53
- if ( ! organizationIds . includes ( id ) ) {
54
- throw new ReferenceError ( "Invalid organization ID" ) ;
55
- }
56
- localStorage . setItem ( `user:${ user . id } .lastUsedOrganizationId` , id ) ;
57
- setActiveOrganizationId ( id ) ;
58
- } ) ;
59
-
60
40
if ( isLoading ) {
61
41
return < Loader fullscreen /> ;
62
42
}
63
43
64
44
return (
65
45
< DashboardContext . Provider
66
46
value = { {
67
- organizationId : activeOrganizationId ,
68
- setOrganizationId : setOrganizationId ,
47
+ organizationId : user . organization_ids [ 0 ] ?? "default" ,
69
48
entitlements : entitlementsQuery . data ,
70
49
experiments : experimentsQuery . data ,
71
50
appearance : appearanceQuery . data ,
0 commit comments