4
0
forked from crowetic/commerce

Added locale to all pages

This commit is contained in:
Luis Alvarez 2020-10-27 04:00:42 -05:00
parent f54f830464
commit c1d0395c4e
7 changed files with 52 additions and 19 deletions

View File

@ -1,4 +1,5 @@
import type { GetStaticPropsContext, InferGetStaticPropsType } from 'next'
import { getConfig } from '@lib/bigcommerce/api'
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'
@ -9,13 +10,15 @@ export async function getStaticProps({
params,
locale,
}: GetStaticPropsContext<{ pages: string[] }>) {
const { pages } = await getAllPages({ preview })
const config = getConfig({ locale })
const { pages } = await getAllPages({ preview, config })
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! }, preview }))
pageItem &&
(await getPage({ variables: { id: pageItem.id! }, config, preview }))
const page = data?.page
if (!page) {

View File

@ -1,10 +1,15 @@
import type { GetStaticPropsContext } from 'next'
import { getConfig } from '@lib/bigcommerce/api'
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({ preview })
export async function getStaticProps({
preview,
locale,
}: GetStaticPropsContext) {
const config = getConfig({ locale })
const { pages } = await getAllPages({ config, preview })
return {
props: { pages },
}

View File

@ -1,4 +1,5 @@
import type { GetStaticPropsContext } from 'next'
import { getConfig } from '@lib/bigcommerce/api'
import getAllPages from '@lib/bigcommerce/api/operations/get-all-pages'
import { Layout } from '@components/core'
import { Button } from '@components/ui'
@ -8,8 +9,12 @@ import usePrice from '@lib/bigcommerce/use-price'
import { CartItem } from '@components/cart'
import { Text } from '@components/ui'
export async function getStaticProps({ preview }: GetStaticPropsContext) {
const { pages } = await getAllPages({ preview })
export async function getStaticProps({
preview,
locale,
}: GetStaticPropsContext) {
const config = getConfig({ locale })
const { pages } = await getAllPages({ config, preview })
return {
props: { pages },
}

View File

@ -1,11 +1,16 @@
import type { GetStaticPropsContext } from 'next'
import { getConfig } from '@lib/bigcommerce/api'
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 })
export async function getStaticProps({
preview,
locale,
}: GetStaticPropsContext) {
const config = getConfig({ locale })
const { pages } = await getAllPages({ config, preview })
return {
props: { pages },
}

View File

@ -1,11 +1,16 @@
import type { GetStaticPropsContext } from 'next'
import { getConfig } from '@lib/bigcommerce/api'
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'
export async function getStaticProps({ preview }: GetStaticPropsContext) {
const { pages } = await getAllPages({ preview })
export async function getStaticProps({
preview,
locale,
}: GetStaticPropsContext) {
const config = getConfig({ locale })
const { pages } = await getAllPages({ config, preview })
return {
props: { pages },
}

View File

@ -2,12 +2,14 @@ import cn from 'classnames'
import type { GetStaticPropsContext, InferGetStaticPropsType } from 'next'
import Link from 'next/link'
import { useRouter } from 'next/router'
import { getConfig } from '@lib/bigcommerce/api'
import getAllPages from '@lib/bigcommerce/api/operations/get-all-pages'
import getSiteInfo from '@lib/bigcommerce/api/operations/get-site-info'
import useSearch from '@lib/bigcommerce/products/use-search'
import { Layout } from '@components/core'
import { ProductCard } from '@components/product'
import { Container, Grid, Skeleton } from '@components/ui'
import useSearch from '@lib/bigcommerce/products/use-search'
import getAllPages from '@lib/bigcommerce/api/operations/get-all-pages'
import getSiteInfo from '@lib/bigcommerce/api/operations/get-site-info'
import rangeMap from '@lib/range-map'
import getSlug from '@utils/get-slug'
import {
@ -17,9 +19,13 @@ import {
useSearchMeta,
} from '@utils/search'
export async function getStaticProps({ preview }: GetStaticPropsContext) {
const { pages } = await getAllPages({ preview })
const { categories, brands } = await getSiteInfo({ preview })
export async function getStaticProps({
preview,
locale,
}: GetStaticPropsContext) {
const config = getConfig({ locale })
const { pages } = await getAllPages({ config, preview })
const { categories, brands } = await getSiteInfo({ config, preview })
return {
props: { pages, categories, brands },

View File

@ -1,4 +1,5 @@
import type { GetStaticPropsContext } from 'next'
import { getConfig } from '@lib/bigcommerce/api'
import getAllPages from '@lib/bigcommerce/api/operations/get-all-pages'
import useWishlist from '@lib/bigcommerce/wishlist/use-wishlist'
import { Layout } from '@components/core'
@ -6,9 +7,12 @@ import { Heart } from '@components/icons'
import { Container, Text } from '@components/ui'
import { WishlistCard } from '@components/wishlist'
export async function getStaticProps({ preview }: GetStaticPropsContext) {
const { pages } = await getAllPages({ preview })
export async function getStaticProps({
preview,
locale,
}: GetStaticPropsContext) {
const config = getConfig({ locale })
const { pages } = await getAllPages({ config, preview })
return {
props: { pages },
}