From 9b5bde07beea95823f79fe397a8cec8a4a5f03c2 Mon Sep 17 00:00:00 2001 From: Richard Yi Date: Tue, 21 Mar 2023 00:27:16 +0800 Subject: [PATCH] Use collection handle for urls --- src/lib/hooks/use-layout-data.tsx | 4 +- src/modules/collections/templates/index.tsx | 2 +- .../layout/components/dropdown-menu/index.tsx | 2 +- .../layout/components/footer-nav/index.tsx | 2 +- .../components/main-menu/index.tsx | 2 +- .../components/product-actions/index.tsx | 2 +- src/modules/search/components/hit/index.tsx | 4 +- .../collections/{[id].tsx => [handle].tsx} | 59 +++++++++++++------ 8 files changed, 50 insertions(+), 27 deletions(-) rename src/pages/collections/{[id].tsx => [handle].tsx} (72%) diff --git a/src/lib/hooks/use-layout-data.tsx b/src/lib/hooks/use-layout-data.tsx index f06c79a2d..008920b49 100644 --- a/src/lib/hooks/use-layout-data.tsx +++ b/src/lib/hooks/use-layout-data.tsx @@ -7,7 +7,7 @@ import { ProductPreviewType } from "types/global" import { CalculatedVariant } from "types/medusa" type LayoutCollection = { - id: string + handle: string title: string } @@ -30,7 +30,7 @@ const fetchCollectionData = async (): Promise => { } while (collections.length < count) return collections.map((c) => ({ - id: c.id, + handle: c.handle, title: c.title, })) } diff --git a/src/modules/collections/templates/index.tsx b/src/modules/collections/templates/index.tsx index eb92a47a4..7f466e4f8 100644 --- a/src/modules/collections/templates/index.tsx +++ b/src/modules/collections/templates/index.tsx @@ -3,7 +3,7 @@ import getNumberOfSkeletons from "@lib/util/get-number-of-skeletons" import repeat from "@lib/util/repeat" import ProductPreview from "@modules/products/components/product-preview" import SkeletonProductPreview from "@modules/skeletons/components/skeleton-product-preview" -import { fetchCollectionProducts } from "@pages/collections/[id]" +import { fetchCollectionProducts } from "@pages/collections/[handle]" import { useCart } from "medusa-react" import React, { useEffect } from "react" import { useInView } from "react-intersection-observer" diff --git a/src/modules/layout/components/dropdown-menu/index.tsx b/src/modules/layout/components/dropdown-menu/index.tsx index 1af37b6aa..e63eb2185 100644 --- a/src/modules/layout/components/dropdown-menu/index.tsx +++ b/src/modules/layout/components/dropdown-menu/index.tsx @@ -74,7 +74,7 @@ const DropdownMenu = () => { return (
setOpen(false)}> {collection.title} diff --git a/src/modules/layout/components/footer-nav/index.tsx b/src/modules/layout/components/footer-nav/index.tsx index 422efe6ba..9e1a7a38d 100644 --- a/src/modules/layout/components/footer-nav/index.tsx +++ b/src/modules/layout/components/footer-nav/index.tsx @@ -24,7 +24,7 @@ const FooterNav = () => { > {collections?.map((c) => (
  • - + {c.title}
  • diff --git a/src/modules/mobile-menu/components/main-menu/index.tsx b/src/modules/mobile-menu/components/main-menu/index.tsx index 998bf791f..e600902e1 100644 --- a/src/modules/mobile-menu/components/main-menu/index.tsx +++ b/src/modules/mobile-menu/components/main-menu/index.tsx @@ -78,7 +78,7 @@ const MainMenu = () => { <> {collections.map((collection) => (
  • - +