mirror of
https://github.com/vercel/commerce.git
synced 2025-07-23 04:36:49 +00:00
feat: toggle wishlist
This commit is contained in:
9
framework/vendure/schema.d.ts
vendored
9
framework/vendure/schema.d.ts
vendored
@@ -3198,10 +3198,15 @@ export type ActiveCustomerQuery = { __typename?: 'Query' } & {
|
||||
activeCustomer?: Maybe<
|
||||
{ __typename?: 'Customer' } & Pick<
|
||||
Customer,
|
||||
'id' | 'firstName' | 'lastName' | 'emailAddress'
|
||||
>
|
||||
'id' | 'firstName' | 'lastName' | 'emailAddress' | 'favorites'
|
||||
>,
|
||||
>
|
||||
}
|
||||
export type FavoriteList = {
|
||||
items: [Favorite!]!
|
||||
totalItems: Int!
|
||||
}
|
||||
|
||||
|
||||
export type GetAllProductPathsQueryVariables = Exact<{
|
||||
first?: Maybe<Scalars['Int']>
|
||||
|
@@ -1,12 +1,13 @@
|
||||
import classNames from 'classnames'
|
||||
import { useRouter } from 'next/router'
|
||||
import React from 'react'
|
||||
import { useActiveCustomer } from 'src/components/hooks/auth'
|
||||
import { DEFAULT_PAGE_SIZE, ROUTE } from 'src/utils/constanst.utils'
|
||||
import { ButtonCommon, EmptyCommon } from '..'
|
||||
import PaginationCommon from '../PaginationCommon/PaginationCommon'
|
||||
import ProductCard, { ProductCardProps } from '../ProductCard/ProductCard'
|
||||
import s from "./ProductList.module.scss"
|
||||
|
||||
import { FavoriteList } from '@framework/schema'
|
||||
interface ProductListProps {
|
||||
data: ProductCardProps[],
|
||||
total?: number,
|
||||
@@ -16,6 +17,8 @@ interface ProductListProps {
|
||||
|
||||
const ProductList = ({ data, total = data.length, defaultCurrentPage, onPageChange }: ProductListProps) => {
|
||||
const router = useRouter()
|
||||
const {wishlist:FavoriteList } = useActiveCustomer();
|
||||
|
||||
const handlePageChange = (page: number) => {
|
||||
onPageChange && onPageChange(page)
|
||||
}
|
||||
@@ -33,7 +36,6 @@ const ProductList = ({ data, total = data.length, defaultCurrentPage, onPageChan
|
||||
<div className={s.list}>
|
||||
{
|
||||
data.map((product, index) => {
|
||||
console.log(product);
|
||||
|
||||
return <ProductCard {...product} key={index} />
|
||||
})
|
||||
|
@@ -1,11 +1,14 @@
|
||||
import { ActiveCustomerQuery } from '@framework/schema'
|
||||
import { ActiveCustomerQuery,FavoriteList } from '@framework/schema'
|
||||
import { activeCustomerQuery } from '@framework/utils/queries/active-customer-query'
|
||||
import gglFetcher from 'src/utils/gglFetcher'
|
||||
import useSWR from 'swr'
|
||||
|
||||
const useActiveCustomer = () => {
|
||||
const { data, ...rest } = useSWR<ActiveCustomerQuery>([activeCustomerQuery], gglFetcher)
|
||||
return { customer: data?.activeCustomer, ...rest }
|
||||
|
||||
return {
|
||||
customer: data?.activeCustomer,
|
||||
wishlist:data?.activeCustomer?.favorites,
|
||||
...rest }
|
||||
}
|
||||
|
||||
export default useActiveCustomer
|
||||
|
Reference in New Issue
Block a user