forked from crowetic/commerce
update swell consts, cleanup cart types
This commit is contained in:
parent
7786d6445d
commit
9675be1546
@ -11,5 +11,5 @@ BIGCOMMERCE_CHANNEL_ID=
|
|||||||
NEXT_PUBLIC_SHOPIFY_STORE_DOMAIN=
|
NEXT_PUBLIC_SHOPIFY_STORE_DOMAIN=
|
||||||
NEXT_PUBLIC_SHOPIFY_STOREFRONT_ACCESS_TOKEN=
|
NEXT_PUBLIC_SHOPIFY_STOREFRONT_ACCESS_TOKEN=
|
||||||
|
|
||||||
SWELL_STORE_ID=
|
NEXT_PUBLIC_SWELL_STORE_ID=
|
||||||
SWELL_PUBLIC_KEY=
|
NEXT_PUBLIC_SWELL_PUBLIC_KEY=
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import { swellConfig } from '../../index'
|
import { swellConfig } from '../..'
|
||||||
|
|
||||||
const fetchSwellApi = async (
|
const fetchSwellApi = async (
|
||||||
query: string,
|
query: string,
|
||||||
|
@ -5,7 +5,6 @@ import useCart from './use-cart'
|
|||||||
import { Cart, CartItemBody } from '../types'
|
import { Cart, CartItemBody } from '../types'
|
||||||
import { checkoutToCart } from './utils'
|
import { checkoutToCart } from './utils'
|
||||||
import { getCheckoutId } from '../utils'
|
import { getCheckoutId } from '../utils'
|
||||||
import { Mutation, MutationCheckoutLineItemsAddArgs } from '../schema'
|
|
||||||
import { useCallback } from 'react'
|
import { useCallback } from 'react'
|
||||||
|
|
||||||
export default useAddItem as UseAddItem<typeof handler>
|
export default useAddItem as UseAddItem<typeof handler>
|
||||||
@ -38,7 +37,7 @@ export const handler: MutationHook<Cart, {}, CartItemBody> = {
|
|||||||
variables.variant_id = item.variantId
|
variables.variant_id = item.variantId
|
||||||
}
|
}
|
||||||
|
|
||||||
const response = await fetch<Mutation, MutationCheckoutLineItemsAddArgs>({
|
const response = await fetch({
|
||||||
...options,
|
...options,
|
||||||
variables,
|
variables,
|
||||||
})
|
})
|
||||||
|
@ -13,10 +13,8 @@ import useRemoveItem, {
|
|||||||
} from '@commerce/cart/use-remove-item'
|
} from '@commerce/cart/use-remove-item'
|
||||||
|
|
||||||
import useCart from './use-cart'
|
import useCart from './use-cart'
|
||||||
import { checkoutLineItemRemoveMutation, getCheckoutId } from '../utils'
|
|
||||||
import { checkoutToCart } from './utils'
|
import { checkoutToCart } from './utils'
|
||||||
import { Cart, LineItem } from '../types'
|
import { Cart, LineItem } from '../types'
|
||||||
import { Mutation, MutationCheckoutLineItemsRemoveArgs } from '../schema'
|
|
||||||
import { RemoveCartItemBody } from '@commerce/types'
|
import { RemoveCartItemBody } from '@commerce/types'
|
||||||
|
|
||||||
export type RemoveItemFn<T = any> = T extends LineItem
|
export type RemoveItemFn<T = any> = T extends LineItem
|
||||||
@ -39,12 +37,10 @@ export const handler = {
|
|||||||
options,
|
options,
|
||||||
fetch,
|
fetch,
|
||||||
}: HookFetcherContext<RemoveCartItemBody>) {
|
}: HookFetcherContext<RemoveCartItemBody>) {
|
||||||
const response = await fetch<Mutation, MutationCheckoutLineItemsRemoveArgs>(
|
const response = await fetch({
|
||||||
{
|
...options,
|
||||||
...options,
|
variables: [itemId],
|
||||||
variables: [itemId],
|
})
|
||||||
}
|
|
||||||
)
|
|
||||||
return checkoutToCart(response)
|
return checkoutToCart(response)
|
||||||
},
|
},
|
||||||
useHook: ({
|
useHook: ({
|
||||||
@ -52,9 +48,9 @@ export const handler = {
|
|||||||
}: MutationHookContext<Cart | null, RemoveCartItemBody>) => <
|
}: MutationHookContext<Cart | null, RemoveCartItemBody>) => <
|
||||||
T extends LineItem | undefined = undefined
|
T extends LineItem | undefined = undefined
|
||||||
>(
|
>(
|
||||||
item
|
ctx: { item?: T } = {}
|
||||||
) => {
|
) => {
|
||||||
// const { item } = ctx
|
const { item } = ctx
|
||||||
const { mutate } = useCart()
|
const { mutate } = useCart()
|
||||||
const removeItem: RemoveItemFn<LineItem> = async (input) => {
|
const removeItem: RemoveItemFn<LineItem> = async (input) => {
|
||||||
const itemId = input?.id ?? item?.id
|
const itemId = input?.id ?? item?.id
|
||||||
|
@ -14,7 +14,6 @@ import useCart from './use-cart'
|
|||||||
import { handler as removeItemHandler } from './use-remove-item'
|
import { handler as removeItemHandler } from './use-remove-item'
|
||||||
import type { Cart, LineItem, UpdateCartItemBody } from '../types'
|
import type { Cart, LineItem, UpdateCartItemBody } from '../types'
|
||||||
import { checkoutToCart } from './utils'
|
import { checkoutToCart } from './utils'
|
||||||
import { Mutation, MutationCheckoutLineItemsUpdateArgs } from '../schema'
|
|
||||||
|
|
||||||
export type UpdateItemInput<T = any> = T extends LineItem
|
export type UpdateItemInput<T = any> = T extends LineItem
|
||||||
? Partial<UpdateItemInputBase<LineItem>>
|
? Partial<UpdateItemInputBase<LineItem>>
|
||||||
@ -46,12 +45,10 @@ export const handler = {
|
|||||||
message: 'The item quantity has to be a valid integer',
|
message: 'The item quantity has to be a valid integer',
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
const response = await fetch<Mutation, MutationCheckoutLineItemsUpdateArgs>(
|
const response = await fetch({
|
||||||
{
|
...options,
|
||||||
...options,
|
variables: [item.itemId, { quantity: item.quantity }],
|
||||||
variables: [item.itemId, { quantity: item.quantity }],
|
})
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
return checkoutToCart(response)
|
return checkoutToCart(response)
|
||||||
},
|
},
|
||||||
|
@ -25,7 +25,7 @@ const getAllPages = async (options?: {
|
|||||||
config = getConfig(config)
|
config = getConfig(config)
|
||||||
const { locale, fetchSwell } = config
|
const { locale, fetchSwell } = config
|
||||||
const { results } = await fetchSwell('content', 'list', ['pages'])
|
const { results } = await fetchSwell('content', 'list', ['pages'])
|
||||||
const pages = results.map(({ slug, ...rest }) => ({
|
const pages = results.map(({ slug, ...rest }: { slug: string }) => ({
|
||||||
url: `/${locale}/${slug}`,
|
url: `/${locale}/${slug}`,
|
||||||
...rest,
|
...rest,
|
||||||
}))
|
}))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user