Moved auth & cart hooks + several fixes

This commit is contained in:
cond0r
2021-02-22 14:06:34 +02:00
parent 005fe9d6c9
commit 528d7556a8
53 changed files with 447 additions and 331 deletions

View File

@@ -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) => ({

View File

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

View File

@@ -27,7 +27,7 @@ const getProduct = async (options: {
variables,
})
const product = data?.productByHandle
const { productByHandle: product } = data
return {
product: product ? normalizeProduct(product) : null,

View File

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