From e111d351bfc73f8f88c4a10956e20345226741e5 Mon Sep 17 00:00:00 2001 From: Luis Alvarez Date: Sun, 25 Oct 2020 18:21:28 -0500 Subject: [PATCH] Add current locale to commerce provider --- components/core/Layout/Layout.tsx | 13 ++++++++----- components/product/ProductCard/ProductCard.tsx | 11 +++++------ 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/components/core/Layout/Layout.tsx b/components/core/Layout/Layout.tsx index f76eed877..c96d434bd 100644 --- a/components/core/Layout/Layout.tsx +++ b/components/core/Layout/Layout.tsx @@ -1,14 +1,16 @@ +import { FC, useEffect, useState } from 'react' import cn from 'classnames' -import s from './Layout.module.css' -import React, { FC, useEffect, useState } from 'react' +import { useRouter } from 'next/router' +import type { Page } from '@lib/bigcommerce/api/operations/get-all-pages' +import { CommerceProvider } from '@lib/bigcommerce' import { CartSidebarView } from '@components/cart' import { Container, Sidebar, Button, Modal } from '@components/ui' import { Navbar, Featurebar, Footer } from '@components/core' import { LoginView, SignUpView } from '@components/auth' import { useUI } from '@components/ui/context' import { usePreventScroll } from '@react-aria/overlays' -import { CommerceProvider } from '@lib/bigcommerce' -import type { Page } from '@lib/bigcommerce/api/operations/get-all-pages' +import s from './Layout.module.css' + interface Props { pageProps: { pages?: Page[] @@ -25,6 +27,7 @@ const Layout: FC = ({ children, pageProps }) => { } = useUI() const [acceptedCookies, setAcceptedCookies] = useState(false) const [hasScrolled, setHasScrolled] = useState(false) + const { locale = 'en-US' } = useRouter() // TODO: Update code, add throttle and more. // TODO: Make sure to not do any unnecessary updates as it's doing right now @@ -47,7 +50,7 @@ const Layout: FC = ({ children, pageProps }) => { }) return ( - +
= ({ priority, }) => { const src = p.images.edges?.[0]?.node.urlLarge! + const { price } = usePrice({ + amount: p.prices?.price?.value, + baseAmount: p.prices?.retailPrice?.value, + currencyCode: p.prices?.price?.currencyCode!, + }) if (variant === 'slim') { return ( @@ -47,12 +52,6 @@ const ProductCard: FC = ({ ) } - const { price } = usePrice({ - amount: p.prices?.price?.value, - baseAmount: p.prices?.retailPrice?.value, - currencyCode: p.prices?.price?.currencyCode!, - }) - return (