forked from crowetic/commerce
* Custom Checkout Progress * Updates to Checkout * Custom Checkout Progress * Adding tabs * Adding Collapse * Adding Collapse * Improving Sidebar Scroll * Modif footer * Changes * More design updates * sidebar cart * More design updates * More design updates * More design updates * More design updates * Types * Types * Design Updates * More changes * More changes * More changes * Changes * Changes * Changes * New tailwind required changes * Sidebar Styling issues with Mobile * Latest changes - Normalizing cart * Styling Fixes * New changes * Changes * latest * Refactor and Renaming some UI Props * Adding Quantity Component * Adding Rating Component * Rating Component * More updates * User Select disabled, plus hidding horizontal scroll bars * Changes * Adding ProductOptions Component and more helpers * Styling updates * Styling updates * Fix for slim tags * Missmatch with RightArrow * Footer updates and some styles * Latest Updates * Latest Updates * Latest Updates * Removing Portal, since it's not needed. We might add it later I'd rather not to. * Removing Portal, since it's not needed. We might add it later I'd rather not to. * Sam backdrop filter * General UI Improvements * General UI Improvements * Search now with Geist Colors * Now with Geist Colors * Changes * Scroll for Mobile on IOs devises * LoadingDots Working (: * Changes * More Changes * Perf changes * More perf changes * Fade to the Nametags in the ProductCard * changes * Search issue ui * Search issue ui * Make sure to only refresh navbar and modals when required * Index revalidate * Fixed image issue * hide album scroll on windows * Fix scrollbar * Changing * Adding 404 with Layout * Removing Toast * Adding Assets * Adding Assets * Progress with LocalProvider * New productTag * Only images for the drop * changes * Empty SWRhooks * Adding Local Provider * Working local * Working view of a LocalProvider * More updates * Changes * Removed react-ticker * default to local if no env available * default to local if no env available * add missing `@` to css import * rewrite search rewrites to multiple pages * allow requests in getStaticProps to execute in parallel * make type import explicit * add a tsconfig.js file * use local provider in tsconfig.js * avoid a circular dependency * Saleor was not in the providers list * avoid circular dependency in bigcommerce * Adding more to the Local Provider (#366) * Adding more data * Adding more data * optimize assets (#370) * Optimize assets (#372) * optimize assets * remove assets * remove assets * cart enabled * Adding saleor * Changes with Webpack * Changes Co-authored-by: Luis Alvarez <luis@vercel.com> Co-authored-by: Tobias Koppers <tobias.koppers@googlemail.com> Co-authored-by: Shu Ding <g@shud.in>
127 lines
3.5 KiB
TypeScript
127 lines
3.5 KiB
TypeScript
import cn from 'classnames'
|
|
import React, { FC } from 'react'
|
|
import dynamic from 'next/dynamic'
|
|
import { useRouter } from 'next/router'
|
|
import { CommerceProvider } from '@framework'
|
|
import { useUI } from '@components/ui/context'
|
|
import type { Page } from '@commerce/types/page'
|
|
import { Navbar, Footer } from '@components/common'
|
|
import type { Category } from '@commerce/types/site'
|
|
import ShippingView from '@components/checkout/ShippingView'
|
|
import CartSidebarView from '@components/cart/CartSidebarView'
|
|
import { useAcceptCookies } from '@lib/hooks/useAcceptCookies'
|
|
import { Sidebar, Button, Modal, LoadingDots } from '@components/ui'
|
|
import PaymentMethodView from '@components/checkout/PaymentMethodView'
|
|
import CheckoutSidebarView from '@components/checkout/CheckoutSidebarView'
|
|
|
|
import LoginView from '@components/auth/LoginView'
|
|
import s from './Layout.module.css'
|
|
|
|
const Loading = () => (
|
|
<div className="w-80 h-80 flex items-center text-center justify-center p-3">
|
|
<LoadingDots />
|
|
</div>
|
|
)
|
|
|
|
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
|
|
)
|
|
|
|
interface Props {
|
|
pageProps: {
|
|
pages?: Page[]
|
|
categories: Category[]
|
|
}
|
|
}
|
|
|
|
const ModalView: FC<{ modalView: string; closeModal(): any }> = ({
|
|
modalView,
|
|
closeModal,
|
|
}) => {
|
|
return (
|
|
<Modal onClose={closeModal}>
|
|
{modalView === 'LOGIN_VIEW' && <LoginView />}
|
|
{modalView === 'SIGNUP_VIEW' && <SignUpView />}
|
|
{modalView === 'FORGOT_VIEW' && <ForgotPassword />}
|
|
</Modal>
|
|
)
|
|
}
|
|
|
|
const ModalUI: FC = () => {
|
|
const { displayModal, closeModal, modalView } = useUI()
|
|
return displayModal ? (
|
|
<ModalView modalView={modalView} closeModal={closeModal} />
|
|
) : null
|
|
}
|
|
|
|
const SidebarView: FC<{ sidebarView: string; closeSidebar(): any }> = ({
|
|
sidebarView,
|
|
closeSidebar,
|
|
}) => {
|
|
return (
|
|
<Sidebar onClose={closeSidebar}>
|
|
{sidebarView === 'CART_VIEW' && <CartSidebarView />}
|
|
{sidebarView === 'CHECKOUT_VIEW' && <CheckoutSidebarView />}
|
|
{sidebarView === 'PAYMENT_VIEW' && <PaymentMethodView />}
|
|
{sidebarView === 'SHIPPING_VIEW' && <ShippingView />}
|
|
</Sidebar>
|
|
)
|
|
}
|
|
|
|
const SidebarUI: FC = () => {
|
|
const { displaySidebar, closeSidebar, sidebarView } = useUI()
|
|
return displaySidebar ? (
|
|
<SidebarView sidebarView={sidebarView} closeSidebar={closeSidebar} />
|
|
) : null
|
|
}
|
|
|
|
const Layout: FC<Props> = ({
|
|
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 (
|
|
<CommerceProvider locale={locale}>
|
|
<div className={cn(s.root)}>
|
|
<Navbar links={navBarlinks} />
|
|
<main className="fit">{children}</main>
|
|
<Footer pages={pageProps.pages} />
|
|
<ModalUI />
|
|
<SidebarUI />
|
|
<FeatureBar
|
|
title="This site uses cookies to improve your experience. By clicking, you agree to our Privacy Policy."
|
|
hide={acceptedCookies}
|
|
action={
|
|
<Button className="mx-5" onClick={() => onAcceptCookies()}>
|
|
Accept cookies
|
|
</Button>
|
|
}
|
|
/>
|
|
</div>
|
|
</CommerceProvider>
|
|
)
|
|
}
|
|
|
|
export default Layout
|