Files
CMS-Client/components/_App/Layout.js
T
2023-10-21 03:06:58 -07:00

79 lines
2.1 KiB
JavaScript

import React, { useEffect, useState } from "react";
import Head from "next/head";
import { useRouter } from "next/router";
import LeftSidebar from "@/components/_App/LeftSidebar";
import TopNavbar from "@/components/_App/TopNavbar";
import Footer from "@/components/_App/Footer";
import ScrollToTop from "./ScrollToTop";
import ControlPanelModal from "./ControlPanelModal";
import AuthRoute from "middlewares/AuthRoute";
const Layout = ({ children }) => {
const router = useRouter();
const [active, setActive] = useState(false);
const [isAuthenticationPage, setIsAuthenticationPage] = useState(false);
const toggleActive = () => {
setActive(!active);
};
useEffect(() => {
const authenticationPages = [
// "/",
"/auth",
"/auth/login",
"/auth/sign-up",
"/auth/forgot-password",
"/auth/lock-screen",
"/auth/confirm-mail",
"/auth/logout",
];
setIsAuthenticationPage(authenticationPages.includes(router.pathname));
}, [router.pathname]);
// Debugging: Log the value of isAuthenticationPage
console.log("isAuthenticationPage:", isAuthenticationPage, router.pathname);
const title = isAuthenticationPage ? "CMC - auth" : "CMC - dashboard";
const mainWrapper = {
paddingLeft: typeof window !== "undefined" && isAuthenticationPage && "0"
}
return (
<>
<Head>
<title>{title}</title>
<meta name="viewport" content="initial-scale=1.0, width=device-width" />
</Head>
<div
className={`main-wrapper-content ${active ? "active" : ""}`}
style={mainWrapper}
>
{!isAuthenticationPage && (
<>
<TopNavbar toggleActive={toggleActive} />
<LeftSidebar toggleActive={toggleActive} />
</>
)}
<div
className={`main-content ${isAuthenticationPage ? "authBox" : ""}`}
>
{children}
</div>
{!isAuthenticationPage && <Footer />}
</div>
<ScrollToTop />
{!isAuthenticationPage && <ControlPanelModal />}
</>
);
};
export default Layout;