Skip to content

Commit

Permalink
fix(header): handle header for unauthenticated user
Browse files Browse the repository at this point in the history
  • Loading branch information
iqbalpa committed Jul 15, 2024
1 parent c815ff1 commit 0788a4d
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 14 deletions.
54 changes: 41 additions & 13 deletions src/components/dropdown/dropdown.tsx
Original file line number Diff line number Diff line change
@@ -1,25 +1,53 @@
import React from 'react';
import Link from 'next/link';
import { useSelector } from 'react-redux';
import { RootState } from '@/store/store';

interface IDropdown {
isScrolled: boolean;
handleLogout: () => void;
}

const Dropdown: React.FC<IDropdown> = ({ isScrolled, handleLogout }) => {
const user = useSelector((state: RootState) => state.user.user);

const Dropdown: React.FC<{ isScrolled: boolean }> = ({ isScrolled }) => {
return (
<div
className={`flex w-full flex-col transition-all duration-500 ${
isScrolled ? 'bg-opacity-100' : 'bg-opacity-10'
} bg-slate-800 text-center text-white`}
>
<Link
href="/watchlist"
className="py-2 duration-150 hover:scale-105 hover:bg-slate-900 hover:bg-opacity-50 hover:font-semibold"
>
Watchlist
</Link>
<Link
href="signin"
className="py-2 duration-150 hover:scale-105 hover:bg-slate-900 hover:bg-opacity-50 hover:font-semibold"
>
Login
</Link>
{user ? (
<>
<Link
href="/watchlist"
className="py-2 duration-150 hover:scale-105 hover:bg-slate-900 hover:bg-opacity-50 hover:font-semibold"
>
Watchlist
</Link>
<button
onClick={handleLogout}
className="py-2 duration-150 hover:scale-105 hover:bg-slate-900 hover:bg-opacity-50 hover:font-semibold"
>
Logout
</button>
</>
) : (
<>
<Link
href="/signin"
className="py-2 duration-150 hover:scale-105 hover:bg-slate-900 hover:bg-opacity-50 hover:font-semibold"
>
Watchlist
</Link>
<Link
href="/signin"
className="py-2 duration-150 hover:scale-105 hover:bg-slate-900 hover:bg-opacity-50 hover:font-semibold"
>
Login
</Link>
</>
)}
</div>
);
};
Expand Down
4 changes: 3 additions & 1 deletion src/components/header/header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,9 @@ const Header: React.FC = () => {
)}
</div>
</div>
{isOpen && <Dropdown isScrolled={isScrolled} />}
{isOpen && (
<Dropdown isScrolled={isScrolled} handleLogout={handleLogout} />
)}
</header>
);
};
Expand Down

0 comments on commit 0788a4d

Please sign in to comment.