|
1 | | -import { useState } from "react"; |
| 1 | +import { useState, Fragment } from "react"; |
| 2 | +import { Menu, Transition } from "@headlessui/react"; |
| 3 | +import { |
| 4 | + ChevronDownIcon, |
| 5 | + CreditCardIcon, |
| 6 | + UserCircleIcon, |
| 7 | + ArrowRightOnRectangleIcon, |
| 8 | + Cog6ToothIcon |
| 9 | +} from "@heroicons/react/24/outline"; |
2 | 10 | import useGraffiticodeAuth from "../hooks/use-graffiticode-auth"; |
3 | 11 | import WalletSelectionDialog from "./WalletSelectionDialog"; |
4 | 12 |
|
@@ -35,9 +43,98 @@ export default function SignInComponent({ label = "Sign in", className }: SignIn |
35 | 43 |
|
36 | 44 | if (user) { |
37 | 45 | return ( |
38 | | - <button className={className} disabled={loading} onClick={signOut}> |
39 | | - {`${user.uid.slice(0, 7)}...${user.uid.slice(33)}`} (Sign out) |
40 | | - </button> |
| 46 | + <Menu as="div" className="relative inline-block text-left"> |
| 47 | + <div> |
| 48 | + <Menu.Button className={`inline-flex justify-center items-center w-full ${className}`}> |
| 49 | + {`${user.uid.slice(0, 7)}...${user.uid.slice(33)}`} |
| 50 | + <ChevronDownIcon className="ml-2 -mr-1 h-4 w-4" aria-hidden="true" /> |
| 51 | + </Menu.Button> |
| 52 | + </div> |
| 53 | + |
| 54 | + <Transition |
| 55 | + as={Fragment} |
| 56 | + enter="transition ease-out duration-100" |
| 57 | + enterFrom="transform opacity-0 scale-95" |
| 58 | + enterTo="transform opacity-100 scale-100" |
| 59 | + leave="transition ease-in duration-75" |
| 60 | + leaveFrom="transform opacity-100 scale-100" |
| 61 | + leaveTo="transform opacity-0 scale-95" |
| 62 | + > |
| 63 | + <Menu.Items className="absolute right-0 z-10 mt-2 w-56 origin-top-right rounded-md bg-white shadow-lg ring-1 ring-black ring-opacity-5 focus:outline-none"> |
| 64 | + <div className="px-1 py-1"> |
| 65 | + <div className="px-3 py-2 text-xs text-gray-500 border-b border-gray-200"> |
| 66 | + Account |
| 67 | + </div> |
| 68 | + <Menu.Item> |
| 69 | + {({ active }) => ( |
| 70 | + <a |
| 71 | + href="/profile" |
| 72 | + className={`${ |
| 73 | + active ? 'bg-gray-100 text-gray-900' : 'text-gray-700' |
| 74 | + } group flex items-center px-4 py-2 text-sm mt-1`} |
| 75 | + > |
| 76 | + <UserCircleIcon |
| 77 | + className="mr-3 h-4 w-4 text-gray-400 group-hover:text-gray-500" |
| 78 | + aria-hidden="true" |
| 79 | + /> |
| 80 | + Profile |
| 81 | + </a> |
| 82 | + )} |
| 83 | + </Menu.Item> |
| 84 | + <Menu.Item> |
| 85 | + {({ active }) => ( |
| 86 | + <a |
| 87 | + href="/payments" |
| 88 | + className={`${ |
| 89 | + active ? 'bg-gray-100 text-gray-900' : 'text-gray-700' |
| 90 | + } group flex items-center px-4 py-2 text-sm`} |
| 91 | + > |
| 92 | + <CreditCardIcon |
| 93 | + className="mr-3 h-4 w-4 text-gray-400 group-hover:text-gray-500" |
| 94 | + aria-hidden="true" |
| 95 | + /> |
| 96 | + Payments & Billing |
| 97 | + </a> |
| 98 | + )} |
| 99 | + </Menu.Item> |
| 100 | + <Menu.Item> |
| 101 | + {({ active }) => ( |
| 102 | + <a |
| 103 | + href="/settings" |
| 104 | + className={`${ |
| 105 | + active ? 'bg-gray-100 text-gray-900' : 'text-gray-700' |
| 106 | + } group flex items-center px-4 py-2 text-sm`} |
| 107 | + > |
| 108 | + <Cog6ToothIcon |
| 109 | + className="mr-3 h-4 w-4 text-gray-400 group-hover:text-gray-500" |
| 110 | + aria-hidden="true" |
| 111 | + /> |
| 112 | + Settings |
| 113 | + </a> |
| 114 | + )} |
| 115 | + </Menu.Item> |
| 116 | + <div className="border-t border-gray-200 my-1"></div> |
| 117 | + <Menu.Item> |
| 118 | + {({ active }) => ( |
| 119 | + <button |
| 120 | + onClick={signOut} |
| 121 | + disabled={loading} |
| 122 | + className={`${ |
| 123 | + active ? 'bg-gray-100 text-gray-900' : 'text-gray-700' |
| 124 | + } group flex items-center w-full text-left px-4 py-2 text-sm`} |
| 125 | + > |
| 126 | + <ArrowRightOnRectangleIcon |
| 127 | + className="mr-3 h-4 w-4 text-gray-400 group-hover:text-gray-500" |
| 128 | + aria-hidden="true" |
| 129 | + /> |
| 130 | + Sign out |
| 131 | + </button> |
| 132 | + )} |
| 133 | + </Menu.Item> |
| 134 | + </div> |
| 135 | + </Menu.Items> |
| 136 | + </Transition> |
| 137 | + </Menu> |
41 | 138 | ); |
42 | 139 | } else { |
43 | 140 | return ( |
|
0 commit comments