| 1 | import { |
| 2 | ArrowRightStartOnRectangleIcon, |
| 3 | Cog6ToothIcon, |
| 4 | UserCircleIcon as UserCircleIconOutline, |
| 5 | } from "@heroicons/react/24/outline"; |
| 6 | import { UserCircleIcon as UserCircleIconSolid } from "@heroicons/react/24/solid"; |
| 7 | import { isOnPremSession } from "core/control-plane/AuthTypes"; |
| 8 | import { useContext } from "react"; |
| 9 | import { ToolTip } from "../../../../components/gui/Tooltip"; |
| 10 | import { |
| 11 | Button, |
| 12 | Listbox, |
| 13 | ListboxButton, |
| 14 | ListboxOption, |
| 15 | ListboxOptions, |
| 16 | } from "../../../../components/ui"; |
| 17 | import { Divider } from "../../../../components/ui/Divider"; |
| 18 | import { useAuth } from "../../../../context/Auth"; |
| 19 | import { IdeMessengerContext } from "../../../../context/IdeMessenger"; |
| 20 | |
| 21 | export function AccountDropdown() { |
| 22 | const { session, logout, login } = useAuth(); |
| 23 | const ideMessenger = useContext(IdeMessengerContext); |
| 24 | |
| 25 | if (isOnPremSession(session)) { |
| 26 | return null; |
| 27 | } |
| 28 | |
| 29 | if (!session) { |
| 30 | return ( |
| 31 | <ToolTip content="Log in" className="text-xs md:!hidden"> |
| 32 | <Button |
| 33 | variant="ghost" |
| 34 | className="text-description flex w-full flex-row items-center gap-2 px-2 py-1.5" |
| 35 | onClick={() => login(false)} |
| 36 | > |
| 37 | <UserCircleIconOutline className="xs:h-4 xs:w-4 h-3 w-3 flex-shrink-0" /> |
| 38 | <span className="text-description hidden text-xs md:block"> |
| 39 | Log in |
| 40 | </span> |
| 41 | </Button> |
| 42 | </ToolTip> |
| 43 | ); |
| 44 | } |
| 45 | |
| 46 | return ( |
| 47 | <div> |
| 48 | <Listbox> |
| 49 | {({ open }) => ( |
| 50 | <> |
| 51 | <ListboxButton |
| 52 | className={`text-description w-full justify-start gap-1 border-none px-2 py-1.5 ${ |
| 53 | open ? "bg-input" : "hover:bg-input bg-inherit" |
| 54 | }`} |
| 55 | > |
| 56 | <UserCircleIconSolid className="xs:h-4 xs:w-4 h-3 w-3 flex-shrink-0" /> |
| 57 | <div className="ml-1 flex min-w-0 flex-1 flex-col items-start overflow-hidden"> |
| 58 | <span className="w-full truncate text-xs font-medium hover:brightness-110"> |
| 59 | {session.account.label} |
| 60 | </span> |
| 61 | <span className="text-description-muted w-full truncate text-xs"> |
| 62 | {session.account.id} |
| 63 | </span> |
| 64 | </div> |
| 65 | </ListboxButton> |
| 66 | <ListboxOptions anchor="right end"> |
| 67 | {/* Account info section for small screens */} |
| 68 | <div className="md:hidden"> |
| 69 | <div className="flex items-center gap-2 px-2 py-1"> |
| 70 | <UserCircleIconSolid className="h-5 w-5 flex-shrink-0" /> |
| 71 | <div className="flex min-w-0 flex-col"> |
| 72 | <span className="truncate text-xs font-medium"> |
| 73 | {session.account.label} |
| 74 | </span> |
| 75 | <span className="text-description-muted truncate text-xs"> |
| 76 | {session.account.id} |
| 77 | </span> |
| 78 | </div> |
| 79 | </div> |
| 80 | <Divider /> |
| 81 | </div> |
| 82 | |
| 83 | <ListboxOption |
| 84 | onClick={() => |
| 85 | ideMessenger.post( |
| 86 | "openUrl", |
| 87 | "https://hub.continue.dev/settings", |
| 88 | ) |
| 89 | } |
| 90 | value="manage-account" |
| 91 | > |
| 92 | <div className="flex items-center gap-2 py-0.5"> |
| 93 | <Cog6ToothIcon className="h-3.5 w-3.5" /> |
| 94 | <span>Manage Account</span> |
| 95 | </div> |
| 96 | </ListboxOption> |
| 97 | |
| 98 | <ListboxOption onClick={logout} value="logout"> |
| 99 | <div className="flex items-center gap-2 py-0.5"> |
| 100 | <ArrowRightStartOnRectangleIcon className="h-3.5 w-3.5" /> |
| 101 | <span>Log out</span> |
| 102 | </div> |
| 103 | </ListboxOption> |
| 104 | </ListboxOptions> |
| 105 | </> |
| 106 | )} |
| 107 | </Listbox> |
| 108 | </div> |
| 109 | ); |
| 110 | } |