Merge branch 'release-stable' of github.com:KieIO/grocery-vercel-commerce into feature/m3-viewed-product

This commit is contained in:
DatNguyen
2021-10-18 14:38:40 +07:00
53 changed files with 1215 additions and 180 deletions

10
pages/forgot-password.tsx Normal file
View File

@@ -0,0 +1,10 @@
import { FormForgot, Layout } from 'src/components/common'
export default function NotFound() {
return (
<div>
<FormForgot/>
</div>
)
}
NotFound.Layout = Layout

View File

@@ -8,20 +8,23 @@ import { FeaturedProductsCarousel, FreshProducts, HomeBanner, HomeCategories, Ho
import HomeSpice from 'src/components/modules/home/HomeSpice/HomeSpice';
import { FACET } from 'src/utils/constanst.utils';
import { FilterOneVatiant, getFacetIdByName } from 'src/utils/funtion.utils';
import { CODE_FACET_DISCOUNT, CODE_FACET_FEATURED } from 'src/utils/constanst.utils';
import { CODE_FACET_DISCOUNT, CODE_FACET_FEATURED,COLLECTION_SLUG_SPICE } from 'src/utils/constanst.utils';
import { getAllFacetValueIdsByParentCode, getAllFacetValuesForFeatuedProducts, getAllPromies, getFreshFacetId } from 'src/utils/funtion.utils';
import { PromiseWithKey } from 'src/utils/types.utils';
interface Props {
featuredAndDiscountFacetsValue: FacetValue[],
freshProducts: ProductCard[],
featuredProducts: ProductCard[],
collections: Collection[]
veggie: ProductCard[],
featuredAndDiscountFacetsValue: FacetValue[],
freshProducts: ProductCard[],
featuredProducts: ProductCard[],
collections: Collection[]
spiceProducts:ProductCard[]
veggie: ProductCard[],
}
export default function Home({ featuredAndDiscountFacetsValue,
freshProducts, featuredProducts, veggie,
collections }: Props) {
export default function Home({ featuredAndDiscountFacetsValue, veggie,
freshProducts, featuredProducts,
collections,spiceProducts }: Props) {
return (
<>
<HomeBanner />
@@ -30,7 +33,7 @@ export default function Home({ featuredAndDiscountFacetsValue,
<HomeCollection data = {veggie}/>
<FreshProducts data={freshProducts} collections={collections} />
<HomeVideo />
<HomeSpice />
{spiceProducts.length>0 && <HomeSpice data={spiceProducts}/>}
<FeaturedProductsCarousel data={featuredProducts} featuredFacetsValue={featuredAndDiscountFacetsValue} />
<HomeCTA />
<HomeRecipe />
@@ -76,6 +79,7 @@ export async function getStaticProps({
props.freshProducts = []
}
//veggie
const veggieProductvariables: ProductVariables = {
groupByProduct:false
}
@@ -115,16 +119,24 @@ export async function getStaticProps({
})
promisesWithKey.push({ key: 'collections', promise: collectionsPromise, keyResult: 'collections' })
// spiceProducts
const spiceProducts = commerce.getAllProducts({
variables: {
collectionSlug: COLLECTION_SLUG_SPICE,
},
config,
preview,
})
promisesWithKey.push({ key: 'spiceProducts', promise: spiceProducts, keyResult: 'products' })
try {
const promises = getAllPromies(promisesWithKey)
const rs = await Promise.all(promises)
promisesWithKey.map((item, index) => {
props[item.key] = item.keyResult ? FilterOneVatiant(rs[index][item.keyResult]) : rs[index]
return null
})
return {
props,
revalidate: 60,

View File

@@ -3,13 +3,14 @@ import { Collection } from '@commerce/types/collection'
import { Product, ProductCard } from '@commerce/types/product'
import commerce from '@lib/api/commerce'
import { GetStaticPathsContext, GetStaticPropsContext, InferGetStaticPropsType } from 'next'
import { useEffect } from 'react'
import { useEffect, useState } from 'react'
import { Layout, RecipeDetail, RecommendedRecipes, RelevantBlogPosts } from 'src/components/common'
import { useLocalStorage } from 'src/components/hooks/useLocalStorage'
import { ProductInfoDetail, ReleventProducts, ViewedProducts } from 'src/components/modules/product-detail'
import { LOCAL_STORAGE_KEY, MAX_PRODUCT_CAROUSEL, REVALIDATE_TIME } from 'src/utils/constanst.utils'
import { BLOGS_DATA_TEST, INGREDIENT_DATA_TEST, RECIPE_DATA_TEST } from 'src/utils/demo-data'
import { getAllPromies } from 'src/utils/funtion.utils'
import { normalizeProductCard } from '@framework/utils/normalize';
import { PromiseWithKey } from 'src/utils/types.utils'
interface Props {
relevantProducts: ProductCard[],
@@ -17,23 +18,17 @@ interface Props {
collections: Collection[]
}
export default function Slug({ product, relevantProducts, collections }: Props) {
const [viewedProduct,setViewedProduct] = useLocalStorage<Product[]>(LOCAL_STORAGE_KEY.VIEWEDPRODUCT, []);
const [local,setLocal] = useLocalStorage<Product[]>(LOCAL_STORAGE_KEY.VIEWEDPRODUCT, []);
const [viewed, setViewed] = useState<ProductCard[]>([])
useEffect(() => {
// const local = localStorage.getItem(LOCAL_STORAGE_KEY.VIEWEDPRODUCT)
// if(local){
// const oldList:Product[] = JSON.parse(local)
// if(!oldList.find(p => p.id === product.id)){
// localStorage.setItem(LOCAL_STORAGE_KEY.VIEWEDPRODUCT,JSON.stringify([...oldList,product]))
// }
// }else{
// localStorage.setItem(LOCAL_STORAGE_KEY.VIEWEDPRODUCT,JSON.stringify([product]))
// }
if(viewedProduct){
if(!viewedProduct.find(p => p.id === product.id)){
setViewedProduct([...viewedProduct, product])
if(local){
if(!local.find(p => p.id === product.id)){
setLocal([...local, product])
}else{
setViewed(local.filter((p)=>p.id !== product.id).map((p)=>normalizeProductCard(p)))
}
}else{
setViewedProduct([product])
setLocal([product])
}
}, [product])
@@ -42,7 +37,7 @@ export default function Slug({ product, relevantProducts, collections }: Props)
<RecipeDetail ingredients={INGREDIENT_DATA_TEST} />
<RecommendedRecipes data={RECIPE_DATA_TEST} />
<ReleventProducts data={relevantProducts} collections={collections}/>
<ViewedProducts/>
<ViewedProducts data={viewed}/>
<RelevantBlogPosts data={BLOGS_DATA_TEST} title="relevent blog posts" />
</>
}

10
pages/reset-password.tsx Normal file
View File

@@ -0,0 +1,10 @@
import { FormResetPassword, Layout } from 'src/components/common'
export default function NotFound() {
return (
<div>
<FormResetPassword/>
</div>
)
}
NotFound.Layout = Layout