Compare commits
2 Commits
9f7e040c67
...
2e80e45eab
| Author | SHA1 | Date | |
|---|---|---|---|
| 2e80e45eab | |||
| e0608eb05b |
@@ -1,56 +0,0 @@
|
|||||||
"use client";
|
|
||||||
|
|
||||||
import { useSidebar } from "@/context/SidebarContext";
|
|
||||||
import AppHeader from "@/layout/AppHeader";
|
|
||||||
import AppSidebar from "@/layout/AppSidebar";
|
|
||||||
import Backdrop from "@/layout/Backdrop";
|
|
||||||
import { apiGetCurrentUser } from "@/service/auth";
|
|
||||||
import { setUserData } from "@/store/features/userSlice";
|
|
||||||
import React, { useEffect } from "react";
|
|
||||||
import { useDispatch } from "react-redux";
|
|
||||||
|
|
||||||
export default function AdminLayout({
|
|
||||||
children,
|
|
||||||
}: {
|
|
||||||
children: React.ReactNode;
|
|
||||||
}) {
|
|
||||||
const { isExpanded, isHovered, isMobileOpen } = useSidebar();
|
|
||||||
const dispatch = useDispatch()
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
const fetchUser = async () => {
|
|
||||||
try {
|
|
||||||
const userData = await apiGetCurrentUser();
|
|
||||||
dispatch(setUserData(userData.data));
|
|
||||||
} catch (err) {
|
|
||||||
console.error("Lỗi:", err);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
fetchUser();
|
|
||||||
}, [])
|
|
||||||
|
|
||||||
|
|
||||||
// Dynamic class for main content margin based on sidebar state
|
|
||||||
const mainContentMargin = isMobileOpen
|
|
||||||
? "ml-0"
|
|
||||||
: isExpanded || isHovered
|
|
||||||
? "lg:ml-[290px]"
|
|
||||||
: "lg:ml-[90px]";
|
|
||||||
|
|
||||||
return (
|
|
||||||
<div className="min-h-screen xl:flex">
|
|
||||||
{/* Sidebar and Backdrop */}
|
|
||||||
<AppSidebar />
|
|
||||||
<Backdrop />
|
|
||||||
{/* Main Content Area */}
|
|
||||||
<div
|
|
||||||
className={`flex-1 transition-all duration-300 ease-in-out ${mainContentMargin}`}
|
|
||||||
>
|
|
||||||
{/* Header */}
|
|
||||||
<AppHeader />
|
|
||||||
{/* Page Content */}
|
|
||||||
<div className="p-4 mx-auto max-w-(--breakpoint-2xl) md:p-6">{children}</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
@@ -1,42 +0,0 @@
|
|||||||
import type { Metadata } from "next";
|
|
||||||
import { EcommerceMetrics } from "@/components/ecommerce/EcommerceMetrics";
|
|
||||||
import React from "react";
|
|
||||||
import MonthlyTarget from "@/components/ecommerce/MonthlyTarget";
|
|
||||||
import MonthlySalesChart from "@/components/ecommerce/MonthlySalesChart";
|
|
||||||
import StatisticsChart from "@/components/ecommerce/StatisticsChart";
|
|
||||||
import RecentOrders from "@/components/ecommerce/RecentOrders";
|
|
||||||
import DemographicCard from "@/components/ecommerce/DemographicCard";
|
|
||||||
|
|
||||||
export const metadata: Metadata = {
|
|
||||||
title:
|
|
||||||
"Admin Dashboard",
|
|
||||||
description: "This is Dashboard Home for History Web",
|
|
||||||
};
|
|
||||||
|
|
||||||
export default function Ecommerce() {
|
|
||||||
return (
|
|
||||||
<div className="grid grid-cols-12 gap-4 md:gap-6">
|
|
||||||
<div className="col-span-12 space-y-6 xl:col-span-7">
|
|
||||||
<EcommerceMetrics />
|
|
||||||
|
|
||||||
<MonthlySalesChart />
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div className="col-span-12 xl:col-span-5">
|
|
||||||
<MonthlyTarget />
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div className="col-span-12">
|
|
||||||
<StatisticsChart />
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div className="col-span-12 xl:col-span-5">
|
|
||||||
<DemographicCard />
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div className="col-span-12 xl:col-span-7">
|
|
||||||
<RecentOrders />
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
9
src/app/page.tsx
Normal file
9
src/app/page.tsx
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
import AdminLayout from "./user/layout";
|
||||||
|
|
||||||
|
export default function Page() {
|
||||||
|
return (
|
||||||
|
<AdminLayout>
|
||||||
|
<div className=''>Page</div>
|
||||||
|
</AdminLayout>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -8,6 +8,7 @@ import { apiGetCurrentUser } from "@/service/auth";
|
|||||||
import { setUserData } from "@/store/features/userSlice";
|
import { setUserData } from "@/store/features/userSlice";
|
||||||
import React, { useEffect } from "react";
|
import React, { useEffect } from "react";
|
||||||
import { useDispatch } from "react-redux";
|
import { useDispatch } from "react-redux";
|
||||||
|
import { usePathname } from "next/navigation";
|
||||||
|
|
||||||
export default function AdminLayout({
|
export default function AdminLayout({
|
||||||
children,
|
children,
|
||||||
@@ -16,6 +17,8 @@ export default function AdminLayout({
|
|||||||
}) {
|
}) {
|
||||||
const { isExpanded, isHovered, isMobileOpen } = useSidebar();
|
const { isExpanded, isHovered, isMobileOpen } = useSidebar();
|
||||||
const dispatch = useDispatch()
|
const dispatch = useDispatch()
|
||||||
|
const pathname = usePathname();
|
||||||
|
const isHomePage = pathname === "/";
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const fetchUser = async () => {
|
const fetchUser = async () => {
|
||||||
@@ -31,17 +34,19 @@ export default function AdminLayout({
|
|||||||
|
|
||||||
|
|
||||||
// Dynamic class for main content margin based on sidebar state
|
// Dynamic class for main content margin based on sidebar state
|
||||||
const mainContentMargin = isMobileOpen
|
const mainContentMargin = isHomePage
|
||||||
? "ml-0"
|
? "ml-0"
|
||||||
: isExpanded || isHovered
|
: isMobileOpen
|
||||||
? "lg:ml-[290px]"
|
? "ml-0"
|
||||||
: "lg:ml-[90px]";
|
: isExpanded || isHovered
|
||||||
|
? "lg:ml-[290px]"
|
||||||
|
: "lg:ml-[90px]";
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="min-h-screen xl:flex">
|
<div className="min-h-screen xl:flex">
|
||||||
{/* Sidebar and Backdrop */}
|
{/* Sidebar and Backdrop */}
|
||||||
<AppSidebar />
|
{!isHomePage && <AppSidebar />}
|
||||||
<Backdrop />
|
{!isHomePage && <Backdrop />}
|
||||||
{/* Main Content Area */}
|
{/* Main Content Area */}
|
||||||
<div
|
<div
|
||||||
className={`flex-1 transition-all duration-300 ease-in-out ${mainContentMargin}`}
|
className={`flex-1 transition-all duration-300 ease-in-out ${mainContentMargin}`}
|
||||||
|
|||||||
@@ -5,12 +5,15 @@ import UserDropdown from "@/components/header/UserDropdown";
|
|||||||
import { useSidebar } from "@/context/SidebarContext";
|
import { useSidebar } from "@/context/SidebarContext";
|
||||||
import Image from "next/image";
|
import Image from "next/image";
|
||||||
import Link from "next/link";
|
import Link from "next/link";
|
||||||
|
import { usePathname } from "next/navigation";
|
||||||
import React, { useState ,useEffect,useRef} from "react";
|
import React, { useState ,useEffect,useRef} from "react";
|
||||||
|
|
||||||
const AppHeader: React.FC = () => {
|
const AppHeader: React.FC = () => {
|
||||||
const [isApplicationMenuOpen, setApplicationMenuOpen] = useState(false);
|
const [isApplicationMenuOpen, setApplicationMenuOpen] = useState(false);
|
||||||
|
|
||||||
const { isMobileOpen, toggleSidebar, toggleMobileSidebar } = useSidebar();
|
const { isMobileOpen, toggleSidebar, toggleMobileSidebar } = useSidebar();
|
||||||
|
const pathname = usePathname();
|
||||||
|
const isHomePage = pathname === "/";
|
||||||
|
|
||||||
const handleToggle = () => {
|
const handleToggle = () => {
|
||||||
if (window.innerWidth >= 1024) {
|
if (window.innerWidth >= 1024) {
|
||||||
@@ -44,44 +47,46 @@ const AppHeader: React.FC = () => {
|
|||||||
<header className="sticky top-0 flex w-full bg-white border-gray-200 z-99 dark:border-gray-800 dark:bg-gray-900 lg:border-b">
|
<header className="sticky top-0 flex w-full bg-white border-gray-200 z-99 dark:border-gray-800 dark:bg-gray-900 lg:border-b">
|
||||||
<div className="flex flex-col items-center justify-between grow lg:flex-row lg:px-6">
|
<div className="flex flex-col items-center justify-between grow lg:flex-row lg:px-6">
|
||||||
<div className="flex items-center justify-between w-full gap-2 px-3 py-3 border-b border-gray-200 dark:border-gray-800 sm:gap-4 lg:justify-normal lg:border-b-0 lg:px-0 lg:py-4">
|
<div className="flex items-center justify-between w-full gap-2 px-3 py-3 border-b border-gray-200 dark:border-gray-800 sm:gap-4 lg:justify-normal lg:border-b-0 lg:px-0 lg:py-4">
|
||||||
<button
|
{!isHomePage && (
|
||||||
className="items-center justify-center w-10 h-10 text-gray-500 border-gray-200 rounded-lg z-99999 dark:border-gray-800 lg:flex dark:text-gray-400 lg:h-11 lg:w-11 lg:border"
|
<button
|
||||||
onClick={handleToggle}
|
className="items-center justify-center w-10 h-10 text-gray-500 border-gray-200 rounded-lg z-99999 dark:border-gray-800 lg:flex dark:text-gray-400 lg:h-11 lg:w-11 lg:border"
|
||||||
aria-label="Toggle Sidebar"
|
onClick={handleToggle}
|
||||||
>
|
aria-label="Toggle Sidebar"
|
||||||
{isMobileOpen ? (
|
>
|
||||||
<svg
|
{isMobileOpen ? (
|
||||||
width="24"
|
<svg
|
||||||
height="24"
|
width="24"
|
||||||
viewBox="0 0 24 24"
|
height="24"
|
||||||
fill="none"
|
viewBox="0 0 24 24"
|
||||||
xmlns="http://www.w3.org/2000/svg"
|
fill="none"
|
||||||
>
|
xmlns="http://www.w3.org/2000/svg"
|
||||||
<path
|
>
|
||||||
fillRule="evenodd"
|
<path
|
||||||
clipRule="evenodd"
|
fillRule="evenodd"
|
||||||
d="M6.21967 7.28131C5.92678 6.98841 5.92678 6.51354 6.21967 6.22065C6.51256 5.92775 6.98744 5.92775 7.28033 6.22065L11.999 10.9393L16.7176 6.22078C17.0105 5.92789 17.4854 5.92788 17.7782 6.22078C18.0711 6.51367 18.0711 6.98855 17.7782 7.28144L13.0597 12L17.7782 16.7186C18.0711 17.0115 18.0711 17.4863 17.7782 17.7792C17.4854 18.0721 17.0105 18.0721 16.7176 17.7792L11.999 13.0607L7.28033 17.7794C6.98744 18.0722 6.51256 18.0722 6.21967 17.7794C5.92678 17.4865 5.92678 17.0116 6.21967 16.7187L10.9384 12L6.21967 7.28131Z"
|
clipRule="evenodd"
|
||||||
fill="currentColor"
|
d="M6.21967 7.28131C5.92678 6.98841 5.92678 6.51354 6.21967 6.22065C6.51256 5.92775 6.98744 5.92775 7.28033 6.22065L11.999 10.9393L16.7176 6.22078C17.0105 5.92789 17.4854 5.92788 17.7782 6.22078C18.0711 6.51367 18.0711 6.98855 17.7782 7.28144L13.0597 12L17.7782 16.7186C18.0711 17.0115 18.0711 17.4863 17.7782 17.7792C17.4854 18.0721 17.0105 18.0721 16.7176 17.7792L11.999 13.0607L7.28033 17.7794C6.98744 18.0722 6.51256 18.0722 6.21967 17.7794C5.92678 17.4865 5.92678 17.0116 6.21967 16.7187L10.9384 12L6.21967 7.28131Z"
|
||||||
/>
|
fill="currentColor"
|
||||||
</svg>
|
/>
|
||||||
) : (
|
</svg>
|
||||||
<svg
|
) : (
|
||||||
width="16"
|
<svg
|
||||||
height="12"
|
width="16"
|
||||||
viewBox="0 0 16 12"
|
height="12"
|
||||||
fill="none"
|
viewBox="0 0 16 12"
|
||||||
xmlns="http://www.w3.org/2000/svg"
|
fill="none"
|
||||||
>
|
xmlns="http://www.w3.org/2000/svg"
|
||||||
<path
|
>
|
||||||
fillRule="evenodd"
|
<path
|
||||||
clipRule="evenodd"
|
fillRule="evenodd"
|
||||||
d="M0.583252 1C0.583252 0.585788 0.919038 0.25 1.33325 0.25H14.6666C15.0808 0.25 15.4166 0.585786 15.4166 1C15.4166 1.41421 15.0808 1.75 14.6666 1.75L1.33325 1.75C0.919038 1.75 0.583252 1.41422 0.583252 1ZM0.583252 11C0.583252 10.5858 0.919038 10.25 1.33325 10.25L14.6666 10.25C15.0808 10.25 15.4166 10.5858 15.4166 11C15.4166 11.4142 15.0808 11.75 14.6666 11.75L1.33325 11.75C0.919038 11.75 0.583252 11.4142 0.583252 11ZM1.33325 5.25C0.919038 5.25 0.583252 5.58579 0.583252 6C0.583252 6.41421 0.919038 6.75 1.33325 6.75L7.99992 6.75C8.41413 6.75 8.74992 6.41421 8.74992 6C8.74992 5.58579 8.41413 5.25 7.99992 5.25L1.33325 5.25Z"
|
clipRule="evenodd"
|
||||||
fill="currentColor"
|
d="M0.583252 1C0.583252 0.585788 0.919038 0.25 1.33325 0.25H14.6666C15.0808 0.25 15.4166 0.585786 15.4166 1C15.4166 1.41421 15.0808 1.75 14.6666 1.75L1.33325 1.75C0.919038 1.75 0.583252 1.41422 0.583252 1ZM0.583252 11C0.583252 10.5858 0.919038 10.25 1.33325 10.25L14.6666 10.25C15.0808 10.25 15.4166 10.5858 15.4166 11C15.4166 11.4142 15.0808 11.75 14.6666 11.75L1.33325 11.75C0.919038 11.75 0.583252 11.4142 0.583252 11ZM1.33325 5.25C0.919038 5.25 0.583252 5.58579 0.583252 6C0.583252 6.41421 0.919038 6.75 1.33325 6.75L7.99992 6.75C8.41413 6.75 8.74992 6.41421 8.74992 6C8.74992 5.58579 8.41413 5.25 7.99992 5.25L1.33325 5.25Z"
|
||||||
/>
|
fill="currentColor"
|
||||||
</svg>
|
/>
|
||||||
)}
|
</svg>
|
||||||
{/* Cross Icon */}
|
)}
|
||||||
</button>
|
{/* Cross Icon */}
|
||||||
|
</button>
|
||||||
|
)}
|
||||||
|
|
||||||
<Link href="/" className="lg:hidden">
|
<Link href="/" className="lg:hidden">
|
||||||
<Image
|
<Image
|
||||||
@@ -178,4 +183,3 @@ const AppHeader: React.FC = () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export default AppHeader;
|
export default AppHeader;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user