diff --git a/components/wishlist/WishlistButton/WishlistButton.tsx b/components/wishlist/WishlistButton/WishlistButton.tsx index 31775b566..0c4c20194 100644 --- a/components/wishlist/WishlistButton/WishlistButton.tsx +++ b/components/wishlist/WishlistButton/WishlistButton.tsx @@ -8,7 +8,7 @@ import useCustomer from '@framework/customer/use-customer' import useAddItem from '@framework/wishlist/use-add-item' import useRemoveItem from '@framework/wishlist/use-remove-item' import useWishlist from '@framework/wishlist/use-add-item' -import type { Product } from '@framework/types' + type Props = { productId: Product['id'] variant: ProductVariant diff --git a/framework/bigcommerce/product/use-search.tsx b/framework/bigcommerce/product/use-search.tsx index 0ff767d8a..393a8c0b9 100644 --- a/framework/bigcommerce/product/use-search.tsx +++ b/framework/bigcommerce/product/use-search.tsx @@ -1,5 +1,5 @@ import { HookHandler } from '@commerce/utils/types' -import useSearch, { UseSearch } from '@commerce/product/use-search' +import useSearch, { UseSearch } from '@commerce/products/use-search' import type { SearchProductsData } from '../api/catalog/products' import type { BigcommerceProvider } from '..' diff --git a/framework/commerce/products/use-search.tsx b/framework/commerce/products/use-search.tsx new file mode 100644 index 000000000..1f887f5fe --- /dev/null +++ b/framework/commerce/products/use-search.tsx @@ -0,0 +1,57 @@ +import type { SearchProductsData } from '../types' +import type { + Prop, + HookFetcherFn, + UseHookInput, + UseHookResponse, +} from '../utils/types' +import defaultFetcher from '../utils/default-fetcher' +import useData from '../utils/use-data' +import { Provider, useCommerce } from '..' +import { BigcommerceProvider } from '@framework' + +export type UseSearchHandler
= Prop< + Prop
, + 'useSearch' +> + +export type UseSeachInput
= UseHookInput< + UseSearchHandler
+> + +export type SearchResponse
= UseHookResponse< + UseSearchHandler
+> + +export type UseSearch
= Partial< + UseSeachInput
+> extends UseSeachInput
+ ? (input?: UseSeachInput
) => SearchResponse
+ : (input: UseSeachInput
) => SearchResponse
+
+export const fetcher = defaultFetcher as HookFetcherFn (
+ input: UseSeachInput = {}
+) {
+ const { providerRef, fetcherRef } = useCommerce ()
+
+ const provider = providerRef.current
+ const opts = provider.products?.useSearch
+
+ const fetcherFn = opts?.fetcher ?? fetcher
+ const useHook = opts?.useHook ?? ((ctx) => ctx.useData())
+
+ return useHook({
+ input,
+ useData(ctx) {
+ const response = useData(
+ { ...opts!, fetcher: fetcherFn },
+ ctx?.input ?? [],
+ provider.fetcher ?? fetcherRef.current,
+ ctx?.swrOptions ?? input.swrOptions
+ )
+ return response
+ },
+ })
+}