import cn from 'clsx'; import s from './Layout.module.css'; import dynamic from 'next/dynamic'; import { useRouter } from 'next/router'; import { CommerceProvider } from '@framework'; import LoginView from '@components/auth/LoginView'; import { useUI } from '@components/ui/context'; import { Navbar, Footer } from '@components/common'; import ShippingView from '@components/checkout/ShippingView'; import CartSidebarView from '@components/cart/CartSidebarView'; import { useAcceptCookies } from '@lib/hooks/useAcceptCookies'; import { Sidebar, Button, LoadingDots } from '@components/ui'; import PaymentMethodView from '@components/checkout/PaymentMethodView'; import CheckoutSidebarView from '@components/checkout/CheckoutSidebarView'; import { CheckoutProvider } from '@components/checkout/context'; import { MenuSidebarView } from '@components/common/UserNav'; import type { Page } from '@commerce/types/page'; import type { Category } from '@commerce/types/site'; import type { Link as LinkProps } from '../UserNav/MenuSidebarView'; const Loading = () => (
); const dynamicProps = { loading: Loading, }; const SignUpView = dynamic(() => import('@components/auth/SignUpView'), { ...dynamicProps, }); const ForgotPassword = dynamic( () => import('@components/auth/ForgotPassword'), { ...dynamicProps, } ); const FeatureBar = dynamic(() => import('@components/common/FeatureBar'), { ...dynamicProps, }); const Modal = dynamic(() => import('@components/ui/Modal'), { ...dynamicProps, ssr: false, }); interface Props { pageProps: { pages?: Page[]; categories: Category[]; }; } const ModalView: React.FC<{ modalView: string; closeModal(): any }> = ({ modalView, closeModal, }) => { return ( {modalView === 'LOGIN_VIEW' && } {modalView === 'SIGNUP_VIEW' && } {modalView === 'FORGOT_VIEW' && } ); }; const ModalUI: React.FC = () => { const { displayModal, closeModal, modalView } = useUI(); return displayModal ? ( ) : null; }; const SidebarView: React.FC<{ sidebarView: string; closeSidebar(): any; links: LinkProps[]; }> = ({ sidebarView, closeSidebar, links }) => { return ( {sidebarView === 'CART_VIEW' && } {sidebarView === 'SHIPPING_VIEW' && } {sidebarView === 'PAYMENT_VIEW' && } {sidebarView === 'CHECKOUT_VIEW' && } {sidebarView === 'MOBILE_MENU_VIEW' && } ); }; const SidebarUI: React.FC<{ links: LinkProps[] }> = ({ links }) => { const { displaySidebar, closeSidebar, sidebarView } = useUI(); return displaySidebar ? ( ) : null; }; const Layout: React.FC = ({ children, pageProps: { categories = [], ...pageProps }, }) => { const { acceptedCookies, onAcceptCookies } = useAcceptCookies(); const { locale = 'en-US' } = useRouter(); const navBarlinks = categories.slice(0, 2).map((c) => ({ label: c.name, href: `/search/${c.slug}`, })); return (
{children}
); }; export default Layout;