fix: cart
This commit is contained in:
@@ -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('');
|
||||
|
||||
Reference in New Issue
Block a user