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