forked from crowetic/commerce
Fixed types
This commit is contained in:
parent
46ae76c67f
commit
e90d9a2121
@ -1,7 +1,5 @@
|
|||||||
|
import { Page } from '../../schema'
|
||||||
import { ShopifyConfig, getConfig } from '..'
|
import { ShopifyConfig, getConfig } from '..'
|
||||||
import type { Page } from '../../types'
|
|
||||||
|
|
||||||
export type { Page }
|
|
||||||
|
|
||||||
export type GetPageResult<T extends { page?: any } = { page?: Page }> = T
|
export type GetPageResult<T extends { page?: any } = { page?: Page }> = T
|
||||||
|
|
||||||
|
@ -40,7 +40,8 @@ export const handler: MutationHook<Cart, {}, CartItemBody> = {
|
|||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
return checkoutToCart(checkoutLineItemsAdd)
|
// TODO: Fix this Cart type here
|
||||||
|
return checkoutToCart(checkoutLineItemsAdd) as any
|
||||||
},
|
},
|
||||||
useHook: ({ fetch }) => () => {
|
useHook: ({ fetch }) => () => {
|
||||||
const { mutate } = useCart()
|
const { mutate } = useCart()
|
||||||
|
@ -1,6 +1,4 @@
|
|||||||
import { useMemo } from 'react'
|
import { useMemo } from 'react'
|
||||||
import type { ShopifyProvider } from '..'
|
|
||||||
|
|
||||||
import useCommerceCart, {
|
import useCommerceCart, {
|
||||||
FetchCartInput,
|
FetchCartInput,
|
||||||
UseCart,
|
UseCart,
|
||||||
@ -11,7 +9,7 @@ import { SWRHook } from '@commerce/utils/types'
|
|||||||
import { checkoutCreate, checkoutToCart } from './utils'
|
import { checkoutCreate, checkoutToCart } from './utils'
|
||||||
import getCheckoutQuery from '../utils/queries/get-checkout-query'
|
import getCheckoutQuery from '../utils/queries/get-checkout-query'
|
||||||
|
|
||||||
export default useCommerceCart as UseCart<ShopifyProvider>
|
export default useCommerceCart as UseCart<typeof handler>
|
||||||
|
|
||||||
export const handler: SWRHook<
|
export const handler: SWRHook<
|
||||||
Cart | null,
|
Cart | null,
|
||||||
@ -38,7 +36,8 @@ export const handler: SWRHook<
|
|||||||
checkout = await checkoutCreate(fetch)
|
checkout = await checkoutCreate(fetch)
|
||||||
}
|
}
|
||||||
|
|
||||||
return checkoutToCart({ checkout })
|
// TODO: Fix this type
|
||||||
|
return checkoutToCart({ checkout } as any)
|
||||||
},
|
},
|
||||||
useHook: ({ useData }) => (input) => {
|
useHook: ({ useData }) => (input) => {
|
||||||
const response = useData({
|
const response = useData({
|
||||||
|
@ -24,7 +24,8 @@ const fetcher: HookFetcherFn<Cart | null, FetchCartInput> = async ({
|
|||||||
checkout = await checkoutCreate(fetch)
|
checkout = await checkoutCreate(fetch)
|
||||||
}
|
}
|
||||||
|
|
||||||
return checkoutToCart({ checkout })
|
// TODO: Fix this type
|
||||||
|
return checkoutToCart({ checkout } as any)
|
||||||
}
|
}
|
||||||
|
|
||||||
export default fetcher
|
export default fetcher
|
||||||
|
@ -2,9 +2,9 @@ import useCustomer, { UseCustomer } from '@commerce/customer/use-customer'
|
|||||||
import { Customer } from '@commerce/types'
|
import { Customer } from '@commerce/types'
|
||||||
import { SWRHook } from '@commerce/utils/types'
|
import { SWRHook } from '@commerce/utils/types'
|
||||||
import { getCustomerQuery, getCustomerToken } from '../utils'
|
import { getCustomerQuery, getCustomerToken } from '../utils'
|
||||||
import type { ShopifyProvider } from '..'
|
|
||||||
|
|
||||||
export default useCustomer as UseCustomer<ShopifyProvider>
|
export default useCustomer as UseCustomer<typeof handler>
|
||||||
|
|
||||||
export const handler: SWRHook<Customer | null> = {
|
export const handler: SWRHook<Customer | null> = {
|
||||||
fetchOptions: {
|
fetchOptions: {
|
||||||
query: getCustomerQuery,
|
query: getCustomerQuery,
|
||||||
|
@ -30,9 +30,6 @@ export type CartItemBody = Core.CartItemBody & {
|
|||||||
optionSelections?: OptionSelections
|
optionSelections?: OptionSelections
|
||||||
}
|
}
|
||||||
|
|
||||||
type X = Core.CartItemBody extends CartItemBody ? any : never
|
|
||||||
type Y = CartItemBody extends Core.CartItemBody ? any : never
|
|
||||||
|
|
||||||
export type GetCartHandlerBody = Core.GetCartHandlerBody
|
export type GetCartHandlerBody = Core.GetCartHandlerBody
|
||||||
|
|
||||||
export type AddCartItemBody = Core.AddCartItemBody<CartItemBody>
|
export type AddCartItemBody = Core.AddCartItemBody<CartItemBody>
|
||||||
|
@ -1,4 +1,8 @@
|
|||||||
import { Product, Image } from '../types'
|
// TODO: Fix the types in this file
|
||||||
|
// import { Product, Image } from '../types'
|
||||||
|
|
||||||
|
type Product = any
|
||||||
|
type Image = any
|
||||||
|
|
||||||
export default function toCommerceProducts(products: Product[]) {
|
export default function toCommerceProducts(products: Product[]) {
|
||||||
return products.map((product: Product) => {
|
return products.map((product: Product) => {
|
||||||
@ -20,10 +24,12 @@ export default function toCommerceProducts(products: Product[]) {
|
|||||||
url: image.src,
|
url: image.src,
|
||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
variants: product.variants.map((variant) => {
|
// TODO: Fix the variant type
|
||||||
|
variants: product.variants.map((variant: any) => {
|
||||||
return {
|
return {
|
||||||
id: variant.id,
|
id: variant.id,
|
||||||
options: variant.selectedOptions.map((selectedOption) => {
|
// TODO: Fix the selectedOption type
|
||||||
|
options: variant.selectedOptions.map((selectedOption: any) => {
|
||||||
return {
|
return {
|
||||||
__typename: 'MultipleChoiceOption',
|
__typename: 'MultipleChoiceOption',
|
||||||
displayName: selectedOption.name,
|
displayName: selectedOption.name,
|
||||||
@ -39,11 +45,13 @@ export default function toCommerceProducts(products: Product[]) {
|
|||||||
}),
|
}),
|
||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
productOptions: product.options.map((option) => {
|
// TODO: Fix the option type
|
||||||
|
productOptions: product.options.map((option: any) => {
|
||||||
return {
|
return {
|
||||||
__typename: 'MultipleChoiceOption',
|
__typename: 'MultipleChoiceOption',
|
||||||
displayName: option.name,
|
displayName: option.name,
|
||||||
values: option.values.map((value) => {
|
// TODO: Fix the value type
|
||||||
|
values: option.values.map((value: any) => {
|
||||||
return {
|
return {
|
||||||
node: {
|
node: {
|
||||||
entityId: 1,
|
entityId: 1,
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
|
// 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 { HookFetcher } from '@commerce/utils/types'
|
||||||
import { SwrOptions } from '@commerce/utils/use-data'
|
|
||||||
import useCommerceWishlist from '@commerce/wishlist/use-wishlist'
|
import useCommerceWishlist from '@commerce/wishlist/use-wishlist'
|
||||||
import { Product } from '../schema'
|
import { Product } from '../schema'
|
||||||
import useCustomer from '../customer/use-customer'
|
import useCustomer from '../customer/use-customer'
|
||||||
@ -31,7 +33,8 @@ export const fetcher: HookFetcher<Wishlist | null, UseWishlistInput> = () => {
|
|||||||
|
|
||||||
export function extendHook(
|
export function extendHook(
|
||||||
customFetcher: typeof fetcher,
|
customFetcher: typeof fetcher,
|
||||||
swrOptions?: SwrOptions<Wishlist | null, UseWishlistInput>
|
// swrOptions?: SwrOptions<Wishlist | null, UseWishlistInput>
|
||||||
|
swrOptions?: any
|
||||||
) {
|
) {
|
||||||
const useWishlist = ({ includeProducts }: UseWishlistOptions = {}) => {
|
const useWishlist = ({ includeProducts }: UseWishlistOptions = {}) => {
|
||||||
return { data: null }
|
return { data: null }
|
||||||
|
@ -39,5 +39,3 @@ module.exports = withCommerceConfig({
|
|||||||
].filter((x) => x)
|
].filter((x) => x)
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
console.log('configs', module.exports)
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user