Skip to content

chore: add setting to enable multi-organization ui #13266

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 13, 2024
Merged
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
38 changes: 36 additions & 2 deletions site/src/pages/UserSettingsPage/AccountPage/AccountPage.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import type { FC } from "react";
import Button from "@mui/material/Button";
import { type FC, useEffect, useState } from "react";
import { useQuery } from "react-query";
import { groupsForUser } from "api/queries/groups";
import { DisabledBadge, EnabledBadge } from "components/Badges/Badges";
import { Stack } from "components/Stack/Stack";
import { useAuthContext } from "contexts/auth/AuthProvider";
import { useAuthenticated } from "contexts/auth/RequireAuth";
Expand All @@ -13,14 +15,29 @@ export const AccountPage: FC = () => {
const { user: me, permissions, organizationId } = useAuthenticated();
const { updateProfile, updateProfileError, isUpdatingProfile } =
useAuthContext();
const { entitlements } = useDashboard();
const { entitlements, experiments } = useDashboard();

const hasGroupsFeature = entitlements.features.user_role_management.enabled;
const groupsQuery = useQuery({
...groupsForUser(organizationId, me.id),
enabled: hasGroupsFeature,
});

const multiOrgExperimentEnabled = experiments.includes("multi-organization");
const [multiOrgUiEnabled, setMultiOrgUiEnabled] = useState(
() =>
multiOrgExperimentEnabled &&
Boolean(localStorage.getItem("enableMultiOrganizationUi")),
);

useEffect(() => {
if (multiOrgUiEnabled) {
localStorage.setItem("enableMultiOrganizationUi", "true");
} else {
localStorage.removeItem("enableMultiOrganizationUi");
}
}, [multiOrgUiEnabled]);

return (
<Stack spacing={6}>
<Section title="Account" description="Update your account info">
Expand All @@ -41,6 +58,23 @@ export const AccountPage: FC = () => {
error={groupsQuery.error}
/>
)}

{multiOrgExperimentEnabled && (
<Section
title="Organizations"
description={
<span>Danger: enabling will break things in the UI.</span>
}
>
<Stack>
{multiOrgUiEnabled ? <EnabledBadge /> : <DisabledBadge />}
<Button onClick={() => setMultiOrgUiEnabled((enabled) => !enabled)}>
{multiOrgUiEnabled ? "Disable" : "Enable"} frontend
multi-organization support
</Button>
</Stack>
</Section>
)}
</Stack>
);
};
Expand Down
Loading