fix: cart

This commit is contained in:
2026-04-16 09:40:04 +02:00
parent cf48624d7f
commit 9b525f06cd
5 changed files with 220 additions and 217 deletions

View File

@@ -36,28 +36,33 @@ export const useCartStore = defineStore('cart', () => {
}
}
async function addNewCart(name: string) {
try {
error.value = null
const url = `/api/v1/restricted/carts/add-new-cart`
const response = await useFetchJson<ApiResponse>(url)
const newCart: Cart = {
id: response.items.cart_id,
name: response.items.name,
items: []
}
carts.value.push(newCart)
activeCartId.value = newCart.id
return newCart
} catch (e: any) {
error.value = e?.message ?? 'Error creating cart'
}
async function addNewCart(name: string) {
if (!name.trim()) {
error.value = 'Cart name is required'
return
}
try {
error.value = null
const url = `/api/v1/restricted/carts/add-new-cart?name=${name}`
const response = await useFetchJson<ApiResponse>(url)
const newCart: Cart = {
id: response.items.cart_id,
name: response.items.name,
items: []
}
carts.value.push(newCart)
activeCartId.value = newCart.id
return newCart
} catch (e: any) {
error.value = e?.message ?? 'Error creating cart'
}
}
const route = useRoute()
const amount = ref<number>(1);
const errorMessage = ref('');