mirror of
https://github.com/vercel/commerce.git
synced 2025-03-14 22:42:33 +00:00
Removed old hook
This commit is contained in:
parent
aab2e7f7cc
commit
25b14007da
@ -1,10 +1,8 @@
|
||||
import { FC } from 'react'
|
||||
import Link from 'next/link'
|
||||
import cn from 'classnames'
|
||||
import type { BigcommerceProvider } from '@framework'
|
||||
import { LineItem } from '@framework/types'
|
||||
import type { LineItem } from '@framework/types'
|
||||
import useCart from '@framework/cart/use-cart'
|
||||
import useFake from '@commerce/cart/use-fake'
|
||||
import useCustomer from '@framework/customer/use-customer'
|
||||
import { Heart, Bag } from '@components/icons'
|
||||
import { useUI } from '@components/ui/context'
|
||||
@ -24,8 +22,6 @@ const UserNav: FC<Props> = ({ className }) => {
|
||||
const { toggleSidebar, closeSidebarIfPresent, openModal } = useUI()
|
||||
const itemsCount = data?.lineItems.reduce(countItem, 0) ?? 0
|
||||
|
||||
const x = useFake<BigcommerceProvider>()
|
||||
|
||||
return (
|
||||
<nav className={cn(s.root, className)}>
|
||||
<div className={s.mainContainer}>
|
||||
|
@ -1,45 +0,0 @@
|
||||
import { useMemo } from 'react'
|
||||
import Cookies from 'js-cookie'
|
||||
import type { Cart } from '../types'
|
||||
import type { HookFetcherFn } from '../utils/types'
|
||||
import useData from '../utils/use-data-2'
|
||||
import { Provider, useCommerce } from '..'
|
||||
|
||||
// Input expected by the `useCart` hook
|
||||
export type CartInput = {
|
||||
cartId?: Cart['id']
|
||||
}
|
||||
|
||||
export type CartResponse<P extends Provider> = ReturnType<
|
||||
NonNullable<NonNullable<NonNullable<P['cart']>['useCart']>['onResponse']>
|
||||
>
|
||||
|
||||
export const fetcher: HookFetcherFn<Cart | null, CartInput> = async ({
|
||||
options,
|
||||
input: { cartId },
|
||||
fetch,
|
||||
normalize,
|
||||
}) => {
|
||||
const data = cartId ? await fetch({ ...options }) : null
|
||||
return data && normalize ? normalize(data) : data
|
||||
}
|
||||
|
||||
export default function useFake<P extends Provider>() {
|
||||
const { providerRef, cartCookie } = useCommerce<P>()
|
||||
|
||||
const provider = providerRef.current
|
||||
const opts = provider.cart?.useCart
|
||||
const options = opts?.fetchOptions ?? {}
|
||||
const fetcherFn = opts?.fetcher ?? fetcher
|
||||
const wrapper: typeof fetcher = (context) => {
|
||||
context.input.cartId = Cookies.get(cartCookie)
|
||||
return fetcherFn(context)
|
||||
}
|
||||
const response = useData(options, [], wrapper, opts?.swrOptions)
|
||||
const memoizedResponse = useMemo(
|
||||
() => (opts?.onResponse ? opts.onResponse(response) : response),
|
||||
[response]
|
||||
)
|
||||
|
||||
return memoizedResponse as CartResponse<P>
|
||||
}
|
@ -1,10 +1,5 @@
|
||||
import useSWR, { ConfigInterface, responseInterface } from 'swr'
|
||||
import type {
|
||||
HookInput,
|
||||
HookFetcher,
|
||||
HookFetcherOptions,
|
||||
HookFetcherFn,
|
||||
} from './types'
|
||||
import type { HookInput, HookFetcher, HookFetcherFn } from './types'
|
||||
import defineProperty from './define-property'
|
||||
import { CommerceError } from './errors'
|
||||
import { HookHandler, useCommerce } from '..'
|
||||
|
Loading…
x
Reference in New Issue
Block a user