From acb436e0ebfe094e51d691b2adbe8649e991e31f Mon Sep 17 00:00:00 2001 From: tomasz-io Date: Thu, 20 Mar 2025 15:57:50 -0700 Subject: [PATCH] improv: simplify --- gui/src/pages/config/AccountManagement.tsx | 160 +++++++++++++++++++++ 1 file changed, 160 insertions(+) create mode 100644 gui/src/pages/config/AccountManagement.tsx diff --git a/gui/src/pages/config/AccountManagement.tsx b/gui/src/pages/config/AccountManagement.tsx new file mode 100644 index 000000000..95214278b --- /dev/null +++ b/gui/src/pages/config/AccountManagement.tsx @@ -0,0 +1,160 @@ +import { Listbox, Transition } from "@headlessui/react"; +import { + ArrowTopRightOnSquareIcon, + ChevronUpDownIcon, + PlusCircleIcon, +} from "@heroicons/react/24/outline"; +import { Fragment, useContext, useEffect, useState } from "react"; +import AssistantIcon from "../../components/modelSelection/platform/AssistantIcon"; +import { useAuth } from "../../context/Auth"; +import { IdeMessengerContext } from "../../context/IdeMessenger"; +import { useNavigationListener } from "../../hooks/useNavigationListener"; +import { useAppDispatch } from "../../redux/hooks"; +import { selectProfileThunk } from "../../redux/thunks/profileAndOrg"; +import { ScopeSelect } from "./ScopeSelect"; + +export function AccountManagement() { + useNavigationListener(); + const dispatch = useAppDispatch(); + const ideMessenger = useContext(IdeMessengerContext); + + const { session, login, profiles, selectedProfile, selectedOrganization } = + useAuth(); + + const changeProfileId = (id: string) => { + dispatch(selectProfileThunk(id)); + }; + + const [hubEnabled, setHubEnabled] = useState(false); + + useEffect(() => { + ideMessenger.ide.getIdeSettings().then(({ continueTestEnvironment }) => { + setHubEnabled(continueTestEnvironment === "production"); + }); + }, [ideMessenger]); + + function handleOpenConfig() { + if (!selectedProfile) { + return; + } + ideMessenger.post("config/openProfile", { + profileId: selectedProfile.id, + }); + } + + return ( +
+
+

Configuration

+ {hubEnabled ? ( + // Hub: show org selector + session && ( +
+ {`Organization`} + +
+ ) + ) : ( + // Continue for teams: show org text +
You are using Continue for Teams
+ )} + + {profiles ? ( + <> +
+
+ {`${hubEnabled ? "Assistant" : "Profile"}`} +
+ + {({ open }) => ( +
+ +
+ {selectedProfile && ( + + )} + + {selectedProfile?.title ?? "No Assistant Selected"} + +
+
+
+
+ + + + {profiles.map((option, idx) => ( + + + + {option.title} + + + ))} + {hubEnabled && ( + { + if (session) { + ideMessenger.post("controlPlane/openUrl", { + path: "new", + orgSlug: selectedOrganization?.slug, + }); + } else { + login(false); + } + }} + > + + + Create new Assistant + + + )} + + + + {selectedProfile && ( +
+ + + {hubEnabled + ? "Open Assistant configuration" + : "View Workspace"} + +
+ )} +
+ )} +
+
+ + ) : ( +
Loading...
+ )} +
+
+ ); +}