Skip to content

Commit

Permalink
Merge pull request #8 from DeexithParand2k2/navbar-bug-fix
Browse files Browse the repository at this point in the history
Toggle buttons when clicked in Left Sidebar #2 fixed
  • Loading branch information
anand-harsh authored Oct 22, 2023
2 parents c25ff42 + 20900c3 commit ac787f9
Showing 1 changed file with 40 additions and 42 deletions.
82 changes: 40 additions & 42 deletions src/components/Layout/Header/Header.jsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import React from 'react';
import { ColorModeSwitcher } from '../../../ColorModeSwitcher';
import { RiMenu5Fill, RiLogoutBoxLine, RiDashboardFill } from 'react-icons/ri';
import {
Drawer,
DrawerHeader,
VStack,
HStack,
useDisclosure,
Expand All @@ -14,51 +12,61 @@ import {
} from '@chakra-ui/react';
import { Link } from 'react-router-dom';

// other file imports
import './header.css';
import { ColorModeSwitcher } from '../../../ColorModeSwitcher';

/**
* Reusable Component for LinkButton in the sidebar
*
* @param {string} url (default value = "/") - The url link that renders corresponding component
* @param {string} title (default value = "Home") - Text to display on LinkButton
* @param {function} closingHandler - Handler function to close sidebar on click
*/
const LinkButton = ({ url = '/', title = 'Home', closingHandler }) => (
<Link to={url} onClick={closingHandler}>
<Button variant={'ghost'}>{title}</Button>
</Link>
);


/**
* Header with Drawer and DarkMode Component
*
* @returns {JSX.Element} Renders the header component
*/
const Header = () => {
const { isOpen, onOpen, onClose } = useDisclosure();
const isAuthenticated = true;
const isAuthenticated = true; // Change this based on user authentication status
const user = {
role: 'admin',
};

const logoutHandler = () => {
console.log('logout');
onClose();
role: 'admin', // Change this based on the user's role
};

return (
<>
{/* Color mode switcher */}
<ColorModeSwitcher className="switch" />

{/* Button to open the sidebar */}
<Button className="option" onClick={onOpen} colorScheme={'yellow'}>
<RiMenu5Fill />
</Button>

{/* Sidebar (Drawer) */}
<Drawer placement="left" isOpen={isOpen} onClose={onClose}>
<DrawerOverlay />
<DrawerContent>
{/* <DrawerHeader
className="leftSlide"
height={'3rem'}
borderBottomWidth={'1px'}
>
COURSE BUNDLER
</DrawerHeader> */}
<DrawerBody>
<VStack spacing={'4'} alignItems="flex-start">
<LinkButton url="/" title="Home" onClose={onClose} />
<LinkButton
url="/courses"
title="Browse All Courses"
onClose={onClose}
/>
<LinkButton
url="/request"
title="Request A Course"
onClick={onClose}
/>
<LinkButton url="/contact" title="Contact" onClose={onClose} />
<LinkButton url="/about" title="About" onClose={onClose} />

{/* LinkButtons in the sidebar */}
<LinkButton url="/" title="Home" closingHandler={onClose} />
<LinkButton url="/courses" title="Browse All Courses" closingHandler={onClose} />
<LinkButton url="/request" title="Request A Course" closingHandler={onClose} />
<LinkButton url="/contact" title="Contact" closingHandler={onClose} />
<LinkButton url="/about" title="About" closingHandler={onClose} />

{/* Profile, Logout, and Dashboard Button in sidebar */}
<HStack
justifyContent={'space-evenly'}
position="absolute"
Expand All @@ -73,18 +81,14 @@ const Header = () => {
<Button colorScheme={'yellow'}>Profile</Button>
</Link>
<p>OR</p>

<Button colorScheme={'yellow'} onClick={logoutHandler}>
{' '}
<RiLogoutBoxLine />
Logout
<Button colorScheme={'yellow'} onClick={onClose}>
<RiLogoutBoxLine /> Logout
</Button>
</HStack>
{user && user.role === 'admin' && (
<Link onClick={onClose} to="/admin/dashboard">
<Button>
<RiDashboardFill />
Dashboard
<RiDashboardFill /> Dashboard
</Button>
</Link>
)}
Expand All @@ -111,9 +115,3 @@ const Header = () => {
};

export default Header;

const LinkButton = ({ url = '/', title = 'Home' }) => (
<Link to={url}>
<Button variant={'ghost'}>{title}</Button>
</Link>
);

0 comments on commit ac787f9

Please sign in to comment.