diff --git a/components/cart/CartItem/CartItem.tsx b/components/cart/CartItem/CartItem.tsx
index 652f5a624..4b4d0f01d 100644
--- a/components/cart/CartItem/CartItem.tsx
+++ b/components/cart/CartItem/CartItem.tsx
@@ -81,7 +81,7 @@ const CartItem = ({
{price}
diff --git a/components/product/ProductView/ProductView.tsx b/components/product/ProductView/ProductView.tsx
index 41bb26668..fcbbd22ea 100644
--- a/components/product/ProductView/ProductView.tsx
+++ b/components/product/ProductView/ProductView.tsx
@@ -30,10 +30,8 @@ const ProductView: FC = ({ product, productData, className }) => {
const addToCart = () => {
// TODO: loading state by awating the promise
addItem({
- item: {
- productId: product.entityId,
- variantId: product.variants.edges?.[0]?.node.entityId!,
- },
+ productId: product.entityId,
+ variantId: product.variants.edges?.[0]?.node.entityId!,
})
}
diff --git a/lib/bigcommerce/cart/use-add-item.tsx b/lib/bigcommerce/cart/use-add-item.tsx
index 1a6e144f3..9285073da 100644
--- a/lib/bigcommerce/cart/use-add-item.tsx
+++ b/lib/bigcommerce/cart/use-add-item.tsx
@@ -3,7 +3,7 @@ import { default as useCartAddItem } from '@lib/commerce/cart/use-add-item'
import type { ItemBody, AddItemBody } from '../api/cart'
import { Cart, useCart } from '.'
-export type { ItemBody, AddItemBody }
+export type UpdateItemInput = ItemBody
function fetcher(fetch: Fetcher, { item }: AddItemBody) {
if (
@@ -21,8 +21,8 @@ function fetcher(fetch: Fetcher, { item }: AddItemBody) {
export default function useAddItem() {
const { mutate } = useCart()
const fn = useCartAddItem(fetcher)
- const addItem: typeof fn = async (input) => {
- const data = await fn(input)
+ const addItem = async (input: UpdateItemInput) => {
+ const data = await fn({ item: input })
await mutate(data, false)
return data
}
diff --git a/lib/bigcommerce/cart/use-remove-item.tsx b/lib/bigcommerce/cart/use-remove-item.tsx
index 62a4f28d8..adfa19a3b 100644
--- a/lib/bigcommerce/cart/use-remove-item.tsx
+++ b/lib/bigcommerce/cart/use-remove-item.tsx
@@ -1,9 +1,11 @@
import type { Fetcher } from '@lib/commerce'
import { default as useCartRemoveItem } from '@lib/commerce/cart/use-remove-item'
-import type { ItemBody, RemoveItemBody } from '../api/cart'
+import type { RemoveItemBody } from '../api/cart'
import { Cart, useCart } from '.'
-export type { ItemBody, RemoveItemBody }
+export type RemoveItemInput = {
+ id: string
+}
export function fetcher(
fetch: Fetcher,
@@ -16,11 +18,11 @@ export function fetcher(
})
}
-export default function useRemoveItem() {
+export default function useRemoveItem(item?: any) {
const { mutate } = useCart()
const fn = useCartRemoveItem(fetcher)
- const removeItem: typeof fn = async (input) => {
- const data = await fn(input)
+ const removeItem = async (input: RemoveItemInput) => {
+ const data = await fn({ itemId: input.id ?? item?.id })
await mutate(data, false)
return data
}
diff --git a/lib/bigcommerce/cart/use-update-item.tsx b/lib/bigcommerce/cart/use-update-item.tsx
index 55446d74d..0896c310f 100644
--- a/lib/bigcommerce/cart/use-update-item.tsx
+++ b/lib/bigcommerce/cart/use-update-item.tsx
@@ -26,15 +26,15 @@ function fetcher(
})
}
-export default function useUpdateItem(item: any = {}) {
+export default function useUpdateItem(item?: any) {
const { mutate } = useCart()
const fn = useCartUpdateItem(fetcher)
const updateItem = async (input: UpdateItemInput) => {
const data = await fn({
- itemId: input.id ?? item.id,
+ itemId: input.id ?? item?.id,
item: {
- productId: input.productId ?? item.product_id,
- variantId: input.productId ?? item.variant_id,
+ productId: input.productId ?? item?.product_id,
+ variantId: input.productId ?? item?.variant_id,
quantity: input.quantity,
},
})