diff --git a/storefront/actions/medusa/order.ts b/storefront/actions/medusa/order.ts index 0a0edda..e36dc2c 100644 --- a/storefront/actions/medusa/order.ts +++ b/storefront/actions/medusa/order.ts @@ -33,8 +33,9 @@ export async function placeOrder() { if (cartRes?.type === "order") { removeCartId(); - // TODO: make this us the country code - redirect(`/order/confirmed/${cartRes.order.id}`); + const countryCode = + cartRes.order.shipping_address?.country_code?.toLowerCase(); + redirect(`/${countryCode}/order/confirmed/${cartRes.order.id}`); } return cartRes.cart; diff --git a/storefront/app/(country-code)/layout.tsx b/storefront/app/(country-code)/layout.tsx deleted file mode 100644 index 342c453..0000000 --- a/storefront/app/(country-code)/layout.tsx +++ /dev/null @@ -1,44 +0,0 @@ -import type {PropsWithChildren} from "react"; - -import {ExitPreview} from "@/components/exit-preview"; -import {TailwindIndicator} from "@/components/tailwind-indicator"; -import cache from "next/cache"; -import {draftMode} from "next/headers"; -import VisualEditing from "next-sanity/visual-editing/client-component"; - -export default function Layout({children}: PropsWithChildren) { - const shouldEnableDraftModeToggle = - process.env.NODE_ENV === "development" && draftMode().isEnabled; - return ( - - {children} - {draftMode().isEnabled && ( - { - "use server"; - if (!draftMode().isEnabled) { - console.debug( - "Skipped manual refresh because draft mode is not enabled", - ); - return; - } - if (payload.source === "mutation") { - if (payload.document.slug?.current) { - const tag = `${payload.document._type}:${payload.document.slug.current}`; - console.log("Revalidate slug", tag); - await cache.revalidateTag(tag); - } - console.log("Revalidate tag", payload.document._type); - return cache.revalidateTag(payload.document._type); - } - await cache.revalidatePath("/", "layout"); - }} - /> - )} - - {shouldEnableDraftModeToggle && ( - - )} - - ); -} diff --git a/storefront/app/(country-code)/(checkout)/checkout/_parts/cart-details/index.tsx b/storefront/app/[countryCode]/(checkout)/checkout/_parts/cart-details/index.tsx similarity index 100% rename from storefront/app/(country-code)/(checkout)/checkout/_parts/cart-details/index.tsx rename to storefront/app/[countryCode]/(checkout)/checkout/_parts/cart-details/index.tsx diff --git a/storefront/app/(country-code)/(checkout)/checkout/_parts/cart-details/line-item.tsx b/storefront/app/[countryCode]/(checkout)/checkout/_parts/cart-details/line-item.tsx similarity index 100% rename from storefront/app/(country-code)/(checkout)/checkout/_parts/cart-details/line-item.tsx rename to storefront/app/[countryCode]/(checkout)/checkout/_parts/cart-details/line-item.tsx diff --git a/storefront/app/(country-code)/(checkout)/checkout/_parts/checkout-form/address-form/index.tsx b/storefront/app/[countryCode]/(checkout)/checkout/_parts/checkout-form/address-form/index.tsx similarity index 100% rename from storefront/app/(country-code)/(checkout)/checkout/_parts/checkout-form/address-form/index.tsx rename to storefront/app/[countryCode]/(checkout)/checkout/_parts/checkout-form/address-form/index.tsx diff --git a/storefront/app/(country-code)/(checkout)/checkout/_parts/checkout-form/delivery/index.tsx b/storefront/app/[countryCode]/(checkout)/checkout/_parts/checkout-form/delivery/index.tsx similarity index 100% rename from storefront/app/(country-code)/(checkout)/checkout/_parts/checkout-form/delivery/index.tsx rename to storefront/app/[countryCode]/(checkout)/checkout/_parts/checkout-form/delivery/index.tsx diff --git a/storefront/app/(country-code)/(checkout)/checkout/_parts/checkout-form/index.tsx b/storefront/app/[countryCode]/(checkout)/checkout/_parts/checkout-form/index.tsx similarity index 100% rename from storefront/app/(country-code)/(checkout)/checkout/_parts/checkout-form/index.tsx rename to storefront/app/[countryCode]/(checkout)/checkout/_parts/checkout-form/index.tsx diff --git a/storefront/app/(country-code)/(checkout)/checkout/_parts/checkout-form/payment/button/index.tsx b/storefront/app/[countryCode]/(checkout)/checkout/_parts/checkout-form/payment/button/index.tsx similarity index 100% rename from storefront/app/(country-code)/(checkout)/checkout/_parts/checkout-form/payment/button/index.tsx rename to storefront/app/[countryCode]/(checkout)/checkout/_parts/checkout-form/payment/button/index.tsx diff --git a/storefront/app/(country-code)/(checkout)/checkout/_parts/checkout-form/payment/button/manual.tsx b/storefront/app/[countryCode]/(checkout)/checkout/_parts/checkout-form/payment/button/manual.tsx similarity index 100% rename from storefront/app/(country-code)/(checkout)/checkout/_parts/checkout-form/payment/button/manual.tsx rename to storefront/app/[countryCode]/(checkout)/checkout/_parts/checkout-form/payment/button/manual.tsx diff --git a/storefront/app/(country-code)/(checkout)/checkout/_parts/checkout-form/payment/button/stripe.tsx b/storefront/app/[countryCode]/(checkout)/checkout/_parts/checkout-form/payment/button/stripe.tsx similarity index 100% rename from storefront/app/(country-code)/(checkout)/checkout/_parts/checkout-form/payment/button/stripe.tsx rename to storefront/app/[countryCode]/(checkout)/checkout/_parts/checkout-form/payment/button/stripe.tsx diff --git a/storefront/app/(country-code)/(checkout)/checkout/_parts/checkout-form/payment/index.tsx b/storefront/app/[countryCode]/(checkout)/checkout/_parts/checkout-form/payment/index.tsx similarity index 100% rename from storefront/app/(country-code)/(checkout)/checkout/_parts/checkout-form/payment/index.tsx rename to storefront/app/[countryCode]/(checkout)/checkout/_parts/checkout-form/payment/index.tsx diff --git a/storefront/app/(country-code)/(checkout)/checkout/_parts/checkout-form/payment/utils.ts b/storefront/app/[countryCode]/(checkout)/checkout/_parts/checkout-form/payment/utils.ts similarity index 100% rename from storefront/app/(country-code)/(checkout)/checkout/_parts/checkout-form/payment/utils.ts rename to storefront/app/[countryCode]/(checkout)/checkout/_parts/checkout-form/payment/utils.ts diff --git a/storefront/app/(country-code)/(checkout)/checkout/_parts/checkout-form/payment/wrapper/index.tsx b/storefront/app/[countryCode]/(checkout)/checkout/_parts/checkout-form/payment/wrapper/index.tsx similarity index 100% rename from storefront/app/(country-code)/(checkout)/checkout/_parts/checkout-form/payment/wrapper/index.tsx rename to storefront/app/[countryCode]/(checkout)/checkout/_parts/checkout-form/payment/wrapper/index.tsx diff --git a/storefront/app/(country-code)/(checkout)/checkout/_parts/checkout-form/payment/wrapper/stripe-wrapper.tsx b/storefront/app/[countryCode]/(checkout)/checkout/_parts/checkout-form/payment/wrapper/stripe-wrapper.tsx similarity index 100% rename from storefront/app/(country-code)/(checkout)/checkout/_parts/checkout-form/payment/wrapper/stripe-wrapper.tsx rename to storefront/app/[countryCode]/(checkout)/checkout/_parts/checkout-form/payment/wrapper/stripe-wrapper.tsx diff --git a/storefront/app/(country-code)/(checkout)/checkout/_parts/checkout-form/review.tsx b/storefront/app/[countryCode]/(checkout)/checkout/_parts/checkout-form/review.tsx similarity index 100% rename from storefront/app/(country-code)/(checkout)/checkout/_parts/checkout-form/review.tsx rename to storefront/app/[countryCode]/(checkout)/checkout/_parts/checkout-form/review.tsx diff --git a/storefront/app/(country-code)/(checkout)/checkout/page.tsx b/storefront/app/[countryCode]/(checkout)/checkout/page.tsx similarity index 100% rename from storefront/app/(country-code)/(checkout)/checkout/page.tsx rename to storefront/app/[countryCode]/(checkout)/checkout/page.tsx diff --git a/storefront/app/(country-code)/(website)/[...path]/_part/table-of-content.tsx b/storefront/app/[countryCode]/(website)/[...path]/_part/table-of-content.tsx similarity index 90% rename from storefront/app/(country-code)/(website)/[...path]/_part/table-of-content.tsx rename to storefront/app/[countryCode]/(website)/[...path]/_part/table-of-content.tsx index e7b6d4f..4335d49 100644 --- a/storefront/app/(country-code)/(website)/[...path]/_part/table-of-content.tsx +++ b/storefront/app/[countryCode]/(website)/[...path]/_part/table-of-content.tsx @@ -1,12 +1,13 @@ import type {TEXT_PAGE_QUERYResult} from "@/types/sanity.generated"; import type {BlocksBody} from "@/utils/content/toc"; +import LocalizedLink from "@/components/shared/localized-link"; import TocSelect from "@/components/shared/toc-select"; import Body from "@/components/shared/typography/body"; import getBlocksToc from "@/utils/content/toc"; import {getPtComponentId} from "@/utils/ids"; import {toPlainText} from "@portabletext/react"; -import Link from "next/link"; +import React from "react"; export default function TableOfContents({ body, @@ -24,7 +25,7 @@ export default function TableOfContents({ index, ) => !item.isSub && ( - {toPlainText(item.block)} - + ), )} diff --git a/storefront/app/(country-code)/(website)/[...path]/page.tsx b/storefront/app/[countryCode]/(website)/[...path]/page.tsx similarity index 92% rename from storefront/app/(country-code)/(website)/[...path]/page.tsx rename to storefront/app/[countryCode]/(website)/[...path]/page.tsx index 48040de..4555b4a 100644 --- a/storefront/app/(country-code)/(website)/[...path]/page.tsx +++ b/storefront/app/[countryCode]/(website)/[...path]/page.tsx @@ -9,7 +9,7 @@ import {notFound} from "next/navigation"; import TextPage from "./text-page.template"; -export type DynamicRouteProps = PageProps<"...path">; +export type DynamicRouteProps = PageProps<"...path" | "countryCode">; export async function generateMetadata( {params}: DynamicRouteProps, @@ -34,7 +34,6 @@ export async function generateMetadata( export default async function DynamicRoute({params}: DynamicRouteProps) { const initialData = await loadPageByPathname({params}); - if (!initialData) return notFound(); switch (initialData._type) { @@ -42,6 +41,7 @@ export default async function DynamicRoute({params}: DynamicRouteProps) { case "home": return ( ); diff --git a/storefront/app/(country-code)/(website)/[...path]/text-page.template.tsx b/storefront/app/[countryCode]/(website)/[...path]/text-page.template.tsx similarity index 100% rename from storefront/app/(country-code)/(website)/[...path]/text-page.template.tsx rename to storefront/app/[countryCode]/(website)/[...path]/text-page.template.tsx diff --git a/storefront/app/(country-code)/(website)/faqs/_parts/faq-content.tsx b/storefront/app/[countryCode]/(website)/faqs/_parts/faq-content.tsx similarity index 100% rename from storefront/app/(country-code)/(website)/faqs/_parts/faq-content.tsx rename to storefront/app/[countryCode]/(website)/faqs/_parts/faq-content.tsx diff --git a/storefront/app/(country-code)/(website)/faqs/_parts/faq-page.tsx b/storefront/app/[countryCode]/(website)/faqs/_parts/faq-page.tsx similarity index 100% rename from storefront/app/(country-code)/(website)/faqs/_parts/faq-page.tsx rename to storefront/app/[countryCode]/(website)/faqs/_parts/faq-page.tsx diff --git a/storefront/app/(country-code)/(website)/faqs/_parts/search-bar.tsx b/storefront/app/[countryCode]/(website)/faqs/_parts/search-bar.tsx similarity index 100% rename from storefront/app/(country-code)/(website)/faqs/_parts/search-bar.tsx rename to storefront/app/[countryCode]/(website)/faqs/_parts/search-bar.tsx diff --git a/storefront/app/(country-code)/(website)/faqs/page.tsx b/storefront/app/[countryCode]/(website)/faqs/page.tsx similarity index 100% rename from storefront/app/(country-code)/(website)/faqs/page.tsx rename to storefront/app/[countryCode]/(website)/faqs/page.tsx diff --git a/storefront/app/(country-code)/(website)/layout.tsx b/storefront/app/[countryCode]/(website)/layout.tsx similarity index 100% rename from storefront/app/(country-code)/(website)/layout.tsx rename to storefront/app/[countryCode]/(website)/layout.tsx diff --git a/storefront/app/(country-code)/(website)/not-found.tsx b/storefront/app/[countryCode]/(website)/not-found.tsx similarity index 100% rename from storefront/app/(country-code)/(website)/not-found.tsx rename to storefront/app/[countryCode]/(website)/not-found.tsx diff --git a/storefront/app/(country-code)/(website)/order/confirmed/[id]/_parts/order-item.tsx b/storefront/app/[countryCode]/(website)/order/confirmed/[id]/_parts/order-item.tsx similarity index 100% rename from storefront/app/(country-code)/(website)/order/confirmed/[id]/_parts/order-item.tsx rename to storefront/app/[countryCode]/(website)/order/confirmed/[id]/_parts/order-item.tsx diff --git a/storefront/app/(country-code)/(website)/order/confirmed/[id]/page.tsx b/storefront/app/[countryCode]/(website)/order/confirmed/[id]/page.tsx similarity index 100% rename from storefront/app/(country-code)/(website)/order/confirmed/[id]/page.tsx rename to storefront/app/[countryCode]/(website)/order/confirmed/[id]/page.tsx diff --git a/storefront/app/(country-code)/(website)/page.tsx b/storefront/app/[countryCode]/(website)/page.tsx similarity index 100% rename from storefront/app/(country-code)/(website)/page.tsx rename to storefront/app/[countryCode]/(website)/page.tsx diff --git a/storefront/app/(country-code)/(website)/products/[handle]/_parts/add-to-cart.tsx b/storefront/app/[countryCode]/(website)/products/[handle]/_parts/add-to-cart.tsx similarity index 99% rename from storefront/app/(country-code)/(website)/products/[handle]/_parts/add-to-cart.tsx rename to storefront/app/[countryCode]/(website)/products/[handle]/_parts/add-to-cart.tsx index ee758dc..9f236af 100644 --- a/storefront/app/(country-code)/(website)/products/[handle]/_parts/add-to-cart.tsx +++ b/storefront/app/[countryCode]/(website)/products/[handle]/_parts/add-to-cart.tsx @@ -16,7 +16,6 @@ export default function AddToCart({ variant: "PDP" | "sticky"; }) { const {activeVariant} = useProductVariants(); - return ( ) { return ( - Home{" "} + Home{" "} {collection && ( <> {" / "} - + {collection.title} - {" "} + {" "} )} {" / "} diff --git a/storefront/app/(country-code)/(website)/products/[handle]/_parts/image-carousel.tsx b/storefront/app/[countryCode]/(website)/products/[handle]/_parts/image-carousel.tsx similarity index 100% rename from storefront/app/(country-code)/(website)/products/[handle]/_parts/image-carousel.tsx rename to storefront/app/[countryCode]/(website)/products/[handle]/_parts/image-carousel.tsx diff --git a/storefront/app/(country-code)/(website)/products/[handle]/_parts/options.tsx b/storefront/app/[countryCode]/(website)/products/[handle]/_parts/options.tsx similarity index 100% rename from storefront/app/(country-code)/(website)/products/[handle]/_parts/options.tsx rename to storefront/app/[countryCode]/(website)/products/[handle]/_parts/options.tsx diff --git a/storefront/app/(country-code)/(website)/products/[handle]/_parts/price.tsx b/storefront/app/[countryCode]/(website)/products/[handle]/_parts/price.tsx similarity index 100% rename from storefront/app/(country-code)/(website)/products/[handle]/_parts/price.tsx rename to storefront/app/[countryCode]/(website)/products/[handle]/_parts/price.tsx diff --git a/storefront/app/(country-code)/(website)/products/[handle]/_parts/product-information.tsx b/storefront/app/[countryCode]/(website)/products/[handle]/_parts/product-information.tsx similarity index 100% rename from storefront/app/(country-code)/(website)/products/[handle]/_parts/product-information.tsx rename to storefront/app/[countryCode]/(website)/products/[handle]/_parts/product-information.tsx diff --git a/storefront/app/(country-code)/(website)/products/[handle]/_parts/specs.tsx b/storefront/app/[countryCode]/(website)/products/[handle]/_parts/specs.tsx similarity index 100% rename from storefront/app/(country-code)/(website)/products/[handle]/_parts/specs.tsx rename to storefront/app/[countryCode]/(website)/products/[handle]/_parts/specs.tsx diff --git a/storefront/app/(country-code)/(website)/products/[handle]/_parts/sticky-atc.tsx b/storefront/app/[countryCode]/(website)/products/[handle]/_parts/sticky-atc.tsx similarity index 100% rename from storefront/app/(country-code)/(website)/products/[handle]/_parts/sticky-atc.tsx rename to storefront/app/[countryCode]/(website)/products/[handle]/_parts/sticky-atc.tsx diff --git a/storefront/app/(country-code)/(website)/products/[handle]/page.tsx b/storefront/app/[countryCode]/(website)/products/[handle]/page.tsx similarity index 83% rename from storefront/app/(country-code)/(website)/products/[handle]/page.tsx rename to storefront/app/[countryCode]/(website)/products/[handle]/page.tsx index ccc3f04..027af4c 100644 --- a/storefront/app/(country-code)/(website)/products/[handle]/page.tsx +++ b/storefront/app/[countryCode]/(website)/products/[handle]/page.tsx @@ -10,14 +10,10 @@ import {ProductImagesCarousel} from "./_parts/image-carousel"; import ProductInformation from "./_parts/product-information"; import StickyAtc from "./_parts/sticky-atc"; -type ProductPageProps = PageProps<"handle">; +type ProductPageProps = PageProps<"countryCode" | "handle">; export default async function ProductPage({params}: ProductPageProps) { - const region = await getRegion( - // TODO: Make this come from the params - process.env.NEXT_PUBLIC_MEDUSA_DEFAULT_COUNTRY_CODE!, - ); - + const region = await getRegion(params.countryCode); if (!region) { console.log("No region found"); return notFound(); @@ -43,7 +39,11 @@ export default async function ProductPage({params}: ProductPageProps) { {content?.sections && ( - + )} diff --git a/storefront/app/(country-code)/(website)/products/[handle]/product-context.tsx b/storefront/app/[countryCode]/(website)/products/[handle]/product-context.tsx similarity index 100% rename from storefront/app/(country-code)/(website)/products/[handle]/product-context.tsx rename to storefront/app/[countryCode]/(website)/products/[handle]/product-context.tsx diff --git a/storefront/app/(country-code)/(website)/products/page.tsx b/storefront/app/[countryCode]/(website)/products/page.tsx similarity index 85% rename from storefront/app/(country-code)/(website)/products/page.tsx rename to storefront/app/[countryCode]/(website)/products/page.tsx index aca3cca..d886fe1 100644 --- a/storefront/app/(country-code)/(website)/products/page.tsx +++ b/storefront/app/[countryCode]/(website)/products/page.tsx @@ -8,11 +8,12 @@ import Heading from "@/components/shared/typography/heading"; import {Suspense} from "react"; type CollectionPageProps = PageProps< - never, + "countryCode", "category" | "collection" | "page" | "sort" >; export default async function CollectionPage({ + params, searchParams, }: CollectionPageProps) { return ( @@ -25,7 +26,10 @@ export default async function CollectionPage({
}> - +
diff --git a/storefront/app/[countryCode]/layout.tsx b/storefront/app/[countryCode]/layout.tsx new file mode 100644 index 0000000..b103042 --- /dev/null +++ b/storefront/app/[countryCode]/layout.tsx @@ -0,0 +1,52 @@ +import type {PageProps} from "@/types"; +import type {PropsWithChildren} from "react"; + +import {CountryCodeProvider} from "@/components/context/country-code-context"; +import {ExitPreview} from "@/components/exit-preview"; +import {TailwindIndicator} from "@/components/tailwind-indicator"; +import cache from "next/cache"; +import {draftMode} from "next/headers"; +import VisualEditing from "next-sanity/visual-editing/client-component"; + +type LayoutProps = PropsWithChildren< + Omit, "searchParams"> +>; + +export default function Layout({children, params}: LayoutProps) { + const shouldEnableDraftModeToggle = + process.env.NODE_ENV === "development" && draftMode().isEnabled; + return ( + + + {children} + {draftMode().isEnabled && ( + { + "use server"; + if (!draftMode().isEnabled) { + console.debug( + "Skipped manual refresh because draft mode is not enabled", + ); + return; + } + if (payload.source === "mutation") { + if (payload.document.slug?.current) { + const tag = `${payload.document._type}:${payload.document.slug.current}`; + console.log("Revalidate slug", tag); + await cache.revalidateTag(tag); + } + console.log("Revalidate tag", payload.document._type); + return cache.revalidateTag(payload.document._type); + } + await cache.revalidatePath("/", "layout"); + }} + /> + )} + + {shouldEnableDraftModeToggle && ( + + )} + + + ); +} diff --git a/storefront/components/context/country-code-context.tsx b/storefront/components/context/country-code-context.tsx new file mode 100644 index 0000000..b028497 --- /dev/null +++ b/storefront/components/context/country-code-context.tsx @@ -0,0 +1,32 @@ +"use client"; +import type {PropsWithChildren} from "react"; + +import {createContext, useContext} from "react"; + +type CountryCodeContextType = { + countryCode: string; +}; + +type CountryCodeProviderProps = PropsWithChildren; + +export const CountryCodeContext = createContext< + CountryCodeContextType | undefined +>(undefined); + +export function CountryCodeProvider({ + children, + countryCode, +}: CountryCodeProviderProps) { + return ( + + {children} + + ); +} +export function useCountryCode() { + const context = useContext(CountryCodeContext); + if (context === undefined) { + throw new Error("useCountryCode must be used within a CountryCodeProvider"); + } + return context.countryCode; +} diff --git a/storefront/components/global/footer/parts/bottom-links.tsx b/storefront/components/global/footer/parts/bottom-links.tsx index 2c84df3..23e0bf2 100644 --- a/storefront/components/global/footer/parts/bottom-links.tsx +++ b/storefront/components/global/footer/parts/bottom-links.tsx @@ -1,7 +1,7 @@ import type {Footer} from "@/types/sanity.generated"; +import LocalizedLink from "@/components/shared/localized-link"; import Label from "@/components/shared/typography/label"; -import Link from "next/link"; import React from "react"; export default function BottomLinks({ @@ -19,7 +19,7 @@ export default function BottomLinks({ {bottomLinks?.map((link) => { if (!link.link) return null; return ( - {link.label} - + ); })} @@ -36,11 +36,11 @@ export default function BottomLinks({ {socialLinks?.map((link) => { if (!link.link) return null; return ( - + - + ); })} diff --git a/storefront/components/global/footer/parts/top-links.tsx b/storefront/components/global/footer/parts/top-links.tsx index 05edbc7..72287f4 100644 --- a/storefront/components/global/footer/parts/top-links.tsx +++ b/storefront/components/global/footer/parts/top-links.tsx @@ -1,8 +1,8 @@ import type {Footer} from "@/types/sanity.generated"; +import LocalizedLink from "@/components/shared/localized-link"; import {RichText} from "@/components/shared/rich-text"; import Body from "@/components/shared/typography/body"; -import Link from "next/link"; export default function TopLinks({information, linkList}: NonNullable