Skip to content

Commit

Permalink
Merge pull request #366 from dhruv8433/responsive-dashboard
Browse files Browse the repository at this point in the history
make admin dashboard responsive
  • Loading branch information
pooranjoyb authored Jul 28, 2024
2 parents bb2b6a2 + 11ef613 commit 7ccbee1
Show file tree
Hide file tree
Showing 5 changed files with 210 additions and 18 deletions.
12 changes: 6 additions & 6 deletions src/admin/AdminLayout/AdminLayout.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import React from "react";
import { Outlet } from "react-router-dom";
import Sidebar from "./Sidebar";
import '../admin.css'
import AdminNavbar from "./AdminNavbar";

const AdminLayout: React.FC = () => {
return (
<>
<div className="relative z-10">
<AdminNavbar />
</div>
<div className="flex">
<Sidebar />
<div className="p-8 flex flex-col w-full">
<span className="text-2xl font-bold">
Welcome to SuperAdmin Portal!
</span>
<div className="dashboard p-8 flex flex-col w-full lg::absolute">
<Outlet />
</div>
</div>
Expand Down
196 changes: 196 additions & 0 deletions src/admin/AdminLayout/AdminNavbar.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,196 @@
import { useState } from "react";
import { Link } from "react-router-dom";
import { useDispatch, useSelector } from "react-redux";
import { Slide, toast } from "react-toastify";
import { adminLoggedOut } from "../../utils/features/Auth/authSlice";
import { RootState } from "../../utils/features/store";
import { motion, useMotionValueEvent, useScroll } from "framer-motion";


function AdminNavbar() {
const userName = useSelector((state: RootState) => state.auth.user?.username);
const dispatch = useDispatch();
const [showMenu, setShowMenu] = useState(false);
const [showHamburgerMenu, setShowHamburgerMenu] = useState(false);

const toastNotification = (message: string) => {
toast(message, {
position: "top-right",
autoClose: 5000,
closeOnClick: true,
pauseOnHover: false,
transition: Slide,
});
};

const handleToggleMenu = () => {
setShowMenu((prev) => !prev);
};

const handleCloseMenu = () => {
setShowMenu(false);
};

const handleToggleHamburgerMenu = () => {
setShowHamburgerMenu((prev) => !prev);
};


function logoutAdmin() {
dispatch(adminLoggedOut());
}

const { scrollY } = useScroll();
const [hidden, setHidden] = useState(false);

useMotionValueEvent(scrollY, "change", (latest) => {
const previous = scrollY.getPrevious();
if (previous && latest > previous && latest > 80) {
setHidden(true);
} else {
setHidden(false);
}
});

return (
<>
<div className="navbar flex justify-between bg-base-100 p-4">
<div className="flex md:ml-16 ml-2">
<Link to="/admin">
<img
src="/logo.png"
alt="Admin Logo"
className="md:w-36 w-20 duration-100"
/>
</Link>
</div>

<div className="hidden lg:flex justify-center z-[100]">
<motion.div
variants={{
visible: { y: 0 },
Hidden: { y: "-200%" },
}}
animate={hidden ? "Hidden" : "visible"}
transition={{ duration: 0.3, ease: "easeInOut" }}
className="navbar rounded-3xl fixed top-4 w-auto flex justify-center backdrop-filter backdrop-blur-md shadow-2xl max-w-screen-xl"
>
<ul className="flex justify-between px-12">
<a href="/admin">
<li className="hover:scale-105 duration-75 text-sm hover:font-semibold px-4 rounded-full">
Dashboard
</li>
</a>
<a href="/admin/order">
<li className="hover:scale-105 duration-75 text-sm hover:font-semibold px-4 rounded-full">
Orders
</li>
</a>
<a href="/admin/transaction">
<li className="hover:scale-105 duration-75 text-sm hover:font-semibold px-4 rounded-full">
Transactions
</li>
</a>
<a href="/admin/add-product">
<li className="hover:scale-105 duration-75 text-sm hover:font-semibold px-4 rounded-full">
Add Prdocut
</li>
</a>
</ul>
</motion.div>
</div>

<div className="flex-none gap-6 md:mr-16 mr-2">
<div className="dropdown dropdown-end">
<div
tabIndex={0}
role="button"
className="btn btn-ghost btn-circle avatar"
onClick={handleToggleMenu}
>
<div className="w-10 rounded-full">
<img src={"/images/winter2.jpg"} />
</div>
</div>
{showMenu && (
<ul
tabIndex={0}
className="menu menu-sm dropdown-content mt-3 z-[1] p-2 bg-base-100 rounded-box w-52 shadow-2xl"
>
<li onClick={handleCloseMenu}>
<Link to={"/admin"} className="justify-between">
{`${userName}` || <p>Profile</p>}
</Link>
</li>
<li onClick={() => {
logoutAdmin();
handleCloseMenu();
toastNotification("Logged out successfully!");
}}>
<h1>{<p>Logout</p>}</h1>
</li>
</ul>
)}
</div>
<div className="lg:hidden">
<button
className="btn btn-ghost btn-circle"
onClick={handleToggleHamburgerMenu}
>
<svg
xmlns="http://www.w3.org/2000/svg"
className="h-5 w-5"
fill="none"
viewBox="0 0 24 24"
stroke="currentColor"
>
<path
strokeLinecap="round"
strokeLinejoin="round"
strokeWidth="2"
d="M4 6h16M4 12h16m-7 6h7"
/>
</svg>
</button>
</div>
</div>
</div>
{showHamburgerMenu && (
<div className="lg:hidden bg-base-100 p-4 shadow-2xl absolute top-16 right-0 w-full">
<ul className="menu menu-compact">
<a href="/admin">
<li className="hover:scale-105 duration-75 text-sm hover:font-semibold px-4 my-2 rounded-full">
Dashboard
</li>
</a>
<a href="/admin/order">
<li className="hover:scale-105 duration-75 text-sm hover:font-semibold px-4 my-2 rounded-full">
Orders
</li>
</a>
<a href="/admin/transaction">
<li className="hover:scale-105 duration-75 text-sm hover:font-semibold px-4 my-2 rounded-full">
Transactions
</li>
</a>
<a href="/admin/add-product">
<li className="hover:scale-105 duration-75 text-sm hover:font-semibold px-4 my-2 rounded-full">
Add Prdocut
</li>
</a>
<li className="hover:scale-105 duration-75 text-sm hover:font-semibold px-4 rounded-full hover:cursor-pointer" onClick={() => {
logoutAdmin();
setShowHamburgerMenu(false);
toastNotification("Logged out successfully!");
}}>

Logout
</li>
</ul>
</div>
)}
</>
);
}

export default AdminNavbar;
11 changes: 1 addition & 10 deletions src/admin/AdminLayout/Sidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,12 @@ function Sidebar() {
Open drawer
</label>
</div>
<div className="drawer-side bg-base-200">
<div className="drawer-side border-r">
<label
htmlFor="my-drawer"
aria-label="close sidebar"
className="drawer-overlay"
></label>
<div className="flex md:ml-16 ml-2">
<Link to="/admin">
<img
src="./logo.png"
alt="PopShop Logo"
className="md:w-36 w-20 duration-100 mt-4 -ml-4"
/>
</Link>
</div>
<ul className="menu bg-white text-lg w-80 p-8">
<li className="pt-1 pb-1">
<Link to='/admin'>
Expand Down
4 changes: 2 additions & 2 deletions src/admin/Dashboard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ function Dashboard() {
</div>
</div>
<div className="grid grid-cols-1 sm:grid-cols-8 gap-4 mt-4">
<div className="col-span-2 sm:col-span-3 bg-white border border-gray-300 p-4 rounded-lg">
<div className="sm:col-span-3 bg-white border border-gray-300 p-4 rounded-lg">
<h2 className="text-xl font-bold mb-8">Today Orders</h2>
<p className="text-sm mb-2">{currentDate}</p>
<p className="text-3xl font-bold mb-4">$ 450K</p>
Expand Down Expand Up @@ -374,7 +374,7 @@ function Dashboard() {
Online Users
</h2>
</div>
<div className="flex-grow flex flex-col">
<div className="flex-grow flex flex-col overflow-hidden">
<div
className="flex-grow origin-bottom pr-4"
style={{ height: "200px" }}
Expand Down
5 changes: 5 additions & 0 deletions src/admin/admin.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
@media screen and (max-width: 768px) {
.dashboard{
position: absolute;
}
}

0 comments on commit 7ccbee1

Please sign in to comment.