feat: toggle wishlist

This commit is contained in:
Quangnhankie
2021-10-10 22:06:14 +07:00
parent 1126030abc
commit 391bba5d31
3 changed files with 18 additions and 8 deletions

View File

@@ -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']>

View File

@@ -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} />
})

View File

@@ -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