diff --git a/components/core/Footer/Footer.tsx b/components/core/Footer/Footer.tsx index 191ed27b7..bf31d6128 100644 --- a/components/core/Footer/Footer.tsx +++ b/components/core/Footer/Footer.tsx @@ -1,18 +1,25 @@ -import cn from 'classnames' import { FC } from 'react' -import { Logo } from '@components/ui' +import cn from 'classnames' import Link from 'next/link' +import type { Page } from '@lib/bigcommerce/api/operations/get-all-pages' +import getSlug from '@utils/get-slug' +import { Logo } from '@components/ui' interface Props { className?: string children?: any + pages?: Page[] } -const Footer: FC = ({ className }) => { +const LEGAL_PAGES = ['terms-of-use', 'shipping-returns', 'privacy-policy'] + +const Footer: FC = ({ className, pages }) => { const rootClassName = cn( 'flex flex-col p-6 md:py-12 md:flex-row flex-wrap max-w-screen-xl m-auto', className ) + const { sitePages, legalPages } = getPages(pages) + return (

= ({ className }) => { -
  • - - - Terms of Use - - -
  • - -
  • - - - Privacy Policy - - -
  • + @@ -63,4 +68,31 @@ const Footer: FC = ({ className }) => { ) } +function getPages(pages?: Page[]) { + const sitePages: Page[] = [] + const legalPages: Page[] = [] + + if (pages) { + pages.forEach((page) => { + if (page.url) { + if (LEGAL_PAGES.includes(getSlug(page.url))) { + legalPages.push(page) + } else { + sitePages.push(page) + } + } + }) + } + + return { + sitePages: sitePages.sort(bySortOrder), + legalPages: legalPages.sort(bySortOrder), + } +} + +// Sort pages by the sort order assigned in the BC dashboard +function bySortOrder(a: Page, b: Page) { + return (a.sort_order ?? 0) - (b.sort_order ?? 0) +} + export default Footer diff --git a/components/core/Layout/Layout.tsx b/components/core/Layout/Layout.tsx index 603f1a50f..9f5ed5bb2 100644 --- a/components/core/Layout/Layout.tsx +++ b/components/core/Layout/Layout.tsx @@ -1,22 +1,27 @@ -import cn from 'classnames' import { FC } from 'react' +import type { Page } from '@lib/bigcommerce/api/operations/get-all-pages' import { CommerceProvider } from '@lib/bigcommerce' import { Navbar, Featurebar, Footer } from '@components/core' import { Container, Sidebar } from '@components/ui' import { CartSidebarView } from '@components/cart' import { UIProvider, useUI } from '@components/ui/context' -interface Props { - className?: string - children?: any +interface LayoutProps { + pageProps: { + pages?: Page[] + } } -const CoreLayout: FC = ({ className, children }) => { - const rootClassName = cn('h-full bg-primary', className) +interface Props { + children?: any + pages?: Page[] +} + +const CoreLayout: FC = ({ children, pages }) => { const { displaySidebar, closeSidebar } = useUI() return ( -
    +
    = ({ className, children }) => {
    {children}
    -