fix eslint

This commit is contained in:
2025-07-03 15:24:28 +02:00
parent e935e9f911
commit 9063846282
12 changed files with 784 additions and 1121 deletions

View File

@ -1,26 +1,25 @@
import type { GenericResponse, GenericResponseItems, UserCart } from "~/types";
import { validation } from '../utils/validation'
import { REGEX_PHONE } from '../utils/regex'
import type { GenericResponse, GenericResponseItems, UserCart } from '~/types'
import type {
Address,
AddressesList,
CheckoutOrder,
Payment,
UserAddressOfficial,
} from "~/types/checkout";
import { validation } from "../utils/validation";
import { REGEX_PHONE } from "../utils/regex";
import type { CartProduct } from "~/types/product";
} from '~/types/checkout'
import type { CartProduct } from '~/types/product'
export const useCheckoutStore = defineStore("checkoutStore", () => {
const { $toast } = useNuxtApp();
const menuStore = useMenuStore();
export const useCheckoutStore = defineStore('checkoutStore', () => {
const { $toast } = useNuxtApp()
const menuStore = useMenuStore()
const selectedIso = ref(menuStore.selectedCountry);
const selectedIso = ref(menuStore.selectedCountry)
const vLegal = ref(false);
const vTerms = ref(false);
const vNote = ref("");
const legalValidation = ref(false);
const termsValidation = ref(false);
const vLegal = ref(false)
const vTerms = ref(false)
const vNote = ref('')
const legalValidation = ref(false)
const termsValidation = ref(false)
// get address list
const addressesList = ref<AddressesList[]>()
@ -154,7 +153,7 @@ export const useCheckoutStore = defineStore("checkoutStore", () => {
const phoneValidation = ref<boolean | null>(null)
// send checkout form
const userStore = useUserStore();
const userStore = useUserStore()
async function sendForm() {
const phoneNum = vUseAccountPhoneNumber.value
? accountPhoneNumber.value
@ -197,18 +196,19 @@ export const useCheckoutStore = defineStore("checkoutStore", () => {
},
)
console.log(res);
console.log(res)
if (res.status === 200) {
$toast.success('Form successfully sent', {
autoClose: 5000,
dangerouslyHTMLString: true,
});
})
menuStore.navigateToItem(
menuStore.menuItems?.find((item) => item.id === 13)
);
} else {
$toast.error("Failed to send form. Please try again.", {
menuStore.menuItems?.find(item => item.id === 13),
)
}
else {
$toast.error('Failed to send form. Please try again.', {
autoClose: 5000,
dangerouslyHTMLString: true,
})
@ -219,10 +219,6 @@ export const useCheckoutStore = defineStore("checkoutStore", () => {
}
}
const changeActive = (item: any) => {
activeAddress.value = item
}
// get checkout
async function getCheckout() {
try {
@ -279,99 +275,80 @@ export const useCheckoutStore = defineStore("checkoutStore", () => {
}
// get delivery options
const deliveryOption = ref()
const currentDelivery = ref()
const shippingPrice = ref()
interface DeliveryOptionItem {
country_iso: string
country_name: string
delivery_supplier_id: number
delivery_supplier_name: string
id: number
shippment_price: string
}
const deliveryOption = ref<DeliveryOptionItem[]>([])
const currentDelivery = ref<DeliveryOptionItem | null>(null)
const shippingPrice = ref<number>(0)
async function getDeliveryOptions() {
try {
const res = await useMyFetch<
GenericResponseItems<object>
// {
// items: [
// {
// country_iso: string;
// country_name: string;
// delivery_supplier_id: number;
// delivery_supplier_name: string;
// id: number;
// shippment_price: string;
// }
// ];
// }
>(`/api/restricted/cart/checkout/delivery-options`, {
headers: {
'Content-Type': 'application/json',
},
onErrorOccured: async (_, status) => {
throw createError({
statusCode: status,
statusMessage: `HTTP error: ${status}`,
})
},
})
const data = {
items: [
{
id: 31,
shippment_price: "2",
delivery_supplier_id: 4,
delivery_supplier_name: "Personal collection",
country_iso: "pl",
country_name: "Poland",
const { data } = await useMyFetch<GenericResponseItems<DeliveryOptionItem[]>>(
`/api/restricted/cart/checkout/delivery-options`,
{
headers: {
'Content-Type': 'application/json',
},
{
id: 34,
shippment_price: "20",
delivery_supplier_id: 1,
delivery_supplier_name: "Ceska Posta",
country_iso: "pl",
country_name: "Poland",
onErrorOccured: async (_, status) => {
throw createError({
statusCode: status,
statusMessage: `HTTP error: ${status}`,
})
},
],
items_count: 2,
};
},
)
deliveryOption.value = data.items;
currentDelivery.value = data.items[0];
shippingPrice.value = data.items[0].shippment_price;
fullPrice.value = Number(fullPrice.value) + Number(shippingPrice.value);
} catch (error) {
console.error("getUserCart error:", error);
if (data.items && data.items.length > 0) {
deliveryOption.value = data.items
currentDelivery.value = data.items[0]
shippingPrice.value = Number(data.items[0].shippment_price)
fullPrice.value += shippingPrice.value
}
}
catch (error) {
console.error('getDeliveryOptions error:', error)
}
}
const setCurrentDelivery = (item: any) => {
shippingPrice.value = item.shippment_price;
currentDelivery.value = item;
fullPrice.value = Number(fullPrice.value) + Number(shippingPrice.value);
};
const setCurrentDelivery = (item: DeliveryOptionItem) => {
shippingPrice.value = Number(item.shippment_price)
currentDelivery.value = item
fullPrice.value = Number(fullPrice.value) + Number(shippingPrice.value)
}
interface Address {
is_default: boolean | string
country_iso: string
}
const defaultAddress = ref<Address | undefined>()
const defaultAddress = ref();
async function getDefAddress() {
try {
const { data } = await useMyFetch<
GenericResponse<{
addresses: [
{
is_default: string
},
]
}>
>(`/api/public/user`, {
headers: {
'Content-Type': 'application/json',
const { data } = await useMyFetch<GenericResponse<{ addresses: Address[] }>>(
`/api/public/user`,
{
headers: {
'Content-Type': 'application/json',
},
onErrorOccured: async (_, status) => {
throw createError({
statusCode: status,
statusMessage: `HTTP error: ${status}`,
})
},
},
onErrorOccured: async (_, status) => {
throw createError({
statusCode: status,
statusMessage: `HTTP error: ${status}`,
})
},
})
)
defaultAddress.value = data.addresses.find(
(el: any) => el.is_default === true,
el => el.is_default === true || el.is_default === 'true',
)
}
catch (error) {
@ -380,30 +357,31 @@ export const useCheckoutStore = defineStore("checkoutStore", () => {
}
// get bank data
const paymentMethods = ref([] as Payment[]);
const fullAddress = ref<Address>();
const currentPayment = ref<Payment | null>();
const paymentMethods = ref([] as Payment[])
const fullAddress = ref<Address>()
const currentPayment = ref<Payment | null>()
async function getBankAccount() {
try {
const { data } = await useMyFetch<GenericResponse<Payment[]>>(
`/api/restricted/suitable-bank-accounts/${menuStore.selectedCurrency.iso_code}/${fullAddress.value?.country_iso}`,
{
headers: {
"Content-Type": "application/json",
'Content-Type': 'application/json',
},
onErrorOccured: async (_, status) => {
throw createError({
statusCode: status,
statusMessage: `HTTP error: ${status}`,
});
})
},
}
);
},
)
paymentMethods.value = data;
currentPayment.value = data[0];
} catch (error) {
console.error("getUserCart error:", error);
paymentMethods.value = data
currentPayment.value = data[0]
}
catch (error) {
console.error('getUserCart error:', error)
}
}
@ -414,131 +392,132 @@ export const useCheckoutStore = defineStore("checkoutStore", () => {
`/api/restricted/cart/checkout/order`,
{
headers: {
"Content-Type": "application/json",
'Content-Type': 'application/json',
},
onErrorOccured: async (_, status) => {
throw createError({
statusCode: status,
statusMessage: `HTTP error: ${status}`,
});
})
},
}
);
},
)
fullAddress.value = data.delivery_details.address;
console.log(fullAddress.value);
} catch (error) {
console.error("getOrder error:", error);
fullAddress.value = data.delivery_details.address
}
catch (error) {
console.error('getOrder error:', error)
}
}
async function setNewAddress(indexItem: number) {
currentPayment.value = paymentMethods.value.find(
(item, index) => indexItem === index
);
(item, index) => indexItem === index,
)
}
// send summary form
async function sendSummaryForm() {
vLegal.value
? (legalValidation.value = false)
: (legalValidation.value = true);
vTerms.value
? (termsValidation.value = false)
: (termsValidation.value = true);
legalValidation.value = !vLegal.value
termsValidation.value = !vTerms.value
if (!vTerms.value && !vLegal.value) {
return;
return
}
try {
await useMyFetch<GenericResponse<object>>(
`/api/restricted/cart/checkout/delivery`,
{
method: "PUT",
method: 'PUT',
headers: {
"Content-Type": "application/json",
'Content-Type': 'application/json',
},
body: JSON.stringify({
accept_general_conditions: true,
accept_long_purchase: true,
address: fullAddress.value,
delivery_option_id: currentDelivery.value.id,
delivery_option_id: currentDelivery.value?.id,
note: vNote.value,
}),
onErrorOccured: async (_, status) => {
throw createError({
statusCode: status,
statusMessage: `HTTP error: ${status}`,
});
})
},
}
);
},
)
await putCheckoutBankAccount();
await markOrder();
await getUserCart();
} catch (error) {
console.error("uploadAddress error:", error);
await putCheckoutBankAccount()
await markOrder()
await getUserCart()
}
catch (error) {
console.error('uploadAddress error:', error)
}
}
// put checkout bank-account
async function putCheckoutBankAccount() {
try {
const res = await useMyFetch<GenericResponse<object>>(
await useMyFetch<GenericResponse<object>>(
`/api/restricted/cart/checkout/bank-account/${currentPayment.value?.id}`,
{
method: "PUT",
method: 'PUT',
headers: {
"Content-Type": "application/json",
'Content-Type': 'application/json',
},
onErrorOccured: async (_, status) => {
throw createError({
statusCode: status,
statusMessage: `HTTP error: ${status}`,
});
})
},
}
);
} catch (error) {
console.error("uploadAddress error:", error);
},
)
}
catch (error) {
console.error('uploadAddress error:', error)
}
}
const modalMadeOrder = ref(false);
const modalMadeOrder = ref(false)
async function markOrder() {
try {
const res = await useMyFetch<GenericResponse<object>>(
`/api/restricted/cart/checkout/order`,
{
method: "POST",
method: 'POST',
headers: {
"Content-Type": "application/json",
'Content-Type': 'application/json',
},
onErrorOccured: async (_, status) => {
throw createError({
statusCode: status,
statusMessage: `HTTP error: ${status}`,
});
})
},
}
);
},
)
if (res.status === 200 || res.status === 201) {
$toast.success("Address successfully added", {
$toast.success('Address successfully added', {
autoClose: 5000,
dangerouslyHTMLString: true,
});
modalMadeOrder.value = true;
} else {
$toast.error("Failed to add address. Please try again.", {
})
modalMadeOrder.value = true
}
else {
$toast.error('Failed to add address. Please try again.', {
autoClose: 5000,
dangerouslyHTMLString: true,
});
})
}
// window.location.href = `/golden-panel/my-purchases/${res._data?.data.id}`;
} catch (error) {
console.error("uploadAddress error:", error);
}
catch (error) {
console.error('uploadAddress error:', error)
}
}
return {
@ -575,6 +554,7 @@ export const useCheckoutStore = defineStore("checkoutStore", () => {
defaultAddress,
paymentMethods,
currentPayment,
fullAddress,
vLegal,
vTerms,
@ -587,7 +567,6 @@ export const useCheckoutStore = defineStore("checkoutStore", () => {
getCheckout,
getAddressList,
getUserData,
changeActive,
uploadAddress,
sendForm,
getUserCart,
@ -598,5 +577,5 @@ export const useCheckoutStore = defineStore("checkoutStore", () => {
getOrder,
setNewAddress,
sendSummaryForm,
};
});
}
})

View File

@ -1,4 +1,4 @@
import { useStore } from "./store";
import { useStore } from './store'
import type {
Country,
Currency,
@ -7,78 +7,78 @@ import type {
GenericResponseItems,
Language,
UIFrontMenu,
} from "~/types";
import { useMyFetch } from "#imports";
} from '~/types'
import { useMyFetch } from '#imports'
function buildTreeRecursive(
data: (FrontMenu | UIFrontMenu)[],
parentId: number
parentId: number,
): UIFrontMenu[] {
const children = data.filter(
(item): item is UIFrontMenu =>
item.id_parent === parentId && !item.is_default
);
item.id_parent === parentId && !item.is_default,
)
return children.map((item) => ({
return children.map(item => ({
...item,
children: buildTreeRecursive(data, item.id),
}));
}))
}
export const useMenuStore = defineStore("menuStore", () => {
const store = useStore();
const { $i18n } = useNuxtApp();
export const useMenuStore = defineStore('menuStore', () => {
const store = useStore()
const { $i18n } = useNuxtApp()
// const session = useSession();
const { $session } = useNuxtApp();
const router = useRouter();
const route = useRoute();
const { $session } = useNuxtApp()
const router = useRouter()
const route = useRoute()
const openMenu = ref(false);
const openDropDown = ref(false);
const openMenu = ref(false)
const openDropDown = ref(false)
const defaultMenu = ref();
const defaultMenu = ref()
const menu = ref([] as UIFrontMenu[]);
const menuItems = ref([] as FrontMenu[]);
const menu = ref([] as UIFrontMenu[])
const menuItems = ref([] as FrontMenu[])
// curr/country
const selectedCountry = ref({} as Country);
const selectedPhoneCountry = ref({} as Country);
const selectedCurrency = ref({} as Currency);
const selectedLanguage = ref({} as Language);
const selectedCountry = ref({} as Country)
const selectedPhoneCountry = ref({} as Country)
const selectedCurrency = ref({} as Currency)
const selectedLanguage = ref({} as Language)
const countries = ref([] as Country[]);
const currencies = ref([] as Currency[]);
const languages = ref([] as Language[]);
const countries = ref([] as Country[])
const currencies = ref([] as Currency[])
const languages = ref([] as Language[])
const getLocales = async () => {
const { data: countriesList } = await useMyFetch<
GenericResponse<Country[]>
>(`/api/public/country/list`);
countries.value = countriesList;
>(`/api/public/country/list`)
countries.value = countriesList
selectedCountry.value = countriesList.find(
(country) => country.iso_code === $session.currentCountryIso.value
) as Country;
country => country.iso_code === $session.currentCountryIso.value,
) as Country
selectedPhoneCountry.value = countriesList.find(
(country) => country.iso_code === $session.currentCountryIso.value
) as Country;
country => country.iso_code === $session.currentCountryIso.value,
) as Country
const { data: currenciesList } = await useMyFetch<
GenericResponseItems<Currency[]>
>(`/api/public/currencies`);
currencies.value = currenciesList.items;
>(`/api/public/currencies`)
currencies.value = currenciesList.items
selectedCurrency.value = currenciesList.items.find(
(currency) => currency.iso_code === $session.currentCurrencyIso.value
) as Currency;
currency => currency.iso_code === $session.currentCurrencyIso.value,
) as Currency
const { data: languagesList } = await useMyFetch<
GenericResponseItems<Language[]>
>(`/api/public/languages`);
languages.value = languagesList.items;
>(`/api/public/languages`)
languages.value = languagesList.items
selectedLanguage.value = languagesList.items.find(
(language) => language.iso_code === $session.currentLanguageIso.value
) as Language;
};
language => language.iso_code === $session.currentLanguageIso.value,
) as Language
}
const loadMenu = async () => {
try {
@ -86,81 +86,84 @@ export const useMenuStore = defineStore("menuStore", () => {
`/api/public/front/menu`,
{
onErrorOccured: (err, status) => {
console.log(err, status);
console.log(err, status)
},
}
);
},
)
menuItems.value = data;
menuItems.value = data
const root = data.find((item) => item.is_root) as UIFrontMenu;
defaultMenu.value = data.find((item) => item.is_default);
const root = data.find(item => item.is_root) as UIFrontMenu
defaultMenu.value = data.find(item => item.is_default)
if (root) {
menu.value = buildTreeRecursive(data, root.id);
} else {
console.warn("Root menu item not found");
menu.value = [];
menu.value = buildTreeRecursive(data, root.id)
}
else {
console.warn('Root menu item not found')
menu.value = []
}
} catch (error) {
console.log(error);
}
};
catch (error) {
console.log(error)
}
}
const navigateToItem = (item?: UIFrontMenu) => {
if (item) {
router.push({
params: { slug: item.front_menu_lang[0].link_rewrite, id: item.id },
name: `id-slug___${$i18n.locale.value}`,
});
openDropDown.value = false;
} else {
})
openDropDown.value = false
}
else {
router.push({
params: {
slug: defaultMenu.value.front_menu_lang[0].link_rewrite,
id: defaultMenu.value.id,
},
name: `id-slug___${$i18n.locale.value}`,
});
})
}
};
}
function navigateToShop() {
navigateToItem(menuItems.value?.find((item) => item.id === 5));
navigateToItem(menuItems.value?.find(item => item.id === 5))
}
function getProductMenu() {
return menuItems.value?.find((item) => item.id === 13);
return menuItems.value?.find(item => item.id === 14)
}
const getFirstImage = (size: "l" | "m" | "s" = "m", needbaseurl: boolean) => {
const req = useRequestEvent();
const url = useRequestURL();
const getFirstImage = (size: 'l' | 'm' | 's' = 'm', needbaseurl: boolean) => {
const req = useRequestEvent()
const url = useRequestURL()
// let img = "";
const img: string[] = [];
const img: string[] = []
for (const s in store.components) {
if (store.components[s].front_section.img.length === 0) continue;
if (store.components[s].front_section.img.length === 0) continue
img.push(
`/api/public/file/${store.components[s].front_section.img[0]}_${size}.webp`
);
if (img.length > 0) break;
`/api/public/file/${store.components[s].front_section.img[0]}_${size}.webp`,
)
if (img.length > 0) break
}
if (img.length > 0) {
if (needbaseurl) {
return `${req?.headers.get("x-forwarded-proto") || url.protocol}://${
req?.headers.get("x-forwarded-host") ||
url.host ||
req?.headers.get("host")
}${img[0]}`;
return `${req?.headers.get('x-forwarded-proto') || url.protocol}://${
req?.headers.get('x-forwarded-host')
|| url.host
|| req?.headers.get('host')
}${img[0]}`
}
return img[0];
return img[0]
}
return "";
};
return ''
}
const headMeta = computed(() => {
const item = menuItems.value?.find(
(item) => item.id.toString() === route.params.id
);
item => item.id.toString() === route.params.id,
)
const meta = {
title: item?.front_menu_lang[0].meta_title,
@ -169,77 +172,77 @@ export const useMenuStore = defineStore("menuStore", () => {
},
link: [
// { rel: "manifest", href: "/api/manifest.json" }
{ rel: "icon", type: "image/x-icon", href: "/favicon.png" },
{ rel: 'icon', type: 'image/x-icon', href: '/favicon.png' },
],
script: [
{
src: "https://leiadmin.com/leitag.js?lei=894500UT83EISNNA8D04&color=dark",
src: 'https://leiadmin.com/leitag.js?lei=894500UT83EISNNA8D04&color=dark',
defer: true,
},
],
meta: [
{
hid: "description",
name: "description",
hid: 'description',
name: 'description',
content: item?.front_menu_lang[0].meta_description,
},
{
property: "og:title",
property: 'og:title',
content: item?.front_menu_lang[0].meta_title,
},
{
property: "og:description",
property: 'og:description',
content: item?.front_menu_lang[0].meta_description,
},
{
property: "og:image",
content: getFirstImage("m", true),
property: 'og:image',
content: getFirstImage('m', true),
},
{
property: "twitter:title",
property: 'twitter:title',
content: item?.front_menu_lang[0].meta_title,
},
{
property: "twitter:description",
property: 'twitter:description',
content: item?.front_menu_lang[0].meta_description,
},
{
property: "twitter:image",
content: getFirstImage("m", true),
property: 'twitter:image',
content: getFirstImage('m', true),
},
],
};
const preload = getFirstImage("l", false);
if (preload) {
meta.link.push({ rel: "preload", as: "image", href: preload } as never);
}
return meta;
});
const preload = getFirstImage('l', false)
if (preload) {
meta.link.push({ rel: 'preload', as: 'image', href: preload } as never)
}
return meta
})
const formatPrice = (value: number): string => {
return value.toLocaleString(selectedLanguage.value.iso_code, {
minimumFractionDigits: selectedCurrency.value.precision,
maximumFractionDigits: selectedCurrency.value.precision,
currency: selectedCurrency.value.iso_code,
style: "currency",
currencyDisplay: "symbol",
currencySign: "accounting",
});
};
style: 'currency',
currencyDisplay: 'symbol',
currencySign: 'accounting',
})
}
// watches
watch(
() => $session.cookieData,
async () => {
await getLocales();
await loadMenu();
await store.getMinValue();
await store.getCalculator();
await getLocales()
await loadMenu()
await store.getMinValue()
await store.getCalculator()
},
{ deep: true }
);
{ deep: true },
)
return {
menu,
@ -261,5 +264,6 @@ export const useMenuStore = defineStore("menuStore", () => {
navigateToItem,
getLocales,
getProductMenu,
};
});
formatPrice,
}
})

