You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

114 lines
6.1 KiB

  1. import { PropsWithChildren, useState } from 'react';
  2. import ApplicationLogo from '@/Components/ApplicationLogo';
  3. import Footer from '@/Components/Footer';
  4. import { Link, usePage } from '@inertiajs/react';
  5. import { User } from '@/types';
  6. import { AlertOctagon, Bell, Bookmark, ChevronDown, Grid, Home, LogOut } from 'react-feather';
  7. import Modal from '@/Components/Modal';
  8. import axios from 'axios';
  9. import ModalButton from '@/Components/ModalButton';
  10. import NavIconLink from '@/Components/NavIconLink';
  11. export default function Authenticated({ user, children }: PropsWithChildren<{ user: User }>) {
  12. const { url } = usePage();
  13. const [isUserOptionsHiglighted, setIsUserOptionsHiglighted] = useState(false);
  14. const [isDashboardHiglighted, setIsDashboardHiglighted] = useState(false);
  15. const [isNotificationsHiglighted, setIsNotificationsHiglighted] = useState(false);
  16. const [isBookmarksHiglighted, setIsBookmarksHiglighted] = useState(false);
  17. const [isLogoutModalOpen, setIsLogoutModalOpen] = useState(false);
  18. const handleCloseLogoutModal = () => {
  19. setIsLogoutModalOpen(false);
  20. axios.post('/logout')
  21. .then(response => {
  22. console.log(response.data);
  23. window.location.href = '/';
  24. })
  25. .catch(error => {
  26. console.error(error);
  27. });
  28. };
  29. return (
  30. <div>
  31. <header className="navbar px-4 bg-primary-background border-b-2 border-secondary-main">
  32. <div id="ProjectTitle" className="navbar-start">
  33. <Link href="/dashboard">
  34. <ApplicationLogo />
  35. </Link>
  36. </div>
  37. <nav className="navbar-end">
  38. <NavIconLink href="/dashboard" active={url === '/dashboard'}
  39. onMouseEnter={() => setIsDashboardHiglighted(true)}
  40. onMouseLeave={() => setIsDashboardHiglighted(false)}
  41. >
  42. <Home className={isDashboardHiglighted || url === '/dashboard' ? "stroke-neutral-10 active" : "stroke-secondary-main"} />
  43. </NavIconLink>
  44. <NavIconLink href="/notifications" active={url === '/notifications'}
  45. onMouseEnter={() => setIsNotificationsHiglighted(true)}
  46. onMouseLeave={() => setIsNotificationsHiglighted(false)}
  47. >
  48. <Bell className={isNotificationsHiglighted || url === '/notifications' ? "stroke-neutral-10 active" : "stroke-secondary-main"} />
  49. </NavIconLink>
  50. <NavIconLink href="/bookmarks" active={url === '/bookmarks'}
  51. onMouseEnter={() => setIsBookmarksHiglighted(true)}
  52. onMouseLeave={() => setIsBookmarksHiglighted(false)}
  53. >
  54. <Bookmark className={isBookmarksHiglighted || url === '/bookmarks' ? "stroke-neutral-10 active" : "stroke-secondary-main"} />
  55. </NavIconLink>
  56. <div className="dropdown" id='UserOptions'>
  57. <div tabIndex={0} role="button"
  58. onMouseEnter={() => setIsUserOptionsHiglighted(true)}
  59. onMouseLeave={() => setIsUserOptionsHiglighted(false)}
  60. className="btn m-0 bg-primary-background border-primary-background shadow-xl text-md hover:bg-secondary-hover hover:text-white active:bg-secondary-pressed active:text-white">
  61. {user.username}
  62. <ChevronDown className={isUserOptionsHiglighted ? "stroke-neutral-10" : "stroke-secondary-main"} />
  63. </div>
  64. <ul tabIndex={0} className="dropdown-content z-[1] menu rounded-btn bg-neutral-10 shadow-md px-0">
  65. <li><Link href={route('profile.edit')} className="hover:bg-secondary-hover hover:text-white active:bg-secondary-pressed active:text-white rounded-none">
  66. Settings
  67. </Link></li>
  68. <li><Link href='/about' className="hover:bg-secondary-hover hover:text-white active:bg-secondary-pressed active:text-white rounded-none">
  69. About CodeHub
  70. </Link></li>
  71. <li><button onClick={() => setIsLogoutModalOpen(true)}
  72. className='outline-none hover:bg-secondary-hover hover:text-white focus:bg-secondary-pressed focus:text-white transition duration-150 ease-in-out'>
  73. Log Out
  74. </button></li>
  75. </ul>
  76. </div>
  77. </nav>
  78. </header>
  79. <main>
  80. {children}
  81. </main>
  82. <footer>
  83. <Footer />
  84. </footer>
  85. <Modal show={isLogoutModalOpen} onClose={() => setIsLogoutModalOpen(false)} maxWidth="lg" styling='warning'>
  86. <div className="p-4 flex flex-col items-center">
  87. <AlertOctagon stroke='#E5C100' size={80} />
  88. <h2 className="text-xl font-bold mt-2">Confirm Logout</h2>
  89. <p className="mt-4">Are you sure you want to logout?</p>
  90. <div className='flex items-center justify-center mt-3'>
  91. <ModalButton onClick={() => setIsLogoutModalOpen(false)} className="mx-1 bg-neutral-40 text-black hover:bg-neutral-60 hover:text-white active:bg-neutral-80 active:text-white">
  92. Cancel
  93. </ModalButton>
  94. <ModalButton onClick={handleCloseLogoutModal} className="mx-1 bg-error-main text-white hover:bg-error-hover active:bg-error-pressed">
  95. Logout
  96. <LogOut stroke='#FFFFFF' />
  97. </ModalButton>
  98. </div>
  99. </div>
  100. </Modal>
  101. </div>
  102. )
  103. }