|
1 | | -import { Link } from '@inertiajs/react' |
| 1 | +import { Link, usePage } from '@inertiajs/react' |
| 2 | +import { Menu, MenuButton, MenuItem, MenuItems, Transition } from '@headlessui/react' |
| 3 | +import { Fragment } from 'react' |
| 4 | + |
| 5 | +interface User { |
| 6 | + name: string |
| 7 | + email: string |
| 8 | + username: string |
| 9 | + avatar: string | null |
| 10 | +} |
| 11 | + |
| 12 | +interface PageProps { |
| 13 | + auth: { |
| 14 | + user: User | null |
| 15 | + } |
| 16 | + [key: string]: any |
| 17 | +} |
2 | 18 |
|
3 | 19 | export default function Navbar() { |
| 20 | + const { auth } = usePage<PageProps>().props |
4 | 21 | return ( |
5 | 22 | <nav className="bg-white border-b border-gray-100"> |
6 | 23 | <div className="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8"> |
@@ -38,17 +55,92 @@ export default function Navbar() { |
38 | 55 |
|
39 | 56 | {/* Right Side */} |
40 | 57 | <div className="hidden sm:flex sm:items-center sm:ml-6"> |
41 | | - <div className="flex items-center space-x-4"> |
42 | | - <Link href="/login" className="text-sm text-gray-500 hover:text-gray-900"> |
43 | | - Se connecter |
44 | | - </Link> |
45 | | - <Link |
46 | | - href="/register" |
47 | | - className="inline-flex items-center px-4 py-2 border border-transparent text-sm font-medium rounded-md text-white bg-indigo-600 hover:bg-indigo-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-indigo-500" |
48 | | - > |
49 | | - Créer un compte |
50 | | - </Link> |
51 | | - </div> |
| 58 | + {auth && auth.user && auth.user.username ? ( |
| 59 | + <Menu as="div" className="relative ml-3"> |
| 60 | + <MenuButton className="flex items-center space-x-3 text-sm focus:outline-none"> |
| 61 | + <img |
| 62 | + className="h-8 w-8 rounded-full" |
| 63 | + src={auth.user.avatar || `https://ui-avatars.com/api/?name=${auth.user.name}`} |
| 64 | + alt={auth.user.name} |
| 65 | + /> |
| 66 | + <span className="text-gray-700">{auth.user.name}</span> |
| 67 | + </MenuButton> |
| 68 | + |
| 69 | + <Transition |
| 70 | + as={Fragment} |
| 71 | + enter="transition ease-out duration-100" |
| 72 | + enterFrom="transform opacity-0 scale-95" |
| 73 | + enterTo="transform opacity-100 scale-100" |
| 74 | + leave="transition ease-in duration-75" |
| 75 | + leaveFrom="transform opacity-100 scale-100" |
| 76 | + leaveTo="transform opacity-0 scale-95" |
| 77 | + > |
| 78 | + <MenuItems className="absolute right-0 mt-2 w-48 origin-top-right rounded-md bg-white py-1 shadow-lg ring-1 ring-black ring-opacity-5 focus:outline-none"> |
| 79 | + {/* Tableau de bord */} |
| 80 | + <MenuItem> |
| 81 | + {({ focus }) => ( |
| 82 | + <Link |
| 83 | + href="/dashboard" |
| 84 | + className={`${focus ? 'bg-gray-100' : ''} block px-4 py-2 text-sm text-gray-700`} |
| 85 | + > |
| 86 | + Dashboard |
| 87 | + </Link> |
| 88 | + )} |
| 89 | + </MenuItem> |
| 90 | + <MenuItem> |
| 91 | + {({ focus }) => ( |
| 92 | + <Link |
| 93 | + href={`/@${auth.user?.username}`} |
| 94 | + className={`${ |
| 95 | + focus ? 'bg-gray-100' : '' |
| 96 | + } block px-4 py-2 text-sm text-gray-700`} |
| 97 | + > |
| 98 | + Profile |
| 99 | + </Link> |
| 100 | + )} |
| 101 | + </MenuItem> |
| 102 | + <MenuItem> |
| 103 | + {({ focus }) => ( |
| 104 | + <Link |
| 105 | + href="/settings" |
| 106 | + className={`${ |
| 107 | + focus ? 'bg-gray-100' : '' |
| 108 | + } block px-4 py-2 text-sm text-gray-700`} |
| 109 | + > |
| 110 | + Settings |
| 111 | + </Link> |
| 112 | + )} |
| 113 | + </MenuItem> |
| 114 | + <MenuItem> |
| 115 | + {({ focus }) => ( |
| 116 | + <Link |
| 117 | + href="/logout" |
| 118 | + method="post" |
| 119 | + as="button" |
| 120 | + className={`${ |
| 121 | + focus ? 'bg-gray-100' : '' |
| 122 | + } block w-full px-4 py-2 text-left text-sm text-gray-700`} |
| 123 | + > |
| 124 | + Logout |
| 125 | + </Link> |
| 126 | + )} |
| 127 | + </MenuItem> |
| 128 | + </MenuItems> |
| 129 | + </Transition> |
| 130 | + </Menu> |
| 131 | + ) : ( |
| 132 | + <div className="flex items-center space-x-4"> |
| 133 | + <Link href="/login" className="text-sm text-gray-500 hover:text-gray-900"> |
| 134 | + Se connecter |
| 135 | + </Link> |
| 136 | + <Link |
| 137 | + href="/register" |
| 138 | + className="inline-flex items-center px-4 py-2 border border-transparent text-sm font-medium rounded-md text-white bg-indigo-600 hover:bg-indigo-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-indigo-500" |
| 139 | + > |
| 140 | + Créer un compte |
| 141 | + </Link> |
| 142 | + </div> |
| 143 | + )} |
52 | 144 | </div> |
53 | 145 | </div> |
54 | 146 | </div> |
|
0 commit comments