forked from crowetic/commerce
* Moved everything * Figuring out how to make imports work * Updated exports * Added missing exports * Added @vercel/commerce-local to `site` * Updated commerce config * Updated exports and commerce config * Updated commerce hoc * Fixed exports in local * Added publish config * Updated imports in site * It's actually working * Don't use debugger in dev for better speeds * Improved DX when editing packages * Set up eslint with husky * Updated prettier config * Added prettier setup to every package * Moved bigcommerce * Moved Bigcommerce to src and package updates * Updated setup of bigcommerce * Moved definitions script * Moved commercejs * Move to src * Fixed types in commercejs * Moved kibocommerce * Moved kibocommerce to src * Added package/tsconfig to kibocommerce * Fixed imports and other things * Moved ordercloud * Moved ordercloud to src * Fixed imports * Added missing prettier files * Moved Saleor * Moved Saleor to src * Fixed imports * Replaced all imports to @commerce * Added prettierignore/rc to all providers * Moved shopify to src * Build shopify in packages * Moved Spree * Moved spree to src * Updated spree * Moved swell * Moved swell to src * Fixed type imports in swell * Moved Vendure to packages * Moved vendure to src * Fixed imports in vendure * Added codegen to saleor * Updated codegen setup for shopify * Added codegen to vendure * Added codegen to kibocommerce * Added all packages to site's deps * Updated codegen setup in bigcommerce * Minor fixes * Updated providers' names in site * Updated packages based on Bel's changes * Updated turbo to latest * Fixed ts complains * Set npm engine in root * New lockfile install * remove engines * Regen lockfile * Switched from npm to yarn * Updated typesVersions in all packages * Moved dep * Updated SWR to the just released 1.2.0 * Removed "isolatedModules" from packages * Updated list of providers and default * Updated swell declaration * Removed next import from kibocommerce * Added COMMERCE_PROVIDER log * Added another log * Updated turbo config * Updated docs * Removed test logs Co-authored-by: Jared Palmer <jared@jaredpalmer.com>
151 lines
4.0 KiB
TypeScript
151 lines
4.0 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, LoadingDots } from '@components/ui'
|
|
import PaymentMethodView from '@components/checkout/PaymentMethodView'
|
|
import CheckoutSidebarView from '@components/checkout/CheckoutSidebarView'
|
|
import { CheckoutProvider } from '@components/checkout/context'
|
|
import MenuSidebarView, { Link } from '../UserNav/MenuSidebarView'
|
|
|
|
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
|
|
}
|
|
)
|
|
|
|
const Modal = dynamic(
|
|
() => import('@components/ui/Modal'),
|
|
{
|
|
...dynamicProps,
|
|
ssr: false
|
|
}
|
|
)
|
|
|
|
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
|
|
links: Link[]
|
|
}> = ({ sidebarView, closeSidebar, links }) => {
|
|
return (
|
|
<Sidebar onClose={closeSidebar}>
|
|
{sidebarView === 'MOBILEMENU_VIEW' && <MenuSidebarView links={links} />}
|
|
{sidebarView === 'CART_VIEW' && <CartSidebarView />}
|
|
{sidebarView === 'CHECKOUT_VIEW' && <CheckoutSidebarView />}
|
|
{sidebarView === 'PAYMENT_VIEW' && <PaymentMethodView />}
|
|
{sidebarView === 'SHIPPING_VIEW' && <ShippingView />}
|
|
</Sidebar>
|
|
)
|
|
}
|
|
|
|
const SidebarUI: FC<{ links: any }> = ({ links }) => {
|
|
const { displaySidebar, closeSidebar, sidebarView } = useUI()
|
|
return displaySidebar ? (
|
|
<SidebarView
|
|
sidebarView={sidebarView}
|
|
closeSidebar={closeSidebar}
|
|
links={links}
|
|
/>
|
|
) : 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 />
|
|
<CheckoutProvider>
|
|
<SidebarUI links={navBarlinks} />
|
|
</CheckoutProvider>
|
|
<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
|