1
- import type { FC } from "react" ;
1
+ import Button from "@mui/material/Button" ;
2
+ import { type FC , useEffect , useState } from "react" ;
2
3
import { useQuery } from "react-query" ;
3
4
import { groupsForUser } from "api/queries/groups" ;
5
+ import { DisabledBadge , EnabledBadge } from "components/Badges/Badges" ;
4
6
import { Stack } from "components/Stack/Stack" ;
5
7
import { useAuthContext } from "contexts/auth/AuthProvider" ;
6
8
import { useAuthenticated } from "contexts/auth/RequireAuth" ;
@@ -13,14 +15,29 @@ export const AccountPage: FC = () => {
13
15
const { user : me , permissions, organizationId } = useAuthenticated ( ) ;
14
16
const { updateProfile, updateProfileError, isUpdatingProfile } =
15
17
useAuthContext ( ) ;
16
- const { entitlements } = useDashboard ( ) ;
18
+ const { entitlements, experiments } = useDashboard ( ) ;
17
19
18
20
const hasGroupsFeature = entitlements . features . user_role_management . enabled ;
19
21
const groupsQuery = useQuery ( {
20
22
...groupsForUser ( organizationId , me . id ) ,
21
23
enabled : hasGroupsFeature ,
22
24
} ) ;
23
25
26
+ const multiOrgExperimentEnabled = experiments . includes ( "multi-organization" ) ;
27
+ const [ multiOrgUiEnabled , setMultiOrgUiEnabled ] = useState (
28
+ ( ) =>
29
+ multiOrgExperimentEnabled &&
30
+ Boolean ( localStorage . getItem ( "enableMultiOrganizationUi" ) ) ,
31
+ ) ;
32
+
33
+ useEffect ( ( ) => {
34
+ if ( multiOrgUiEnabled ) {
35
+ localStorage . setItem ( "enableMultiOrganizationUi" , "true" ) ;
36
+ } else {
37
+ localStorage . removeItem ( "enableMultiOrganizationUi" ) ;
38
+ }
39
+ } , [ multiOrgUiEnabled ] ) ;
40
+
24
41
return (
25
42
< Stack spacing = { 6 } >
26
43
< Section title = "Account" description = "Update your account info" >
@@ -41,6 +58,23 @@ export const AccountPage: FC = () => {
41
58
error = { groupsQuery . error }
42
59
/>
43
60
) }
61
+
62
+ { multiOrgExperimentEnabled && (
63
+ < Section
64
+ title = "Organizations"
65
+ description = {
66
+ < span > Danger: enabling will break things in the UI.</ span >
67
+ }
68
+ >
69
+ < Stack >
70
+ { multiOrgUiEnabled ? < EnabledBadge /> : < DisabledBadge /> }
71
+ < Button onClick = { ( ) => setMultiOrgUiEnabled ( ( enabled ) => ! enabled ) } >
72
+ { multiOrgUiEnabled ? "Disable" : "Enable" } frontend
73
+ multi-organization support
74
+ </ Button >
75
+ </ Stack >
76
+ </ Section >
77
+ ) }
44
78
</ Stack >
45
79
) ;
46
80
} ;
0 commit comments