main
|
Last change
on this file since 700e2f9 was 700e2f9, checked in by 186079 <matej.milevski@…>, 5 days ago |
|
Init
|
-
Property mode
set to
100644
|
|
File size:
2.0 KB
|
| Line | |
|---|
| 1 | import { useNavigate } from "@solidjs/router";
|
|---|
| 2 | import { useAuth } from "@/context/AuthContext";
|
|---|
| 3 | import type { Component } from "solid-js";
|
|---|
| 4 |
|
|---|
| 5 | const UserMenu: Component = () => {
|
|---|
| 6 | const { user, logout } = useAuth();
|
|---|
| 7 | const navigate = useNavigate();
|
|---|
| 8 |
|
|---|
| 9 | const handleLogout = () => {
|
|---|
| 10 | logout();
|
|---|
| 11 | navigate("/login");
|
|---|
| 12 | };
|
|---|
| 13 |
|
|---|
| 14 | return (
|
|---|
| 15 | <div class="relative group">
|
|---|
| 16 | <div class="flex items-center gap-2 cursor-pointer px-3 py-2 rounded-md hover:bg-gray-100 transition-colors">
|
|---|
| 17 | <span class="text-gray-500 text-sm">Hello, </span>
|
|---|
| 18 | <span class="font-semibold text-gray-900">{user()?.username}</span>
|
|---|
| 19 | <span class="ml-2 text-xs px-2 py-1 rounded-full bg-blue-100 text-blue-800">
|
|---|
| 20 | {user()?.userType}
|
|---|
| 21 | </span>
|
|---|
| 22 | <svg
|
|---|
| 23 | class="w-4 h-4 text-gray-500 ml-1"
|
|---|
| 24 | fill="none"
|
|---|
| 25 | stroke="currentColor"
|
|---|
| 26 | viewBox="0 0 24 24"
|
|---|
| 27 | >
|
|---|
| 28 | <path
|
|---|
| 29 | stroke-linecap="round"
|
|---|
| 30 | stroke-linejoin="round"
|
|---|
| 31 | stroke-width="2"
|
|---|
| 32 | d="M19 9l-7 7-7-7"
|
|---|
| 33 | />
|
|---|
| 34 | </svg>
|
|---|
| 35 | </div>
|
|---|
| 36 |
|
|---|
| 37 | {/* Dropdown menu */}
|
|---|
| 38 | <div class="absolute right-0 mt-2 w-48 bg-white rounded-md shadow-lg border border-gray-200 opacity-0 invisible group-hover:opacity-100 group-hover:visible transition-all duration-200 z-50">
|
|---|
| 39 | <div class="py-1">
|
|---|
| 40 | <button
|
|---|
| 41 | onClick={handleLogout}
|
|---|
| 42 | class="w-full text-left px-4 py-2 text-sm text-gray-700 hover:bg-gray-100 transition-colors flex items-center gap-2 cursor-pointer"
|
|---|
| 43 | >
|
|---|
| 44 | <svg
|
|---|
| 45 | class="w-4 h-4"
|
|---|
| 46 | fill="none"
|
|---|
| 47 | stroke="currentColor"
|
|---|
| 48 | viewBox="0 0 24 24"
|
|---|
| 49 | >
|
|---|
| 50 | <path
|
|---|
| 51 | stroke-linecap="round"
|
|---|
| 52 | stroke-linejoin="round"
|
|---|
| 53 | stroke-width="2"
|
|---|
| 54 | d="M17 16l4-4m0 0l-4-4m4 4H7m6 4v1a3 3 0 01-3 3H6a3 3 0 01-3-3V7a3 3 0 013-3h4a3 3 0 013 3v1"
|
|---|
| 55 | />
|
|---|
| 56 | </svg>
|
|---|
| 57 | Logout
|
|---|
| 58 | </button>
|
|---|
| 59 | </div>
|
|---|
| 60 | </div>
|
|---|
| 61 | </div>
|
|---|
| 62 | );
|
|---|
| 63 | };
|
|---|
| 64 |
|
|---|
| 65 | export default UserMenu;
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.