From 5f1c3416125ecb733bf6de6916c11c5b2533289e Mon Sep 17 00:00:00 2001 From: Loan Laux Date: Tue, 30 Mar 2021 20:09:18 +0400 Subject: [PATCH] Add missing empty wishlist hooks Signed-off-by: Loan Laux --- .../wishlist/use-add-item.tsx | 13 ++++++ .../wishlist/use-remove-item.tsx | 17 +++++++ .../wishlist/use-wishlist.tsx | 46 +++++++++++++++++++ 3 files changed, 76 insertions(+) create mode 100644 framework/reactioncommerce/wishlist/use-add-item.tsx create mode 100644 framework/reactioncommerce/wishlist/use-remove-item.tsx create mode 100644 framework/reactioncommerce/wishlist/use-wishlist.tsx diff --git a/framework/reactioncommerce/wishlist/use-add-item.tsx b/framework/reactioncommerce/wishlist/use-add-item.tsx new file mode 100644 index 000000000..75f067c3a --- /dev/null +++ b/framework/reactioncommerce/wishlist/use-add-item.tsx @@ -0,0 +1,13 @@ +import { useCallback } from 'react' + +export function emptyHook() { + const useEmptyHook = async (options = {}) => { + return useCallback(async function () { + return Promise.resolve() + }, []) + } + + return useEmptyHook +} + +export default emptyHook diff --git a/framework/reactioncommerce/wishlist/use-remove-item.tsx b/framework/reactioncommerce/wishlist/use-remove-item.tsx new file mode 100644 index 000000000..a2d3a8a05 --- /dev/null +++ b/framework/reactioncommerce/wishlist/use-remove-item.tsx @@ -0,0 +1,17 @@ +import { useCallback } from 'react' + +type Options = { + includeProducts?: boolean +} + +export function emptyHook(options?: Options) { + const useEmptyHook = async ({ id }: { id: string | number }) => { + return useCallback(async function () { + return Promise.resolve() + }, []) + } + + return useEmptyHook +} + +export default emptyHook diff --git a/framework/reactioncommerce/wishlist/use-wishlist.tsx b/framework/reactioncommerce/wishlist/use-wishlist.tsx new file mode 100644 index 000000000..d2ce9db5b --- /dev/null +++ b/framework/reactioncommerce/wishlist/use-wishlist.tsx @@ -0,0 +1,46 @@ +// TODO: replace this hook and other wishlist hooks with a handler, or remove them if +// Shopify doesn't have a wishlist + +import { HookFetcher } from '@commerce/utils/types' +import { Product } from '../schema' + +const defaultOpts = {} + +export type Wishlist = { + items: [ + { + product_id: number + variant_id: number + id: number + product: Product + } + ] +} + +export interface UseWishlistOptions { + includeProducts?: boolean +} + +export interface UseWishlistInput extends UseWishlistOptions { + customerId?: number +} + +export const fetcher: HookFetcher = () => { + return null +} + +export function extendHook( + customFetcher: typeof fetcher, + // swrOptions?: SwrOptions + swrOptions?: any +) { + const useWishlist = ({ includeProducts }: UseWishlistOptions = {}) => { + return { data: null } + } + + useWishlist.extend = extendHook + + return useWishlist +} + +export default extendHook(fetcher)