forked from jamstack-cms/jamstack-ecommerce
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request jamstack-cms#2 from joeynimu/feature-index-and-cat…
…egories-pages added backend for index/home and categories pages
- Loading branch information
Showing
5 changed files
with
131 additions
and
112 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import Head from "next/head" | ||
import { titleIfy, slugify } from "../utils/helpers" | ||
import { DisplayMedium } from "../components" | ||
import CartLink from "../components/CartLink" | ||
import prisma from "../lib/prisma-client" | ||
import { FC } from "react" | ||
import { Category, Product } from "@prisma/client" | ||
|
||
type categoryType = Category & { | ||
products: Product[] | ||
} | ||
|
||
type Props = { | ||
categories: categoryType[] | ||
} | ||
|
||
const Categories: FC<Props> = ({ categories = [] }) => { | ||
return ( | ||
<> | ||
<div className="w-full"> | ||
<CartLink /> | ||
<Head> | ||
<title>Jamstack ECommerce - All Categories</title> | ||
<meta | ||
name="description" | ||
content={`Jamstack ECommerce - All categories`} | ||
/> | ||
<meta | ||
property="og:title" | ||
content="Jamstack ECommerce - All Categories" | ||
key="title" | ||
/> | ||
</Head> | ||
<div className="pt-4 pb-8 sm:pt-10"> | ||
<h1 className="text-5xl font-light">All categories</h1> | ||
</div> | ||
<div className="flex flex-col items-center"> | ||
{/* <div className="flex flex-col justify-between my-4 lg:my-8 lg:flex-row"> */} | ||
<div className="grid grid-cols-1 gap-4 lg:grid-cols-3 md:grid-cols-2"> | ||
{categories.map((category, index) => ( | ||
<DisplayMedium | ||
key={index} | ||
imageSrc={category.image} | ||
subtitle={`${category.products.length} items`} | ||
title={titleIfy(category.name)} | ||
link={`/category/${slugify(category.name)}`} | ||
/> | ||
))} | ||
</div> | ||
</div> | ||
</div> | ||
</> | ||
) | ||
} | ||
|
||
export async function getStaticProps() { | ||
const categories = await prisma.category.findMany({ | ||
include: { | ||
products: true, | ||
}, | ||
}) | ||
|
||
return { | ||
props: { | ||
categories, | ||
}, | ||
} | ||
} | ||
|
||
export default Categories |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters