mirror of
https://github.com/vercel/commerce.git
synced 2025-07-23 04:36:49 +00:00
✨ feat: featured product sub text
:%s
This commit is contained in:
@@ -1,18 +1,21 @@
|
|||||||
import { ProductCard } from '@commerce/types/product';
|
import { ProductCard } from '@commerce/types/product';
|
||||||
import { ProductVariables } from '@framework/api/operations/get-all-products';
|
import { ProductVariables } from '@framework/api/operations/get-all-products';
|
||||||
|
import { FacetValue } from '@framework/schema';
|
||||||
import commerce from '@lib/api/commerce';
|
import commerce from '@lib/api/commerce';
|
||||||
import { GetStaticPropsContext } from 'next';
|
import { GetStaticPropsContext } from 'next';
|
||||||
import { Layout } from 'src/components/common';
|
import { Layout } from 'src/components/common';
|
||||||
import { FeaturedProductsCarousel, FreshProducts, HomeBanner, HomeCategories, HomeCollection, HomeCTA, HomeFeature, HomeRecipe, HomeSubscribe, HomeVideo } from 'src/components/modules/home';
|
import { FeaturedProductsCarousel, FreshProducts, HomeBanner, HomeCategories, HomeCollection, HomeCTA, HomeFeature, HomeRecipe, HomeSubscribe, HomeVideo } from 'src/components/modules/home';
|
||||||
import HomeSpice from 'src/components/modules/home/HomeSpice/HomeSpice';
|
import HomeSpice from 'src/components/modules/home/HomeSpice/HomeSpice';
|
||||||
import { getAllFeaturedFacetId, getFreshFacetId } from 'src/utils/funtion.utils';
|
import { getAllFeaturedFacetId, getAllFeaturedFacetValue, getFreshFacetId } from 'src/utils/funtion.utils';
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
|
featuredFacetsValue: FacetValue[],
|
||||||
freshProducts: ProductCard[],
|
freshProducts: ProductCard[],
|
||||||
featuredProducts: ProductCard[],
|
featuredProducts: ProductCard[],
|
||||||
|
|
||||||
}
|
}
|
||||||
export default function Home({ freshProducts, featuredProducts }: Props) {
|
export default function Home({ featuredFacetsValue,
|
||||||
|
freshProducts, featuredProducts }: Props) {
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<HomeBanner />
|
<HomeBanner />
|
||||||
@@ -22,7 +25,7 @@ export default function Home({ freshProducts, featuredProducts }: Props) {
|
|||||||
<HomeCollection />
|
<HomeCollection />
|
||||||
<HomeVideo />
|
<HomeVideo />
|
||||||
<HomeSpice />
|
<HomeSpice />
|
||||||
<FeaturedProductsCarousel data={featuredProducts} />
|
<FeaturedProductsCarousel data={featuredProducts} featuredFacetsValue={featuredFacetsValue} />
|
||||||
<HomeCTA />
|
<HomeCTA />
|
||||||
<HomeRecipe />
|
<HomeRecipe />
|
||||||
<HomeSubscribe />
|
<HomeSubscribe />
|
||||||
@@ -45,7 +48,7 @@ export async function getStaticProps({
|
|||||||
config,
|
config,
|
||||||
preview,
|
preview,
|
||||||
})
|
})
|
||||||
|
const featuredFacetsValue = getAllFeaturedFacetValue(facets)
|
||||||
|
|
||||||
const freshProductvariables: ProductVariables = {}
|
const freshProductvariables: ProductVariables = {}
|
||||||
const freshFacetId = getFreshFacetId(facets)
|
const freshFacetId = getFreshFacetId(facets)
|
||||||
@@ -60,7 +63,6 @@ export async function getStaticProps({
|
|||||||
})
|
})
|
||||||
|
|
||||||
const allFeaturedFacetId = getAllFeaturedFacetId(facets)
|
const allFeaturedFacetId = getAllFeaturedFacetId(facets)
|
||||||
console.log("featured** ", allFeaturedFacetId)
|
|
||||||
const featuredProductsPromise = commerce.getAllProducts({
|
const featuredProductsPromise = commerce.getAllProducts({
|
||||||
variables: {
|
variables: {
|
||||||
facetValueIds: allFeaturedFacetId
|
facetValueIds: allFeaturedFacetId
|
||||||
@@ -78,6 +80,7 @@ export async function getStaticProps({
|
|||||||
return {
|
return {
|
||||||
props: {
|
props: {
|
||||||
facets,
|
facets,
|
||||||
|
featuredFacetsValue,
|
||||||
freshProducts: freshFacetId ? rs[0].products : [],
|
freshProducts: freshFacetId ? rs[0].products : [],
|
||||||
featuredProducts: rs[1].products
|
featuredProducts: rs[1].products
|
||||||
},
|
},
|
||||||
|
@@ -21,6 +21,9 @@
|
|||||||
width: 24rem;
|
width: 24rem;
|
||||||
height: 24rem;
|
height: 24rem;
|
||||||
}
|
}
|
||||||
|
img {
|
||||||
|
object-fit: contain;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
.right{
|
.right{
|
||||||
margin-left: 1.2rem;
|
margin-left: 1.2rem;
|
||||||
|
@@ -1,4 +1,5 @@
|
|||||||
import { ProductCard } from '@commerce/types/product'
|
import { ProductCard } from '@commerce/types/product'
|
||||||
|
import { Facet, FacetValue } from '@framework/schema'
|
||||||
import Link from 'next/link'
|
import Link from 'next/link'
|
||||||
import React from 'react'
|
import React from 'react'
|
||||||
import { ROUTE } from 'src/utils/constanst.utils'
|
import { ROUTE } from 'src/utils/constanst.utils'
|
||||||
@@ -8,8 +9,8 @@ import ButtonCommon from '../ButtonCommon/ButtonCommon'
|
|||||||
import ButtonIconBuy from '../ButtonIconBuy/ButtonIconBuy'
|
import ButtonIconBuy from '../ButtonIconBuy/ButtonIconBuy'
|
||||||
import s from './FeaturedProductCard.module.scss'
|
import s from './FeaturedProductCard.module.scss'
|
||||||
export interface FeaturedProductCardProps extends ProductCard {
|
export interface FeaturedProductCardProps extends ProductCard {
|
||||||
buttonText?: string
|
buttonText?: string,
|
||||||
featuredFacetId?: string,
|
subText?: string,
|
||||||
}
|
}
|
||||||
|
|
||||||
const FeaturedProductCard = ({
|
const FeaturedProductCard = ({
|
||||||
@@ -17,9 +18,12 @@ const FeaturedProductCard = ({
|
|||||||
name,
|
name,
|
||||||
slug,
|
slug,
|
||||||
price,
|
price,
|
||||||
|
subText,
|
||||||
currencyCode,
|
currencyCode,
|
||||||
buttonText = LANGUAGE.BUTTON_LABEL.BUY_NOW,
|
buttonText = LANGUAGE.BUTTON_LABEL.BUY_NOW,
|
||||||
}: FeaturedProductCardProps) => {
|
}: FeaturedProductCardProps) => {
|
||||||
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={s.featuredProductCardWarpper}>
|
<div className={s.featuredProductCardWarpper}>
|
||||||
<div className={s.left}>
|
<div className={s.left}>
|
||||||
@@ -36,9 +40,7 @@ const FeaturedProductCard = ({
|
|||||||
<div className={s.title}>{name}</div>
|
<div className={s.title}>{name}</div>
|
||||||
</a>
|
</a>
|
||||||
</Link>
|
</Link>
|
||||||
|
<div className={s.subTitle}>{subText}</div>
|
||||||
{/* TODO: */}
|
|
||||||
{/* <div className={s.subTitle}>{subTitle}</div> */}
|
|
||||||
<div className={s.priceWrapper}>
|
<div className={s.priceWrapper}>
|
||||||
<div className={s.price}>{price} {currencyCode}</div>
|
<div className={s.price}>{price} {currencyCode}</div>
|
||||||
{/* TODO: */}
|
{/* TODO: */}
|
||||||
|
@@ -1,76 +1,89 @@
|
|||||||
import { ProductCard } from '@commerce/types/product'
|
import { FacetValue } from '@framework/schema'
|
||||||
import React from 'react'
|
import React, { useMemo } from 'react'
|
||||||
import { ResponsiveType } from 'react-multi-carousel'
|
import { ResponsiveType } from 'react-multi-carousel'
|
||||||
import { CarouselCommon, FeaturedProductCard,HeadingCommon} from 'src/components/common'
|
import { CarouselCommon, FeaturedProductCard, HeadingCommon } from 'src/components/common'
|
||||||
import { FeaturedProductCardProps } from 'src/components/common/FeaturedProductCard/FeaturedProductCard'
|
import { FeaturedProductCardProps } from 'src/components/common/FeaturedProductCard/FeaturedProductCard'
|
||||||
|
import { getFacetNamesFromIds } from 'src/utils/funtion.utils'
|
||||||
import s from "./FeaturedProductsCarousel.module.scss"
|
import s from "./FeaturedProductsCarousel.module.scss"
|
||||||
interface FeaturedProductsCarouselProps {
|
interface FeaturedProductsCarouselProps {
|
||||||
title?: string,
|
data: FeaturedProductCardProps[]
|
||||||
data: ProductCard[]
|
featuredFacetsValue: FacetValue[],
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const RESPONSIVE: ResponsiveType = {
|
||||||
|
hugeScreen: {
|
||||||
|
breakpoint: { max: 9999, min: 1500 },
|
||||||
|
items: 2.25,
|
||||||
|
slidesToSlide: 1, // optional, default to 1.
|
||||||
|
},
|
||||||
|
largeScreen: {
|
||||||
|
breakpoint: { max: 1500, min: 1440 },
|
||||||
|
items: 2.075,
|
||||||
|
slidesToSlide: 1, // optional, default to 1.
|
||||||
|
},
|
||||||
|
largeDesktop: {
|
||||||
|
breakpoint: { max: 1440, min: 1280 },
|
||||||
|
items: 1.75,
|
||||||
|
slidesToSlide: 1, // optional, default to 1.
|
||||||
|
},
|
||||||
|
desktop: {
|
||||||
|
breakpoint: { max: 1280, min: 1148 },
|
||||||
|
items: 1.5,
|
||||||
|
slidesToSlide: 1, // optional, default to 1.
|
||||||
|
},
|
||||||
|
smallDesktop: {
|
||||||
|
breakpoint: { max: 1148, min: 1024 },
|
||||||
|
items: 1.375,
|
||||||
|
slidesToSlide: 1, // optional, default to 1.
|
||||||
|
},
|
||||||
|
lap: {
|
||||||
|
breakpoint: { max: 1024, min: 968 },
|
||||||
|
items: 1.7,
|
||||||
|
},
|
||||||
|
tablet: {
|
||||||
|
breakpoint: { max: 968, min: 768 },
|
||||||
|
items: 1.075,
|
||||||
|
},
|
||||||
|
smallTablet: {
|
||||||
|
breakpoint: { max: 768, min: 640 },
|
||||||
|
items: 1.25,
|
||||||
|
},
|
||||||
|
largeMobile: {
|
||||||
|
breakpoint: { max: 640, min: 400 },
|
||||||
|
items: 1.275,
|
||||||
|
},
|
||||||
|
mobile: {
|
||||||
|
breakpoint: { max: 400, min: 300 },
|
||||||
|
items: 1.1,
|
||||||
|
},
|
||||||
|
smallMobile: {
|
||||||
|
breakpoint: { max: 300, min: 0 },
|
||||||
|
items: 1,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
const RESPONSIVE: ResponsiveType = {
|
const FeaturedProductsCarousel = ({ data, featuredFacetsValue }: FeaturedProductsCarouselProps) => {
|
||||||
hugeScreen: {
|
const featuredProducts = useMemo(() => {
|
||||||
breakpoint: { max: 9999, min: 1500 },
|
return data.map(item => {
|
||||||
items: 2.25,
|
return {
|
||||||
slidesToSlide: 1, // optional, default to 1.
|
...item,
|
||||||
},
|
subText: getFacetNamesFromIds(featuredFacetsValue, item.facetValueIds)
|
||||||
largeScreen: {
|
}
|
||||||
breakpoint: { max: 1500, min: 1440 },
|
})
|
||||||
items: 2.075,
|
}, [data, featuredFacetsValue])
|
||||||
slidesToSlide: 1, // optional, default to 1.
|
return (
|
||||||
},
|
<div className={s.warpper}>
|
||||||
largeDesktop: {
|
<div className={s.heading}>
|
||||||
breakpoint: { max: 1440, min: 1280 },
|
<HeadingCommon>Featured Products</HeadingCommon>
|
||||||
items: 1.75,
|
</div>
|
||||||
slidesToSlide: 1, // optional, default to 1.
|
<CarouselCommon<FeaturedProductCardProps>
|
||||||
},
|
data={featuredProducts}
|
||||||
desktop: {
|
defaultComponentProps={featuredFacetsValue}
|
||||||
breakpoint: { max: 1280, min: 1148 },
|
Component={FeaturedProductCard}
|
||||||
items: 1.5,
|
itemKey="featured-products"
|
||||||
slidesToSlide: 1, // optional, default to 1.
|
responsive={RESPONSIVE} />
|
||||||
},
|
</div>
|
||||||
smallDesktop: {
|
)
|
||||||
breakpoint: { max: 1148, min: 1024 },
|
|
||||||
items: 1.375,
|
|
||||||
slidesToSlide: 1, // optional, default to 1.
|
|
||||||
},
|
|
||||||
lap: {
|
|
||||||
breakpoint: { max: 1024, min: 968 },
|
|
||||||
items: 1.7,
|
|
||||||
},
|
|
||||||
tablet: {
|
|
||||||
breakpoint: { max: 968, min: 768 },
|
|
||||||
items: 1.075,
|
|
||||||
},
|
|
||||||
smallTablet: {
|
|
||||||
breakpoint: { max: 768, min: 640 },
|
|
||||||
items: 1.25,
|
|
||||||
},
|
|
||||||
largeMobile: {
|
|
||||||
breakpoint: { max: 640, min: 400 },
|
|
||||||
items: 1.275,
|
|
||||||
},
|
|
||||||
mobile: {
|
|
||||||
breakpoint: { max: 400, min: 300 },
|
|
||||||
items: 1.1,
|
|
||||||
},
|
|
||||||
smallMobile: {
|
|
||||||
breakpoint: { max: 300, min: 0 },
|
|
||||||
items: 1,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
const FeaturedProductsCarousel = ({title="Featured Products", data}: FeaturedProductsCarouselProps) => {
|
|
||||||
return (
|
|
||||||
<div className={s.warpper}>
|
|
||||||
<div className={s.heading}>
|
|
||||||
<HeadingCommon>{title}</HeadingCommon>
|
|
||||||
</div>
|
|
||||||
<CarouselCommon<FeaturedProductCardProps> data={data} Component={FeaturedProductCard} itemKey="featured-products" responsive={RESPONSIVE}/>
|
|
||||||
</div>
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export default FeaturedProductsCarousel
|
export default FeaturedProductsCarousel
|
||||||
|
@@ -35,4 +35,19 @@ export function getAllFeaturedFacetId(facets: Facet[]) {
|
|||||||
const rs = featuredFacet?.values.map((item: FacetValue) => item.id)
|
const rs = featuredFacet?.values.map((item: FacetValue) => item.id)
|
||||||
|
|
||||||
return rs
|
return rs
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getAllFeaturedFacetValue(facets: Facet[]) {
|
||||||
|
const featuredFacet = facets.find((item: Facet) => item.code === CODE_FACET_FEATURED)
|
||||||
|
return featuredFacet?.values
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getFacetNamesFromIds(facets: FacetValue[], ids?: string[]): string {
|
||||||
|
if (!ids || ids?.length === 0) {
|
||||||
|
return ''
|
||||||
|
}
|
||||||
|
|
||||||
|
const facetItems = facets.filter((item: FacetValue) => ids.includes(item.id))
|
||||||
|
const names = facetItems.map((item: FacetValue) => item.name)
|
||||||
|
return names.join(", ")
|
||||||
}
|
}
|
Reference in New Issue
Block a user