Fixed remaining issues with types

This commit is contained in:
Luis Alvarez 2021-02-15 12:02:24 -05:00
parent 499516e967
commit bb0b8d2771
8 changed files with 26 additions and 14 deletions

View File

@ -68,7 +68,7 @@ async function getCustomerWishlist({
const productsById = graphqlData.products.reduce<{
[k: number]: ProductEdge
}>((prods, p) => {
prods[p.node.entityId] = p
prods[Number(p.node.entityId)] = p as any
return prods
}, {})
// Populate the wishlist items with the graphql products

View File

@ -3,6 +3,7 @@ import setProductLocaleMeta from '../api/utils/set-product-locale-meta'
import { productInfoFragment } from '../api/fragments/product'
import { BigcommerceConfig, getConfig } from '../api'
import { normalizeProduct } from '@framework/lib/normalize'
import type { Product } from '@commerce/types'
export const getProductQuery = /* GraphQL */ `
query getProduct(

View File

@ -107,7 +107,7 @@ const useWishlist: HookHandler<
const { data: customer } = useCustomer()
const response = useData({
input: [
['customerId', customer?.id],
['customerId', (customer as any)?.id],
['includeProducts', input.includeProducts],
],
swrOptions: {

View File

@ -1,19 +1,23 @@
import { useCallback } from 'react'
import { HookFetcher } from '@commerce/utils/types'
import { CommerceError } from '@commerce/utils/errors'
import useWishlistAddItem from '@commerce/wishlist/use-add-item'
import useWishlistAddItem, {
AddItemInput,
} from '@commerce/wishlist/use-add-item'
import { UseWishlistInput } from '@commerce/wishlist/use-wishlist'
import type { ItemBody, AddItemBody } from '../api/wishlist'
import useCustomer from '../customer/use-customer'
import useWishlist, { UseWishlistOptions, Wishlist } from './use-wishlist'
import useWishlist from './use-wishlist'
import type { BigcommerceProvider } from '..'
const defaultOpts = {
url: '/api/bigcommerce/wishlist',
method: 'POST',
}
export type AddItemInput = ItemBody
// export type AddItemInput = ItemBody
export const fetcher: HookFetcher<Wishlist, AddItemBody> = (
export const fetcher: HookFetcher<any, AddItemBody> = (
options,
{ item },
fetch
@ -27,13 +31,13 @@ export const fetcher: HookFetcher<Wishlist, AddItemBody> = (
}
export function extendHook(customFetcher: typeof fetcher) {
const useAddItem = (opts?: UseWishlistOptions) => {
const useAddItem = (opts?: UseWishlistInput<BigcommerceProvider>) => {
const { data: customer } = useCustomer()
const { revalidate } = useWishlist(opts)
const fn = useWishlistAddItem(defaultOpts, customFetcher)
return useCallback(
async function addItem(input: AddItemInput) {
async function addItem(input: AddItemInput<any>) {
if (!customer) {
// A signed customer is required in order to have a wishlist
throw new CommerceError({

View File

@ -4,7 +4,7 @@ import { CommerceError } from '@commerce/utils/errors'
import useWishlistRemoveItem from '@commerce/wishlist/use-remove-item'
import type { RemoveItemBody } from '../api/wishlist'
import useCustomer from '../customer/use-customer'
import useWishlist, { UseWishlistOptions, Wishlist } from './use-wishlist'
import useWishlist from './use-wishlist'
const defaultOpts = {
url: '/api/bigcommerce/wishlist',
@ -15,7 +15,7 @@ export type RemoveItemInput = {
id: string | number
}
export const fetcher: HookFetcher<Wishlist | null, RemoveItemBody> = (
export const fetcher: HookFetcher<any | null, RemoveItemBody> = (
options,
{ itemId },
fetch
@ -28,10 +28,10 @@ export const fetcher: HookFetcher<Wishlist | null, RemoveItemBody> = (
}
export function extendHook(customFetcher: typeof fetcher) {
const useRemoveItem = (opts?: UseWishlistOptions) => {
const useRemoveItem = (opts?: any) => {
const { data: customer } = useCustomer()
const { revalidate } = useWishlist(opts)
const fn = useWishlistRemoveItem<Wishlist | null, RemoveItemBody>(
const fn = useWishlistRemoveItem<any | null, RemoveItemBody>(
defaultOpts,
customFetcher
)

View File

@ -1,4 +1,11 @@
import useAction from '../utils/use-action'
import type { CartItemBody } from '../types'
// Input expected by the action returned by the `useAddItem` hook
// export interface AddItemInput {
// includeProducts?: boolean
// }
export type AddItemInput<T extends CartItemBody> = T
const useAddItem = useAction

View File

@ -61,7 +61,7 @@ export default function Slug({
return router.isFallback ? (
<h1>Loading...</h1> // TODO (BC) Add Skeleton Views
) : (
<ProductView product={product} />
<ProductView product={product as any} />
)
}

View File

@ -44,7 +44,7 @@ export default function Wishlist() {
) : (
data &&
data.items?.map((item) => (
<WishlistCard key={item.id} item={item} />
<WishlistCard key={item.id} product={item as any} />
))
)}
</div>