mirror of
https://github.com/vercel/commerce.git
synced 2025-07-22 20:26:49 +00:00
intt: product-collection
This commit is contained in:
20
src/components/hooks/useGetActiveOrder.tsx
Normal file
20
src/components/hooks/useGetActiveOrder.tsx
Normal 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
|
47
src/components/hooks/useGetProductListByCollection.tsx
Normal file
47
src/components/hooks/useGetProductListByCollection.tsx
Normal 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
|
@@ -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
0
src/utils/enum.ts
Normal file
@@ -1,3 +1,5 @@
|
||||
import { SortOrder } from "@framework/schema";
|
||||
|
||||
export interface ProductProps {
|
||||
category?: string
|
||||
name: string
|
||||
|
Reference in New Issue
Block a user