Fixes in search hook

This commit is contained in:
Luis Alvarez 2021-05-28 12:56:50 -05:00
parent 874cf9d5b3
commit 7f2a0d903a
3 changed files with 7 additions and 11 deletions

View File

@ -22,9 +22,9 @@ export const handler: SWRHook<SearchProductsHook> = {
if (search) url.searchParams.set('search', search) if (search) url.searchParams.set('search', search)
if (Number.isInteger(categoryId)) if (Number.isInteger(categoryId))
url.searchParams.set('category', String(categoryId)) url.searchParams.set('categoryId', String(categoryId))
if (Number.isInteger(brandId)) if (Number.isInteger(brandId))
url.searchParams.set('brand', String(brandId)) url.searchParams.set('brandId', String(brandId))
if (sort) url.searchParams.set('sort', sort) if (sort) url.searchParams.set('sort', sort)
return fetch({ return fetch({

View File

@ -55,7 +55,10 @@ export type ProductTypes = {
} }
export type SearchProductsHook<T extends ProductTypes = ProductTypes> = { export type SearchProductsHook<T extends ProductTypes = ProductTypes> = {
data: T['product'][] data: {
products: T['product'][]
found: boolean
}
body: T['searchBody'] body: T['searchBody']
input: T['searchBody'] input: T['searchBody']
fetcherInput: T['searchBody'] fetcherInput: T['searchBody']
@ -65,13 +68,7 @@ export type ProductsSchema<T extends ProductTypes = ProductTypes> = {
endpoint: { endpoint: {
options: {} options: {}
handlers: { handlers: {
getProducts: { getProducts: SearchProductsHook<T>
data: {
products: T['product'][]
found: boolean
}
body: SearchProductsHook<T>['body']
}
} }
} }
} }

View File

@ -18,7 +18,6 @@ import {
getDesignerPath, getDesignerPath,
useSearchMeta, useSearchMeta,
} from '@lib/search' } from '@lib/search'
import { Product } from '@commerce/types'
// TODO(bc) Remove this. This should come from the API // TODO(bc) Remove this. This should come from the API
import getSlug from '@lib/get-slug' import getSlug from '@lib/get-slug'