Elffuss BraidHub

kikocis/continue public

71fd2e7d4456 · 2.5 KiBRawPermalink
1import { UserCircleIcon } from "@heroicons/react/24/solid";
2
3import { isHubSession } from "core/control-plane/AuthTypes";
4import { SecondaryButton } from "../../components";
5import {
6 Popover,
7 PopoverButton,
8 PopoverPanel,
9 Transition,
10} from "../../components/ui";
11import { useAuth } from "../../context/Auth";
12import { selectCurrentOrg } from "../../redux";
13import { useAppSelector } from "../../redux/hooks";
14import { ScopeSelect } from "./ScopeSelect";
15
16export function AccountButton() {
17 const { session, logout, login, organizations } = useAuth();
18 const selectedOrg = useAppSelector(selectCurrentOrg);
19
20 if (!session) {
21 return (
22 <SecondaryButton
23 className="whitespace-nowrap"
24 onClick={() => login(false)}
25 >
26 Sign in
27 </SecondaryButton>
28 );
29 }
30
31 // No login button for on-prem deployments
32 if (!isHubSession(session)) {
33 return null;
34 }
35
36 return (
37 <Popover className="relative">
38 {({ close }) => (
39 <>
40 <PopoverButton className="bg-vsc-background hover:bg-vsc-input-background text-vsc-foreground my-0.5 flex cursor-pointer rounded-md border-none px-2">
41 <div className="flex items-center gap-1.5">
42 <span className="font-medium">
43 {selectedOrg === null ? "Personal" : selectedOrg.name}
44 </span>
45 <UserCircleIcon className="h-6 w-6" />{" "}
46 </div>
47 </PopoverButton>
48
49 <Transition>
50 <PopoverPanel className="bg-vsc-input-background xs:p-4 absolute right-0 mt-1 rounded-md border border-zinc-700 p-2 shadow-lg">
51 <div className="flex flex-col gap-3">
52 <div className="flex flex-col">
53 <span className="font-medium">{session.account.label}</span>
54 <span className="text-lightgray text-sm">
55 {session.account.id}
56 </span>
57 </div>
58
59 {organizations.length > 0 && (
60 <div className="flex flex-col gap-1">
61 <label className="text-vsc-foreground text-xs">
62 Organization
63 </label>
64 <ScopeSelect onSelect={close} />
65 </div>
66 )}
67
68 <SecondaryButton onClick={logout} className="!mx-0 w-full">
69 Sign out
70 </SecondaryButton>
71 </div>
72 </PopoverPanel>
73 </Transition>
74 </>
75 )}
76 </Popover>
77 );
78}