Improved types and added method for product

This commit is contained in:
Luis Alvarez
2020-10-01 14:53:29 -05:00
parent 2971b4f802
commit fdb306a988
5 changed files with 245 additions and 20 deletions

View File

@@ -1,10 +1,18 @@
import { useRouter } from "next/router";
import { Layout } from "@components/core";
import { ProductView } from "@components/product";
import { GetStaticPropsContext, InferGetStaticPropsType } from 'next';
import { useRouter } from 'next/router';
import getProduct from 'lib/bigcommerce/api/operations/get-product';
import { Layout } from '@components/core';
import { ProductView } from '@components/product';
export async function getStaticProps({
params,
}: GetStaticPropsContext<{ slug: string }>) {
const { product } = await getProduct({ variables: { slug: params!.slug } });
console.log('PRODUCT', product);
export async function getStaticProps() {
const productData = {
title: "T-Shirt",
title: 'T-Shirt',
description: `
Nothing undercover about this tee. Nope. This is the official Bad
Boys tee. Printed in white or black ink on Black, Brown, or Oatmeal.
@@ -13,9 +21,9 @@ export async function getStaticProps() {
run. Printing starts when the drop ends. Reminder: Bad Boys For
Life. Shipping may take 10+ days due to COVID-19.
`,
price: "$50",
colors: ["black", "white", "pink"],
sizes: ["s", "m", "l", "xl", "xxl"],
price: '$50',
colors: ['black', 'white', 'pink'],
sizes: ['s', 'm', 'l', 'xl', 'xxl'],
};
return {
props: {
@@ -28,11 +36,13 @@ export async function getStaticProps() {
export async function getStaticPaths() {
return {
paths: [],
fallback: "unstable_blocking",
fallback: 'unstable_blocking',
};
}
export default function Home({ productData }) {
export default function Home({
productData,
}: InferGetStaticPropsType<typeof getStaticProps>) {
const router = useRouter();
return (
<Layout>