diff --git a/components/header/Preheader.tsx b/components/header/Preheader.tsx index 26b969f..ee9895d 100644 --- a/components/header/Preheader.tsx +++ b/components/header/Preheader.tsx @@ -35,7 +35,7 @@ export default ({ "https://deco-sites-assets.s3.sa-east-1.amazonaws.com/journeys/f5044d94-348f-4a63-aa15-76949855d78d/us-flag.webp", label: "EN", value: "en", - salesChannel: "1" + salesChannel: "1", }, { alt: "Canada", @@ -43,7 +43,7 @@ export default ({ "https://deco-sites-assets.s3.sa-east-1.amazonaws.com/journeys/d83429c1-3a7a-4751-8056-e26c7f33bd0a/ca-flag.webp", label: "EN", value: "en-ca", - salesChannel: "2" + salesChannel: "2", }, { flag: @@ -51,14 +51,14 @@ export default ({ alt: "Canada - French", label: "FR", value: "fr-ca", - salesChannel: "3" + salesChannel: "3", }, ], url, ...props }: PreheaderProps) => { const [currentLang, ...otherLanguages] = langs; - const isKidzHome = url.pathname === "/kidz"; + const isKidzHome = url?.pathname === "/kidz"; const isDesktop = useDevice() === "desktop"; if (!isDesktop) { @@ -112,7 +112,7 @@ export default ({ - + @@ -58,7 +64,7 @@ export const loader = (props: Props, req: Request) => { ...props, currencyCode: vtexSegment.currencyCode, locale: vtexSegment.cultureInfo, - } -} + }; +}; export const LoadingFallback = () => ; diff --git a/sections/Product/ProductShelf.tsx b/sections/Product/ProductShelf.tsx index cc21ba2..6cf5637 100644 --- a/sections/Product/ProductShelf.tsx +++ b/sections/Product/ProductShelf.tsx @@ -6,15 +6,16 @@ import Section, { } from "../../components/ui/Section.tsx"; import { useOffer } from "../../sdk/useOffer.ts"; import { useSendEvent } from "../../sdk/useSendEvent.ts"; -import { SectionProps, type LoadingFallbackProps } from "@deco/deco"; +import { type LoadingFallbackProps, SectionProps } from "@deco/deco"; import { getCookies } from "std/http/cookie.ts"; export interface Props extends SectionHeaderProps { products: Product[] | null; - } -export default function ProductShelf({ products, title, currencyCode, locale }: SectionProps) { +export default function ProductShelf( + { products, title, currencyCode, locale }: SectionProps, +) { if (!products || products.length === 0) { return null; } @@ -42,7 +43,12 @@ export default function ProductShelf({ products, title, currencyCode, locale }: {title} - + ); } @@ -54,8 +60,8 @@ export const loader = (props: Props, req: Request) => { ...props, currencyCode: vtexSegment.currencyCode, locale: vtexSegment.cultureInfo, - } -} + }; +}; export const LoadingFallback = ( { title, cta }: LoadingFallbackProps, diff --git a/sections/Product/ProductShelfTabbed.tsx b/sections/Product/ProductShelfTabbed.tsx index f24281b..809f604 100644 --- a/sections/Product/ProductShelfTabbed.tsx +++ b/sections/Product/ProductShelfTabbed.tsx @@ -6,7 +6,8 @@ import Section, { } from "../../components/ui/Section.tsx"; import { useOffer } from "../../sdk/useOffer.ts"; import { useSendEvent } from "../../sdk/useSendEvent.ts"; -import { type LoadingFallbackProps } from "@deco/deco"; +import { type LoadingFallbackProps, SectionProps } from "@deco/deco"; +import { getCookies } from "std/http/cookie.ts"; /** @titleBy title */ interface Tab { title: string; @@ -17,9 +18,25 @@ export interface Props extends SectionHeaderProps { /** @hide true */ tabIndex?: number; } -export default function TabbedProductShelf( - { tabs, title, cta, tabIndex }: Props, -) { + +export const loader = (props: Props, req: Request) => { + const cookies = getCookies(req.headers); + const vtexSegment = JSON.parse(atob(cookies["vtex_segment"])); + return { + ...props, + currencyCode: vtexSegment.currencyCode, + locale: vtexSegment.cultureInfo, + }; +}; + +export default function TabbedProductShelf({ + tabs, + title, + cta, + tabIndex, + currencyCode, + locale, +}: SectionProps) { const ti = typeof tabIndex === "number" ? Math.min(Math.max(tabIndex, 0), tabs.length) : 0; @@ -34,7 +51,7 @@ export default function TabbedProductShelf( mapProductToAnalyticsItem({ index, product, - ...(useOffer(product.offers)), + ...useOffer(product.offers), }) ) ?? [], }, @@ -51,14 +68,23 @@ export default function TabbedProductShelf( No Products found ) - : } + : ( + + )} ); } -export const LoadingFallback = ( - { title, cta }: LoadingFallbackProps, -) => ( + +export const LoadingFallback = ({ + title, + cta, +}: LoadingFallbackProps) => (