forked from crowetic/commerce
Add preview where applicable
This commit is contained in:
parent
3e7b1f833f
commit
c9b4a9ad4c
@ -71,6 +71,7 @@ export type ProductVariables = { field?: ProductTypes } & Omit<
|
||||
async function getAllProducts(opts?: {
|
||||
variables?: ProductVariables
|
||||
config?: BigcommerceConfig
|
||||
preview?: boolean
|
||||
}): Promise<GetAllProductsResult>
|
||||
|
||||
async function getAllProducts<
|
||||
@ -80,6 +81,7 @@ async function getAllProducts<
|
||||
query: string
|
||||
variables?: V
|
||||
config?: BigcommerceConfig
|
||||
preview?: boolean
|
||||
}): Promise<GetAllProductsResult<T>>
|
||||
|
||||
async function getAllProducts({
|
||||
@ -90,6 +92,7 @@ async function getAllProducts({
|
||||
query?: string
|
||||
variables?: ProductVariables
|
||||
config?: BigcommerceConfig
|
||||
preview?: boolean
|
||||
} = {}): Promise<GetAllProductsResult> {
|
||||
config = getConfig(config)
|
||||
|
||||
|
@ -15,7 +15,6 @@ export type GetCustomerWishlistVariables = {
|
||||
async function getCustomerWishlist(opts: {
|
||||
variables: GetCustomerWishlistVariables
|
||||
config?: BigcommerceConfig
|
||||
preview?: boolean
|
||||
}): Promise<GetCustomerWishlistResult>
|
||||
|
||||
async function getCustomerWishlist<
|
||||
@ -25,7 +24,6 @@ async function getCustomerWishlist<
|
||||
url: string
|
||||
variables: V
|
||||
config?: BigcommerceConfig
|
||||
preview?: boolean
|
||||
}): Promise<GetCustomerWishlistResult<T>>
|
||||
|
||||
async function getCustomerWishlist({
|
||||
@ -35,7 +33,6 @@ async function getCustomerWishlist({
|
||||
url?: string
|
||||
variables: GetCustomerWishlistVariables
|
||||
config?: BigcommerceConfig
|
||||
preview?: boolean
|
||||
}): Promise<GetCustomerWishlistResult> {
|
||||
config = getConfig(config)
|
||||
|
||||
|
@ -74,12 +74,14 @@ export type ProductVariables = { locale?: string } & (
|
||||
async function getProduct(opts: {
|
||||
variables: ProductVariables
|
||||
config?: BigcommerceConfig
|
||||
preview?: boolean
|
||||
}): Promise<GetProductResult>
|
||||
|
||||
async function getProduct<T extends { product?: any }, V = any>(opts: {
|
||||
query: string
|
||||
variables: V
|
||||
config?: BigcommerceConfig
|
||||
preview?: boolean
|
||||
}): Promise<GetProductResult<T>>
|
||||
|
||||
async function getProduct({
|
||||
@ -90,6 +92,7 @@ async function getProduct({
|
||||
query?: string
|
||||
variables: ProductVariables
|
||||
config?: BigcommerceConfig
|
||||
preview?: boolean
|
||||
}): Promise<GetProductResult> {
|
||||
config = getConfig(config)
|
||||
|
||||
|
@ -64,6 +64,7 @@ export type GetSiteInfoResult<
|
||||
async function getSiteInfo(opts?: {
|
||||
variables?: GetSiteInfoQueryVariables
|
||||
config?: BigcommerceConfig
|
||||
preview?: boolean
|
||||
}): Promise<GetSiteInfoResult>
|
||||
|
||||
async function getSiteInfo<
|
||||
@ -73,6 +74,7 @@ async function getSiteInfo<
|
||||
query: string
|
||||
variables?: V
|
||||
config?: BigcommerceConfig
|
||||
preview?: boolean
|
||||
}): Promise<GetSiteInfoResult<T>>
|
||||
|
||||
async function getSiteInfo({
|
||||
@ -83,6 +85,7 @@ async function getSiteInfo({
|
||||
query?: string
|
||||
variables?: GetSiteInfoQueryVariables
|
||||
config?: BigcommerceConfig
|
||||
preview?: boolean
|
||||
} = {}): Promise<GetSiteInfoResult> {
|
||||
config = getConfig(config)
|
||||
// RecursivePartial forces the method to check for every prop in the data, which is
|
||||
|
@ -1,7 +1,7 @@
|
||||
import { GetStaticPropsContext, InferGetStaticPropsType } from 'next'
|
||||
import getSlug from '@utils/get-slug'
|
||||
import type { GetStaticPropsContext, InferGetStaticPropsType } from 'next'
|
||||
import getPage from '@lib/bigcommerce/api/operations/get-page'
|
||||
import getAllPages from '@lib/bigcommerce/api/operations/get-all-pages'
|
||||
import getSlug from '@utils/get-slug'
|
||||
import { Layout, HTMLContent } from '@components/core'
|
||||
|
||||
export async function getStaticProps({
|
||||
@ -9,12 +9,13 @@ export async function getStaticProps({
|
||||
params,
|
||||
locale,
|
||||
}: GetStaticPropsContext<{ pages: string[] }>) {
|
||||
const { pages } = await getAllPages()
|
||||
const { pages } = await getAllPages({ preview })
|
||||
const path = params?.pages.join('/')
|
||||
const slug = locale ? `${locale}/${path}` : path
|
||||
|
||||
const pageItem = pages.find((p) => (p.url ? getSlug(p.url) === slug : false))
|
||||
const data = pageItem && (await getPage({ variables: { id: pageItem.id! } }))
|
||||
const data =
|
||||
pageItem && (await getPage({ variables: { id: pageItem.id! }, preview }))
|
||||
const page = data?.page
|
||||
|
||||
if (!page) {
|
||||
|
@ -1,18 +1,16 @@
|
||||
import { GetStaticPropsContext, InferGetStaticPropsType } from 'next'
|
||||
import type { GetStaticPropsContext } from 'next'
|
||||
import getAllPages from '@lib/bigcommerce/api/operations/get-all-pages'
|
||||
import { Layout } from '@components/core'
|
||||
import { Container } from '@components/ui'
|
||||
|
||||
export async function getStaticProps({ preview }: GetStaticPropsContext) {
|
||||
const { pages } = await getAllPages()
|
||||
const { pages } = await getAllPages({ preview })
|
||||
return {
|
||||
props: { pages },
|
||||
}
|
||||
}
|
||||
|
||||
export default function Blog({}: InferGetStaticPropsType<
|
||||
typeof getStaticProps
|
||||
>) {
|
||||
export default function Blog() {
|
||||
return (
|
||||
<div className="pb-20">
|
||||
<div className="text-center pt-40 pb-56 bg-violet">
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { GetStaticPropsContext, InferGetStaticPropsType } from 'next'
|
||||
import type { GetStaticPropsContext } from 'next'
|
||||
import getAllPages from '@lib/bigcommerce/api/operations/get-all-pages'
|
||||
import { Layout } from '@components/core'
|
||||
import { Button } from '@components/ui'
|
||||
@ -9,15 +9,13 @@ import { CartItem } from '@components/cart'
|
||||
import { Text } from '@components/ui'
|
||||
|
||||
export async function getStaticProps({ preview }: GetStaticPropsContext) {
|
||||
const { pages } = await getAllPages()
|
||||
const { pages } = await getAllPages({ preview })
|
||||
return {
|
||||
props: { pages },
|
||||
}
|
||||
}
|
||||
|
||||
export default function Cart({}: InferGetStaticPropsType<
|
||||
typeof getStaticProps
|
||||
>) {
|
||||
export default function Cart() {
|
||||
const { data, isEmpty } = useCart()
|
||||
const { price: subTotal } = usePrice(
|
||||
data && {
|
||||
|
@ -1,5 +1,5 @@
|
||||
import { useMemo } from 'react'
|
||||
import { GetStaticPropsContext, InferGetStaticPropsType } from 'next'
|
||||
import type { GetStaticPropsContext, InferGetStaticPropsType } from 'next'
|
||||
import { getConfig } from '@lib/bigcommerce/api'
|
||||
import getAllProducts from '@lib/bigcommerce/api/operations/get-all-products'
|
||||
import getSiteInfo from '@lib/bigcommerce/api/operations/get-site-info'
|
||||
@ -19,17 +19,20 @@ export async function getStaticProps({
|
||||
const { products: featuredProducts } = await getAllProducts({
|
||||
variables: { field: 'featuredProducts', first: 6 },
|
||||
config,
|
||||
preview,
|
||||
})
|
||||
const { products: bestSellingProducts } = await getAllProducts({
|
||||
variables: { field: 'bestSellingProducts', first: 6 },
|
||||
config,
|
||||
preview,
|
||||
})
|
||||
const { products: newestProducts } = await getAllProducts({
|
||||
variables: { field: 'newestProducts', first: 12 },
|
||||
config,
|
||||
preview,
|
||||
})
|
||||
const { categories, brands } = await getSiteInfo({ config })
|
||||
const { pages } = await getAllPages({ config })
|
||||
const { categories, brands } = await getSiteInfo({ config, preview })
|
||||
const { pages } = await getAllPages({ config, preview })
|
||||
|
||||
return {
|
||||
props: {
|
||||
|
@ -1,6 +1,16 @@
|
||||
import type { GetStaticPropsContext } from 'next'
|
||||
import getAllPages from '@lib/bigcommerce/api/operations/get-all-pages'
|
||||
import { Layout } from '@components/core'
|
||||
import { Container, Text } from '@components/ui'
|
||||
import { Bag } from '@components/icons'
|
||||
|
||||
export async function getStaticProps({ preview }: GetStaticPropsContext) {
|
||||
const { pages } = await getAllPages({ preview })
|
||||
return {
|
||||
props: { pages },
|
||||
}
|
||||
}
|
||||
|
||||
export default function Orders() {
|
||||
return (
|
||||
<Container>
|
||||
|
@ -1,4 +1,4 @@
|
||||
import {
|
||||
import type {
|
||||
GetStaticPathsContext,
|
||||
GetStaticPropsContext,
|
||||
InferGetStaticPropsType,
|
||||
@ -14,13 +14,15 @@ import getAllProductPaths from '@lib/bigcommerce/api/operations/get-all-product-
|
||||
export async function getStaticProps({
|
||||
params,
|
||||
locale,
|
||||
preview,
|
||||
}: GetStaticPropsContext<{ slug: string }>) {
|
||||
const config = getConfig({ locale })
|
||||
|
||||
const { pages } = await getAllPages({ config })
|
||||
const { pages } = await getAllPages({ config, preview })
|
||||
const { product } = await getProduct({
|
||||
variables: { slug: params!.slug },
|
||||
config,
|
||||
preview,
|
||||
})
|
||||
|
||||
if (!product) {
|
||||
|
@ -1,6 +1,15 @@
|
||||
import type { GetStaticPropsContext } from 'next'
|
||||
import getAllPages from '@lib/bigcommerce/api/operations/get-all-pages'
|
||||
import useCustomer from '@lib/bigcommerce/use-customer'
|
||||
import { Layout } from '@components/core'
|
||||
import { Container, Text } from '@components/ui'
|
||||
import useCustomer from '@lib/bigcommerce/use-customer'
|
||||
|
||||
export async function getStaticProps({ preview }: GetStaticPropsContext) {
|
||||
const { pages } = await getAllPages({ preview })
|
||||
return {
|
||||
props: { pages },
|
||||
}
|
||||
}
|
||||
|
||||
export default function Profile() {
|
||||
const { data } = useCustomer()
|
||||
|
@ -18,8 +18,8 @@ import {
|
||||
} from '@utils/search'
|
||||
|
||||
export async function getStaticProps({ preview }: GetStaticPropsContext) {
|
||||
const { pages } = await getAllPages()
|
||||
const { categories, brands } = await getSiteInfo()
|
||||
const { pages } = await getAllPages({ preview })
|
||||
const { categories, brands } = await getSiteInfo({ preview })
|
||||
|
||||
return {
|
||||
props: { pages, categories, brands },
|
||||
|
11
pages/ui.tsx
11
pages/ui.tsx
@ -1,11 +0,0 @@
|
||||
import { Layout } from '@components/core'
|
||||
import { Container, Skeleton } from '@components/ui'
|
||||
export default function Search() {
|
||||
return (
|
||||
<Container>
|
||||
<Skeleton className="w-64 h-12 rounded-md" />
|
||||
</Container>
|
||||
)
|
||||
}
|
||||
|
||||
Search.Layout = Layout
|
@ -1,15 +1,15 @@
|
||||
import { GetStaticPropsContext, InferGetStaticPropsType } from 'next'
|
||||
import type { GetStaticPropsContext, InferGetStaticPropsType } from 'next'
|
||||
import getAllPages from '@lib/bigcommerce/api/operations/get-all-pages'
|
||||
import useWishlist from '@lib/bigcommerce/wishlist/use-wishlist'
|
||||
import { Layout } from '@components/core'
|
||||
import { Container, Text } from '@components/ui'
|
||||
import { WishlistCard } from '@components/wishlist'
|
||||
|
||||
import getSiteInfo from '@lib/bigcommerce/api/operations/get-site-info'
|
||||
import useWishlist from '@lib/bigcommerce/wishlist/use-wishlist'
|
||||
|
||||
export async function getStaticProps({ preview }: GetStaticPropsContext) {
|
||||
const { pages } = await getAllPages()
|
||||
const { categories, brands } = await getSiteInfo()
|
||||
const { pages } = await getAllPages({ preview })
|
||||
const { categories, brands } = await getSiteInfo({ preview })
|
||||
|
||||
return {
|
||||
props: { pages, categories, brands },
|
||||
@ -20,7 +20,7 @@ export default function Home({
|
||||
categories,
|
||||
brands,
|
||||
}: InferGetStaticPropsType<typeof getStaticProps>) {
|
||||
// const { data } = useWishlist()
|
||||
const { data } = useWishlist()
|
||||
return (
|
||||
<Container>
|
||||
<div className="grid grid-cols-12 gap-8 mt-3 mb-20">
|
||||
|
Loading…
x
Reference in New Issue
Block a user