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<
|
activeCustomer?: Maybe<
|
||||||
{ __typename?: 'Customer' } & Pick<
|
{ __typename?: 'Customer' } & Pick<
|
||||||
Customer,
|
Customer,
|
||||||
'id' | 'firstName' | 'lastName' | 'emailAddress'
|
'id' | 'firstName' | 'lastName' | 'emailAddress' | 'favorites'
|
||||||
>
|
>,
|
||||||
>
|
>
|
||||||
}
|
}
|
||||||
|
export type FavoriteList = {
|
||||||
|
items: [Favorite!]!
|
||||||
|
totalItems: Int!
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
export type GetAllProductPathsQueryVariables = Exact<{
|
export type GetAllProductPathsQueryVariables = Exact<{
|
||||||
first?: Maybe<Scalars['Int']>
|
first?: Maybe<Scalars['Int']>
|
||||||
|
@@ -1,12 +1,13 @@
|
|||||||
import classNames from 'classnames'
|
import classNames from 'classnames'
|
||||||
import { useRouter } from 'next/router'
|
import { useRouter } from 'next/router'
|
||||||
import React from 'react'
|
import React from 'react'
|
||||||
|
import { useActiveCustomer } from 'src/components/hooks/auth'
|
||||||
import { DEFAULT_PAGE_SIZE, ROUTE } from 'src/utils/constanst.utils'
|
import { DEFAULT_PAGE_SIZE, ROUTE } from 'src/utils/constanst.utils'
|
||||||
import { ButtonCommon, EmptyCommon } from '..'
|
import { ButtonCommon, EmptyCommon } from '..'
|
||||||
import PaginationCommon from '../PaginationCommon/PaginationCommon'
|
import PaginationCommon from '../PaginationCommon/PaginationCommon'
|
||||||
import ProductCard, { ProductCardProps } from '../ProductCard/ProductCard'
|
import ProductCard, { ProductCardProps } from '../ProductCard/ProductCard'
|
||||||
import s from "./ProductList.module.scss"
|
import s from "./ProductList.module.scss"
|
||||||
|
import { FavoriteList } from '@framework/schema'
|
||||||
interface ProductListProps {
|
interface ProductListProps {
|
||||||
data: ProductCardProps[],
|
data: ProductCardProps[],
|
||||||
total?: number,
|
total?: number,
|
||||||
@@ -16,6 +17,8 @@ interface ProductListProps {
|
|||||||
|
|
||||||
const ProductList = ({ data, total = data.length, defaultCurrentPage, onPageChange }: ProductListProps) => {
|
const ProductList = ({ data, total = data.length, defaultCurrentPage, onPageChange }: ProductListProps) => {
|
||||||
const router = useRouter()
|
const router = useRouter()
|
||||||
|
const {wishlist:FavoriteList } = useActiveCustomer();
|
||||||
|
|
||||||
const handlePageChange = (page: number) => {
|
const handlePageChange = (page: number) => {
|
||||||
onPageChange && onPageChange(page)
|
onPageChange && onPageChange(page)
|
||||||
}
|
}
|
||||||
@@ -33,8 +36,7 @@ const ProductList = ({ data, total = data.length, defaultCurrentPage, onPageChan
|
|||||||
<div className={s.list}>
|
<div className={s.list}>
|
||||||
{
|
{
|
||||||
data.map((product, index) => {
|
data.map((product, index) => {
|
||||||
console.log(product);
|
|
||||||
|
|
||||||
return <ProductCard {...product} key={index} />
|
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 { activeCustomerQuery } from '@framework/utils/queries/active-customer-query'
|
||||||
import gglFetcher from 'src/utils/gglFetcher'
|
import gglFetcher from 'src/utils/gglFetcher'
|
||||||
import useSWR from 'swr'
|
import useSWR from 'swr'
|
||||||
|
|
||||||
const useActiveCustomer = () => {
|
const useActiveCustomer = () => {
|
||||||
const { data, ...rest } = useSWR<ActiveCustomerQuery>([activeCustomerQuery], gglFetcher)
|
const { data, ...rest } = useSWR<ActiveCustomerQuery>([activeCustomerQuery], gglFetcher)
|
||||||
return { customer: data?.activeCustomer, ...rest }
|
|
||||||
|
return {
|
||||||
|
customer: data?.activeCustomer,
|
||||||
|
wishlist:data?.activeCustomer?.favorites,
|
||||||
|
...rest }
|
||||||
}
|
}
|
||||||
|
|
||||||
export default useActiveCustomer
|
export default useActiveCustomer
|
||||||
|
Reference in New Issue
Block a user