Skip to content

Commit 2b29559

Browse files
authored
chore: add setting to enable multi-organization ui (coder#13266)
1 parent 9ced001 commit 2b29559

File tree

1 file changed

+36
-2
lines changed

1 file changed

+36
-2
lines changed

site/src/pages/UserSettingsPage/AccountPage/AccountPage.tsx

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1-
import type { FC } from "react";
1+
import Button from "@mui/material/Button";
2+
import { type FC, useEffect, useState } from "react";
23
import { useQuery } from "react-query";
34
import { groupsForUser } from "api/queries/groups";
5+
import { DisabledBadge, EnabledBadge } from "components/Badges/Badges";
46
import { Stack } from "components/Stack/Stack";
57
import { useAuthContext } from "contexts/auth/AuthProvider";
68
import { useAuthenticated } from "contexts/auth/RequireAuth";
@@ -13,14 +15,29 @@ export const AccountPage: FC = () => {
1315
const { user: me, permissions, organizationId } = useAuthenticated();
1416
const { updateProfile, updateProfileError, isUpdatingProfile } =
1517
useAuthContext();
16-
const { entitlements } = useDashboard();
18+
const { entitlements, experiments } = useDashboard();
1719

1820
const hasGroupsFeature = entitlements.features.user_role_management.enabled;
1921
const groupsQuery = useQuery({
2022
...groupsForUser(organizationId, me.id),
2123
enabled: hasGroupsFeature,
2224
});
2325

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+
2441
return (
2542
<Stack spacing={6}>
2643
<Section title="Account" description="Update your account info">
@@ -41,6 +58,23 @@ export const AccountPage: FC = () => {
4158
error={groupsQuery.error}
4259
/>
4360
)}
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+
)}
4478
</Stack>
4579
);
4680
};

0 commit comments

Comments
 (0)