diff --git a/src/app/products/[category]/[subcategory]/[product]/page.tsx b/src/app/products/[category]/[subcategory]/[product]/page.tsx
index 878d458..16b6a56 100644
--- a/src/app/products/[category]/[subcategory]/[product]/page.tsx
+++ b/src/app/products/[category]/[subcategory]/[product]/page.tsx
@@ -1,8 +1,64 @@
+import { ProductLink } from "@/components/ui/product-card";
+import { getProductDetails, getRelatedProducts } from "@/db/utils";
+import { notFound } from "next/navigation";
+
export default async function Page(props: {
params: Promise<{
product: string;
+ subcategory: string;
+ category: string;
}>;
}) {
- const { product } = await props.params;
- return <>{product}>;
+ const { product, subcategory, category } = await props.params;
+ const urlDecodedProduct = decodeURIComponent(product);
+ const urlDecodedSubcategory = decodeURIComponent(subcategory);
+ const urlDecodedCategory = decodeURIComponent(category);
+ const productData = getProductDetails({
+ category: urlDecodedCategory,
+ subcategory: urlDecodedSubcategory,
+ product: urlDecodedProduct,
+ });
+ const related = getRelatedProducts({
+ category: urlDecodedCategory,
+ subcategory: urlDecodedSubcategory,
+ product: urlDecodedProduct,
+ });
+ if (!productData) {
+ return notFound();
+ }
+ return (
+
+
+ {productData?.name}
+
+
+
+
+
{productData?.description}
+
+
+
+
+
+ Explore more products
+
+
+ {related?.map((item) => (
+
+ ))}
+
+
+
+ );
}
diff --git a/src/app/products/[category]/[subcategory]/page.tsx b/src/app/products/[category]/[subcategory]/page.tsx
index dddbbb6..55231c9 100644
--- a/src/app/products/[category]/[subcategory]/page.tsx
+++ b/src/app/products/[category]/[subcategory]/page.tsx
@@ -1,7 +1,6 @@
-import Link from "next/link";
-import Image from "next/image";
import { notFound } from "next/navigation";
import { getSubcategoryDetails } from "@/db/utils";
+import { ProductLink } from "@/components/ui/product-card";
export default async function Page(props: {
params: Promise<{
@@ -24,27 +23,12 @@ export default async function Page(props: {
690 Products
{sub.products.map((item) => (
-
-
-
-
-
-
- {item.name}
-
-
{item.description}
-
-
+ category={category}
+ subcategory={subcategory}
+ item={item}
+ />
))}
diff --git a/src/components/ui/product-card.tsx b/src/components/ui/product-card.tsx
new file mode 100644
index 0000000..5169707
--- /dev/null
+++ b/src/components/ui/product-card.tsx
@@ -0,0 +1,34 @@
+import Link from "next/link";
+import Image from "next/image";
+export function ProductLink(props: {
+ category: string;
+ subcategory: string;
+ item: {
+ name: string;
+ description: string;
+ };
+}) {
+ const { category, subcategory, item } = props;
+ return (
+
+
+
+
+
+
+ {item.name}
+
+
{item.description}
+
+
+ );
+}
diff --git a/src/db/utils.ts b/src/db/utils.ts
index 5b06c03..7ad886e 100644
--- a/src/db/utils.ts
+++ b/src/db/utils.ts
@@ -37,4 +37,54 @@ export function getAllCategories() {
export function getAllCollections(){
return artSupplies;
+}
+
+export function getProductDetails(input: {
+ category: string;
+ subcategory: string;
+ product: string;
+}){
+ const categoryData = artSupplies.find((c) =>
+ c.categories.find((cat) => cat.categoryName === input.category),
+ );
+ const cat = categoryData?.categories.find(
+ (cat) => cat.categoryName === input.category,
+ );
+ const screwTypes = cat?.categoryItems.find((collection) =>
+ collection.subcategories.find(
+ (sub) => sub.subcategoryName === input.subcategory,
+ ),
+ );
+ const sub = screwTypes?.subcategories.find(
+ (sub) => sub.subcategoryName === input.subcategory,
+ );
+ const product = sub?.products.find(
+ (prod) => prod.name === input.product,
+ );
+ return product;
+}
+
+export function getRelatedProducts(input: {
+ category: string;
+ subcategory: string;
+ product: string;
+}){
+ const categoryData = artSupplies.find((c) =>
+ c.categories.find((cat) => cat.categoryName === input.category),
+ );
+ const cat = categoryData?.categories.find(
+ (cat) => cat.categoryName === input.category,
+ );
+ const screwTypes = cat?.categoryItems.find((collection) =>
+ collection.subcategories.find(
+ (sub) => sub.subcategoryName === input.subcategory,
+ ),
+ );
+ const sub = screwTypes?.subcategories.find(
+ (sub) => sub.subcategoryName === input.subcategory,
+ );
+ const product = sub?.products.find(
+ (prod) => prod.name === input.product,
+ );
+ return sub?.products.filter((prod) => prod.name !== product?.name);
}
\ No newline at end of file