mirror of
https://github.com/vercel/commerce.git
synced 2025-07-23 04:36:49 +00:00
Merge pull request #71 from KieIO/feature/m1-get-all-collections-fix
bug: fix bug useGetAllCollection
This commit is contained in:
@@ -19,3 +19,13 @@ export const getCollectionsQuery = /* GraphQL */ `
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
`
|
`
|
||||||
|
export const getCollectionsNameQuery = /* GraphQL */ `
|
||||||
|
query getCollections {
|
||||||
|
collections{
|
||||||
|
items{
|
||||||
|
name
|
||||||
|
link:slug
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
`
|
@@ -3,6 +3,7 @@ import Link from 'next/link'
|
|||||||
import { useRouter } from 'next/router'
|
import { useRouter } from 'next/router'
|
||||||
import { memo } from 'react'
|
import { memo } from 'react'
|
||||||
import MenuDropdown from 'src/components/common/MenuDropdown/MenuDropdown'
|
import MenuDropdown from 'src/components/common/MenuDropdown/MenuDropdown'
|
||||||
|
import { useGetAllCollection } from 'src/components/hooks/collection'
|
||||||
import { ProductFeature, QUERY_KEY, ROUTE } from 'src/utils/constanst.utils'
|
import { ProductFeature, QUERY_KEY, ROUTE } from 'src/utils/constanst.utils'
|
||||||
import HeaderNoti from './HeaderNoti/HeaderNoti'
|
import HeaderNoti from './HeaderNoti/HeaderNoti'
|
||||||
import s from './HeaderSubMenu.module.scss'
|
import s from './HeaderSubMenu.module.scss'
|
||||||
@@ -30,39 +31,18 @@ const MENU = [
|
|||||||
},
|
},
|
||||||
]
|
]
|
||||||
|
|
||||||
// note: hard code, remove later
|
|
||||||
const CATEGORY = [
|
|
||||||
{
|
|
||||||
name: 'Veggie',
|
|
||||||
link: `${ROUTE.PRODUCTS}/?${QUERY_KEY.BRAND}=veggie`,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'Seafood',
|
|
||||||
link: `${ROUTE.PRODUCTS}/?${QUERY_KEY.BRAND}=seafood`,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'Frozen',
|
|
||||||
link: `${ROUTE.PRODUCTS}/?${QUERY_KEY.BRAND}=frozen`,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'Coffee Bean',
|
|
||||||
link: `${ROUTE.PRODUCTS}/?${QUERY_KEY.BRAND}=coffee-bean`,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'Sauce',
|
|
||||||
link: `${ROUTE.PRODUCTS}/?${QUERY_KEY.BRAND}=sauce`,
|
|
||||||
},
|
|
||||||
]
|
|
||||||
|
|
||||||
const HeaderSubMenu = memo(() => {
|
const HeaderSubMenu = memo(() => {
|
||||||
const router = useRouter()
|
const router = useRouter()
|
||||||
|
const {collections} = useGetAllCollection();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<section className={s.headerSubMenu}>
|
<section className={s.headerSubMenu}>
|
||||||
<ul className={s.menu}>
|
<ul className={s.menu}>
|
||||||
{/* todo: handle active item */}
|
{/* todo: handle active item */}
|
||||||
<li>
|
<li>
|
||||||
<MenuDropdown options={CATEGORY} align="left">Categories</MenuDropdown>
|
<MenuDropdown options={collections?.items ?? []} align="left">Categories</MenuDropdown>
|
||||||
</li>
|
</li>
|
||||||
{
|
{
|
||||||
MENU.map(item => <li key={item.name}
|
MENU.map(item => <li key={item.name}
|
||||||
|
1
src/components/hooks/collection/index.ts
Normal file
1
src/components/hooks/collection/index.ts
Normal file
@@ -0,0 +1 @@
|
|||||||
|
export {default as useGetAllCollection} from "./useGetAllCollection"
|
12
src/components/hooks/collection/useGetAllCollection.tsx
Normal file
12
src/components/hooks/collection/useGetAllCollection.tsx
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
import { GetCollectionsQuery } from '@framework/schema';
|
||||||
|
import { getCollectionsNameQuery } from '@framework/utils/queries/get-collections-query';
|
||||||
|
import gglFetcher from 'src/utils/gglFetcher';
|
||||||
|
import useSWR from 'swr';
|
||||||
|
|
||||||
|
|
||||||
|
const useGetAllCollection = () => {
|
||||||
|
const { data, ...rest } = useSWR<GetCollectionsQuery>([getCollectionsNameQuery], gglFetcher)
|
||||||
|
return { collections: data?.collections, ...rest }
|
||||||
|
}
|
||||||
|
|
||||||
|
export default useGetAllCollection;
|
Reference in New Issue
Block a user