forked from crowetic/commerce
Fix cart removal
This commit is contained in:
parent
63e8f431d8
commit
80614a1df0
@ -42,7 +42,7 @@ const CartSidebarView: FC = () => {
|
|||||||
</header>
|
</header>
|
||||||
|
|
||||||
{isEmpty ? (
|
{isEmpty ? (
|
||||||
<div className="flex-shrink-0 px-4 border-t border-gray-200 py-5 sm:px-6">
|
<div className="flex-shrink-0 px-4 border-gray-200 py-5 sm:px-6">
|
||||||
<Button>Continue Shopping</Button>
|
<Button>Continue Shopping</Button>
|
||||||
</div>
|
</div>
|
||||||
) : (
|
) : (
|
||||||
|
@ -25,9 +25,11 @@ const UserNav: FC<Props> = ({ className }) => {
|
|||||||
<ul className={s.list}>
|
<ul className={s.list}>
|
||||||
<li className={s.item} onClick={() => openSidebar()}>
|
<li className={s.item} onClick={() => openSidebar()}>
|
||||||
<Bag />
|
<Bag />
|
||||||
<span className="bg-black h-4 w-4 absolute rounded-full inset-3 text-white flex items-center justify-center font-bold text-xs">
|
{itemsCount > 0 && (
|
||||||
{itemsCount}
|
<span className="bg-black h-4 w-4 absolute rounded-full inset-3 text-white flex items-center justify-center font-bold text-xs">
|
||||||
</span>
|
{itemsCount}
|
||||||
|
</span>
|
||||||
|
)}
|
||||||
</li>
|
</li>
|
||||||
<li className={s.item}>
|
<li className={s.item}>
|
||||||
<Heart />
|
<Heart />
|
||||||
|
@ -142,11 +142,9 @@ const cartApi: BigcommerceApiHandler<Cart> = async (req, res, config) => {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
const { data } = await config.storeApiFetch(
|
const result = await config.storeApiFetch<{ data: any } | null>(
|
||||||
`/v3/carts/${cartId}/items/${itemId}`,
|
`/v3/carts/${cartId}/items/${itemId}`,
|
||||||
{
|
{ method: 'DELETE' }
|
||||||
method: 'DELETE',
|
|
||||||
}
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// Update the cart cookie
|
// Update the cart cookie
|
||||||
@ -155,7 +153,7 @@ const cartApi: BigcommerceApiHandler<Cart> = async (req, res, config) => {
|
|||||||
getCartCookie(config.cartCookie, cartId, config.cartCookieMaxAge)
|
getCartCookie(config.cartCookie, cartId, config.cartCookieMaxAge)
|
||||||
)
|
)
|
||||||
|
|
||||||
return res.status(200).json({ data })
|
return res.status(200).json({ data: result?.data })
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(error)
|
console.error(error)
|
||||||
|
@ -37,9 +37,8 @@ export default async function fetchStoreApi<T>(
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
const data = await res.json()
|
// If something was removed, the response will be empty
|
||||||
|
return res.status === 204 ? null : await res.json()
|
||||||
return data
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getErrorText(res: Response) {
|
async function getErrorText(res: Response) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user