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