mirror of
https://github.com/vercel/commerce.git
synced 2025-07-26 19:51:23 +00:00
Moved auth & cart hooks + several fixes
This commit is contained in:
@@ -11,7 +11,7 @@ const getAllCollections = async (options?: {
|
||||
config = getConfig(config)
|
||||
|
||||
const { data } = await config.fetch(getAllCollectionsQuery, { variables })
|
||||
const edges = data?.collections?.edges ?? []
|
||||
const edges = data.collections?.edges ?? []
|
||||
|
||||
const categories = edges.map(
|
||||
({ node: { id: entityId, title: name, handle } }: CollectionEdge) => ({
|
||||
|
@@ -28,7 +28,7 @@ const getAllProducts = async (options: {
|
||||
{ variables }
|
||||
)
|
||||
|
||||
const products = data?.products?.edges?.map(({ node: p }: ProductEdge) =>
|
||||
const products = data.products?.edges?.map(({ node: p }: ProductEdge) =>
|
||||
normalizeProduct(p)
|
||||
)
|
||||
|
||||
|
@@ -27,7 +27,7 @@ const getProduct = async (options: {
|
||||
variables,
|
||||
})
|
||||
|
||||
const product = data?.productByHandle
|
||||
const { productByHandle: product } = data
|
||||
|
||||
return {
|
||||
product: product ? normalizeProduct(product) : null,
|
||||
|
@@ -1,6 +1,6 @@
|
||||
import useSearch, { UseSearch } from '@commerce/products/use-search'
|
||||
import { SearchProductsData } from '@commerce/types'
|
||||
import { HookHandler } from '@commerce/utils/types'
|
||||
import { SWRHook } from '@commerce/utils/types'
|
||||
import useSearch, { UseSearch } from '@commerce/product/use-search'
|
||||
|
||||
import { ProductEdge } from '@framework/schema'
|
||||
import {
|
||||
getAllProductsQuery,
|
||||
@@ -9,6 +9,8 @@ import {
|
||||
} from '@framework/utils'
|
||||
import type { ShopifyProvider } from '..'
|
||||
|
||||
import { Product } from '@commerce/types'
|
||||
|
||||
export default useSearch as UseSearch<ShopifyProvider>
|
||||
|
||||
export type SearchProductsInput = {
|
||||
@@ -18,7 +20,11 @@ export type SearchProductsInput = {
|
||||
sort?: string
|
||||
}
|
||||
|
||||
export const handler: HookHandler<
|
||||
export type SearchProductsData = {
|
||||
products: Product[]
|
||||
found: boolean
|
||||
}
|
||||
export const handler: SWRHook<
|
||||
SearchProductsData,
|
||||
SearchProductsInput,
|
||||
SearchProductsInput
|
||||
@@ -38,7 +44,7 @@ export const handler: HookHandler<
|
||||
found: !!edges?.length,
|
||||
}
|
||||
},
|
||||
useHook({ input, useData }) {
|
||||
useHook: ({ useData }) => (input = {}) => {
|
||||
return useData({
|
||||
input: [
|
||||
['search', input.search],
|
||||
|
Reference in New Issue
Block a user