Elffuss BraidHub

kikocis/continue public

825624809c09 · 2.6 KiBRawPermalink
1import { UserCircleIcon } from "@heroicons/react/24/solid";
2import { isOnPremSession } from "core/control-plane/AuthTypes";
3import { ScopeSelect } from "../../components/AssistantAndOrgListbox/ScopeSelect";
4import {
5 Button,
6 Popover,
7 PopoverButton,
8 PopoverPanel,
9 Transition,
10} from "../../components/ui";
11import { useAuth } from "../../context/Auth";
12import { useAppSelector } from "../../redux/hooks";
13import { selectCurrentOrg } from "../../redux/slices/profilesSlice";
14
15export function AccountButton() {
16 const { session, logout, login, organizations } = useAuth();
17 const selectedOrg = useAppSelector(selectCurrentOrg);
18
19 if (!session) {
20 return (
21 <Button
22 variant="outline"
23 className="mb-1 whitespace-nowrap py-1"
24 onClick={() => login(false)}
25 >
26 Sign in
27 </Button>
28 );
29 }
30
31 // No login button for on-prem deployments
32 if (isOnPremSession(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 <Button
69 variant="ghost"
70 onClick={logout}
71 className="!mx-0 w-full"
72 >
73 Sign out
74 </Button>
75 </div>
76 </PopoverPanel>
77 </Transition>
78 </>
79 )}
80 </Popover>
81 );
82}