fix: remove line items when 0

This commit is contained in:
Victor Gerbrands
2023-05-04 13:02:46 +02:00
parent 5bcf6cb5eb
commit 4d99e73f20
5 changed files with 3408 additions and 31 deletions

View File

@@ -14,7 +14,7 @@ export default function DeleteItemButton({ item }: { item: CartItem }) {
setRemoving(true);
console.log(item.id);
const response = await fetch(`/api/cart?lineId=${item.id}`, {
const response = await fetch(`/api/cart?lineItemId=${item.id}`, {
method: 'DELETE'
});

View File

@@ -20,13 +20,18 @@ export default function EditItemQuantityButton({
async function handleEdit() {
setEditing(true);
const response = await fetch(`/api/cart`, {
method: type === 'minus' && item.quantity - 1 === 0 ? 'DELETE' : 'PUT',
body: JSON.stringify({
lineId: item.id,
variantId: item.merchandise.id,
quantity: type === 'plus' ? item.quantity + 1 : item.quantity - 1
})
const method = type === 'minus' && item.quantity - 1 === 0 ? 'DELETE' : 'PUT';
const url = method === 'PUT' ? '/api/cart' : `/api/cart?lineItemId=${item.id}`;
const response = await fetch(url, {
method,
body:
method === 'PUT'
? JSON.stringify({
lineItemId: item.id,
quantity: type === 'plus' ? item.quantity + 1 : item.quantity - 1
})
: null
});
const data = await response.json();