Elffuss BraidHub

kikocis/continue public

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