mirror of
https://github.com/vercel/commerce.git
synced 2025-03-14 22:42:33 +00:00
Adding wishlist api
This commit is contained in:
parent
c620355448
commit
4cfa0418dd
@ -5,14 +5,21 @@ import { Grid } from '@components/ui'
|
||||
import { ProductCard } from '@components/product'
|
||||
import s from './HomeAllProductsGrid.module.css'
|
||||
import { getCategoryPath, getDesignerPath } from '@lib/search'
|
||||
import wishlist from '@framework/api/wishlist'
|
||||
|
||||
interface Props {
|
||||
categories?: any
|
||||
brands?: any
|
||||
products?: Product[]
|
||||
wishlist?: boolean
|
||||
}
|
||||
|
||||
const Head: FC<Props> = ({ categories, brands, products = [] }) => {
|
||||
const HomeAllProductsGrid: FC<Props> = ({
|
||||
categories,
|
||||
brands,
|
||||
products = [],
|
||||
wishlist = false,
|
||||
}) => {
|
||||
return (
|
||||
<div className={s.root}>
|
||||
<div className={s.asideWrapper}>
|
||||
@ -58,6 +65,7 @@ const Head: FC<Props> = ({ categories, brands, products = [] }) => {
|
||||
width: 480,
|
||||
height: 480,
|
||||
}}
|
||||
wishlist={wishlist}
|
||||
/>
|
||||
))}
|
||||
</Grid>
|
||||
@ -66,4 +74,4 @@ const Head: FC<Props> = ({ categories, brands, products = [] }) => {
|
||||
)
|
||||
}
|
||||
|
||||
export default Head
|
||||
export default HomeAllProductsGrid
|
||||
|
@ -9,20 +9,20 @@ import { useUI } from '@components/ui/context'
|
||||
import DropdownMenu from './DropdownMenu'
|
||||
import s from './UserNav.module.css'
|
||||
import { Avatar } from '@components/common'
|
||||
import frameworkConfig from '@framework/config.json'
|
||||
import Features from '@commerce/utils/features'
|
||||
|
||||
interface Props {
|
||||
className?: string
|
||||
}
|
||||
|
||||
const countItem = (count: number, item: LineItem) => count + item.quantity
|
||||
const isWishlistEnabled = Features.isEnabled('wishlist')
|
||||
|
||||
const UserNav: FC<Props> = ({ className }) => {
|
||||
const { data } = useCart()
|
||||
const { data: customer } = useCustomer()
|
||||
const { toggleSidebar, closeSidebarIfPresent, openModal } = useUI()
|
||||
const itemsCount = data?.lineItems.reduce(countItem, 0) ?? 0
|
||||
const isWishlistEnabled = !!frameworkConfig.features.wishlist
|
||||
|
||||
return (
|
||||
<nav className={cn(s.root, className)}>
|
||||
|
@ -26,6 +26,8 @@ const SORT = Object.entries({
|
||||
'price-desc': 'Price: High to low',
|
||||
})
|
||||
|
||||
import Features from '@commerce/utils/features'
|
||||
|
||||
import {
|
||||
filterQuery,
|
||||
getCategoryPath,
|
||||
@ -40,14 +42,23 @@ export async function getStaticProps({
|
||||
const config = getConfig({ locale })
|
||||
const { pages } = await getAllPages({ config, preview })
|
||||
const { categories, brands } = await getSiteInfo({ config, preview })
|
||||
const isWishlistEnabled = Features.isEnabled('wishlist')
|
||||
return {
|
||||
props: { pages, categories, brands },
|
||||
props: {
|
||||
pages,
|
||||
categories,
|
||||
brands,
|
||||
commerceFeatures: {
|
||||
wishlist: isWishlistEnabled,
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
export default function Search({
|
||||
categories,
|
||||
brands,
|
||||
commerceFeatures: { wishlist },
|
||||
}: InferGetStaticPropsType<typeof getStaticProps>) {
|
||||
const [activeFilter, setActiveFilter] = useState('')
|
||||
const [toggleFilter, setToggleFilter] = useState(false)
|
||||
@ -337,7 +348,7 @@ export default function Search({
|
||||
|
||||
{data ? (
|
||||
<Grid layout="normal">
|
||||
{data.products.map((product) => (
|
||||
{data.products.map((product: Product) => (
|
||||
<ProductCard
|
||||
variant="simple"
|
||||
key={product.path}
|
||||
@ -347,6 +358,7 @@ export default function Search({
|
||||
width: 480,
|
||||
height: 480,
|
||||
}}
|
||||
wishlist={wishlist}
|
||||
/>
|
||||
))}
|
||||
</Grid>
|
||||
|
@ -11,14 +11,14 @@ import { useCustomer } from '@framework/customer'
|
||||
import { WishlistCard } from '@components/wishlist'
|
||||
import useWishlist from '@framework/wishlist/use-wishlist'
|
||||
import getAllPages from '@framework/common/get-all-pages'
|
||||
import frameworkConfig from '@framework/config.json'
|
||||
import Features from '@commerce/utils/features'
|
||||
|
||||
export async function getStaticProps({
|
||||
preview,
|
||||
locale,
|
||||
}: GetStaticPropsContext) {
|
||||
// Disabling page if Feature is not available
|
||||
if (!frameworkConfig.features.wishlist) {
|
||||
if (Features.isEnabled('wishlist')) {
|
||||
return {
|
||||
notFound: true,
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user