intt: product-collection

This commit is contained in:
DatNguyen 2021-09-30 18:14:14 +07:00
parent 128a9f0537
commit 5ace99922d
5 changed files with 76 additions and 1 deletions

View File

@ -0,0 +1,20 @@
import { ActiveOrderQuery } from '@framework/schema'
import { cartFragment } from '@framework/utils/fragments/cart-fragment'
import { gql } from 'graphql-request'
import gglFetcher from 'src/utils/gglFetcher'
import useSWR from 'swr'
const query = gql`
query activeOrder {
activeOrder {
...Cart
}
}
${ cartFragment }
`
const useGetActiveOrder = () => {
const { data, ...rest } = useSWR<ActiveOrderQuery>([query], gglFetcher)
return { order: data?.activeOrder, ...rest }
}
export default useGetActiveOrder

View File

@ -0,0 +1,47 @@
// import { gql } from 'graphql-request'
import { useMemo, useState } from 'react'
// import useActiveCustomer from './useActiveCustomer'
import { CommonError } from 'src/domains/interfaces/CommonError'
import rawFetcher from 'src/utils/rawFetcher'
import {
CollectionList,
CollectionListOptions,
GetCollectionsQuery,
GetCollectionsQueryVariables,
LoginMutation,
} from '@framework/schema'
import { gql } from 'graphql-request'
import { getCollectionsQuery } from '@framework/utils/queries/get-collections-query'
import useSWR from 'swr'
import gglFetcher from 'src/utils/gglFetcher'
const query = gql`
query getCollections($option: CollectionListOptions) {
collections(options:$option) {
items {
id
name
description
slug
productVariants {
totalItems
}
parent {
id
}
children {
id
}
}
}
}
`
const useGetProductListByCollection = (options: any) => {
const { data, ...rest } = useSWR<GetCollectionsQuery>([query, options], gglFetcher)
return { collections: data?.collections, ...rest }
}
export default useGetProductListByCollection

View File

@ -1,5 +1,7 @@
import React from 'react'
import { CollectionListOptions, GetCollectionsQuery } from '@framework/schema'
import React, { useEffect, useMemo, useState } from 'react'
import { Banner, StaticImage } from 'src/components/common'
import useGetProductListByCollection from 'src/components/hooks/useGetProductListByCollection'
import { ROUTE } from 'src/utils/constanst.utils'
import BannerImgRight from './assets/banner_full.png'
import HomeBannerImg from './assets/home_banner.png'
@ -11,6 +13,10 @@ interface Props {
}
const HomeBanner = ({ }: Props) => {
// const variables = useMemo(() => {
// return {option: {filter: {name: {eq: "Computers" }}}}
// }, [])
// const {collections} = useGetProductListByCollection(variables)
return (
<div className={s.homeBanner}>
<section className={s.left}>

0
src/utils/enum.ts Normal file
View File

View File

@ -1,3 +1,5 @@
import { SortOrder } from "@framework/schema";
export interface ProductProps {
category?: string
name: string