View File

@ -1,18 +1,17 @@
import { useMyFetch } from "#imports";
import { useMyFetch } from '#imports'
import type {
GenericResponse,
GenericResponseChildren,
GenericResponseItems,
UserCart,
} from "~/types";
import type { Product } from "~/types/product";
} from '~/types'
import type { Product } from '~/types/product'
export const useProductStore = defineStore("productStore", () => {
const { $toast } = useNuxtApp();
const productList = ref<Product[]>();
const modules = ref();
export const useProductStore = defineStore('productStore', () => {
const { $toast } = useNuxtApp()
const productList = ref<Product[]>()
const modules = ref()
const checkoutStore = useCheckoutStore();
const checkoutStore = useCheckoutStore()
async function getList(count: number, categoryId = 1) {
try {
@ -20,21 +19,22 @@ export const useProductStore = defineStore("productStore", () => {
`/api/public/products/category/${categoryId}?p=1&elems=${count}`,
{
headers: {
"Content-Type": "application/json",
'Content-Type': 'application/json',
},
onErrorOccured: async (_, status) => {
// await navigateTo("/error", { replace: true });
throw createError({
statusCode: status,
statusMessage: `HTTP error: ${status}`,
});
})
},
}
);
},
)
productList.value = data.items;
} catch (error) {
console.error("getList error:", error);
productList.value = data.items
}
catch (error) {
console.error('getList error:', error)
}
}
@ -44,20 +44,21 @@ export const useProductStore = defineStore("productStore", () => {
`/api/public/module/e_shop`,
{
headers: {
"Content-Type": "application/json",
'Content-Type': 'application/json',
},
onErrorOccured: (_, status) => {
throw new Error(`HTTP error: ${status}`);
throw new Error(`HTTP error: ${status}`)
},
}
);
},
)
modules.value = data.children.find(
(item: { id: number; name: string }) =>
item.name === "currency_rates_bar"
);
} catch (error) {
console.error("getList error:", error);
(item: { id: number, name: string }) =>
item.name === 'currency_rates_bar',
)
}
catch (error) {
console.error('getList error:', error)
}
}
@ -66,34 +67,36 @@ export const useProductStore = defineStore("productStore", () => {
const res = await useMyFetch<GenericResponse<object>>(
`/api/public/user/cart/item/add/${id}/1`,
{
method: "PUT",
method: 'PUT',
headers: {
"Content-Type": "application/json",
'Content-Type': 'application/json',
},
onErrorOccured: (_, status) => {
throw new Error(`HTTP error: ${status}`);
throw new Error(`HTTP error: ${status}`)
},
}
);
},
)
if (res.status === 200) {
$toast.success("Item successfully added to your cart.", {
$toast.success('Item successfully added to your cart.', {
autoClose: 5000,
dangerouslyHTMLString: true,
});
checkoutStore.getUserCart();
} else {
$toast.error("Failed to add item to cart. Please try again.", {
autoClose: 5000,
dangerouslyHTMLString: true,
});
})
checkoutStore.getUserCart()
}
} catch (error) {
$toast.error("An unexpected error occurred while updating your cart.", {
else {
$toast.error('Failed to add item to cart. Please try again.', {
autoClose: 5000,
dangerouslyHTMLString: true,
})
}
}
catch (error) {
$toast.error('An unexpected error occurred while updating your cart.', {
autoClose: 5000,
dangerouslyHTMLString: true,
});
console.error("incrementCartItem error:", error);
})
console.error('incrementCartItem error:', error)
}
}
@ -102,34 +105,36 @@ export const useProductStore = defineStore("productStore", () => {
const res = await useMyFetch<GenericResponse<object>>(
`/api/public/user/cart/item/subtract/${id}/1`,
{
method: "PUT",
method: 'PUT',
headers: {
"Content-Type": "application/json",
'Content-Type': 'application/json',
},
onErrorOccured: (_, status) => {
throw new Error(`HTTP error: ${status}`);
throw new Error(`HTTP error: ${status}`)
},
}
);
},
)
if (res.status === 200) {
$toast.success("Item successfully removed from your cart.", {
$toast.success('Item successfully removed from your cart.', {
autoClose: 5000,
dangerouslyHTMLString: true,
});
checkoutStore.getUserCart();
} else {
$toast.error("Failed to removed item from cart. Please try again.", {
autoClose: 5000,
dangerouslyHTMLString: true,
});
})
checkoutStore.getUserCart()
}
} catch (error) {
$toast.error("An unexpected error occurred while updating your cart.", {
else {
$toast.error('Failed to removed item from cart. Please try again.', {
autoClose: 5000,
dangerouslyHTMLString: true,
})
}
}
catch (error) {
$toast.error('An unexpected error occurred while updating your cart.', {
autoClose: 5000,
dangerouslyHTMLString: true,
});
console.error("decrementCartItem error:", error);
})
console.error('decrementCartItem error:', error)
}
}
@ -138,34 +143,36 @@ export const useProductStore = defineStore("productStore", () => {
const res = await useMyFetch<GenericResponse<object>>(
`/api/public/user/cart/item/${id}`,
{
method: "DELETE",
method: 'DELETE',
headers: {
"Content-Type": "application/json",
'Content-Type': 'application/json',
},
onErrorOccured: (_, status) => {
throw new Error(`HTTP error: ${status}`);
throw new Error(`HTTP error: ${status}`)
},
}
);
},
)
if (res.status === 200) {
$toast.success("Item successfully removed from your cart.", {
$toast.success('Item successfully removed from your cart.', {
autoClose: 5000,
dangerouslyHTMLString: true,
});
checkoutStore.getUserCart();
} else {
$toast.error("Failed to removed item from cart. Please try again.", {
autoClose: 5000,
dangerouslyHTMLString: true,
});
})
checkoutStore.getUserCart()
}
} catch (error) {
$toast.error("An unexpected error occurred while updating your cart.", {
else {
$toast.error('Failed to removed item from cart. Please try again.', {
autoClose: 5000,
dangerouslyHTMLString: true,
})
}
}
catch (error) {
$toast.error('An unexpected error occurred while updating your cart.', {
autoClose: 5000,
dangerouslyHTMLString: true,
});
console.error("deleteCartItem error:", error);
})
console.error('deleteCartItem error:', error)
}
}
@ -177,5 +184,5 @@ export const useProductStore = defineStore("productStore", () => {
incrementCartItem,
decrementCartItem,
deleteCartItem,
};
});
}
})