remove pocketbase
This commit is contained in:
@ -1,12 +1,14 @@
|
||||
import type { GenericResponse } from "~/types";
|
||||
import type { GenericResponse, GenericResponseItems, UserCart } from "~/types";
|
||||
import type { AddressesList, UserAddressOfficial } from "~/types/checkout";
|
||||
import { validation } from "../utils/validation";
|
||||
import { REGEX_PHONE } from "../utils/regex";
|
||||
import type { CartProduct } from "~/types/product";
|
||||
|
||||
export const useCheckoutStore = defineStore("checkoutStore", () => {
|
||||
const { $toast } = useNuxtApp();
|
||||
const menuStore = useMenuStore();
|
||||
const selectedIso = ref(menuStore.selectedCountry);
|
||||
const showSummary = ref(false);
|
||||
|
||||
// get address list
|
||||
const addressesList = ref<AddressesList[]>();
|
||||
@ -185,6 +187,7 @@ export const useCheckoutStore = defineStore("checkoutStore", () => {
|
||||
dangerouslyHTMLString: true,
|
||||
});
|
||||
// redirectToSummary();
|
||||
showSummary.value = true;
|
||||
} else {
|
||||
$toast.error("Failed to send form. Please try again.", {
|
||||
autoClose: 5000,
|
||||
@ -222,6 +225,108 @@ export const useCheckoutStore = defineStore("checkoutStore", () => {
|
||||
}
|
||||
}
|
||||
|
||||
// get user cart
|
||||
const products = ref<CartProduct[]>();
|
||||
const fullPrice = ref();
|
||||
const fullProductsPrice = ref();
|
||||
async function getUserCart() {
|
||||
try {
|
||||
const { data } = await useMyFetch<GenericResponse<UserCart>>(
|
||||
`/api/public/user/cart`,
|
||||
{
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
onErrorOccured: async (_, status) => {
|
||||
throw createError({
|
||||
statusCode: status,
|
||||
statusMessage: `HTTP error: ${status}`,
|
||||
});
|
||||
},
|
||||
}
|
||||
);
|
||||
|
||||
products.value = data.cart_items;
|
||||
fullPrice.value = data.total_value;
|
||||
fullProductsPrice.value = data.total_value;
|
||||
fullPrice.value = Number(fullPrice.value) + Number(shippingPrice.value);
|
||||
} catch (error) {
|
||||
console.error("getUserCart error:", error);
|
||||
}
|
||||
}
|
||||
|
||||
// get delivery options
|
||||
const deliveryOption = ref();
|
||||
const currentDelivery = ref();
|
||||
const shippingPrice = ref();
|
||||
async function getDeliveryOptions() {
|
||||
try {
|
||||
const { data } = await useMyFetch<
|
||||
GenericResponseItems<{
|
||||
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}`,
|
||||
});
|
||||
},
|
||||
});
|
||||
|
||||
console.log(data);
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
const defaultAddress = ref();
|
||||
async function getDefAddress() {
|
||||
try {
|
||||
const { data } = await useMyFetch<
|
||||
GenericResponse<{
|
||||
addresses: [
|
||||
{
|
||||
is_default: string;
|
||||
}
|
||||
];
|
||||
}>
|
||||
>(`/api/public/user`, {
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
onErrorOccured: async (_, status) => {
|
||||
throw createError({
|
||||
statusCode: status,
|
||||
statusMessage: `HTTP error: ${status}`,
|
||||
});
|
||||
},
|
||||
});
|
||||
|
||||
defaultAddress.value = data.addresses.find(
|
||||
(el: any) => el.is_default === true
|
||||
);
|
||||
} catch (error) {
|
||||
console.error("getUserCart error:", error);
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
addressesList,
|
||||
activeAddress,
|
||||
@ -246,6 +351,15 @@ export const useCheckoutStore = defineStore("checkoutStore", () => {
|
||||
vNewAddressCode,
|
||||
vNewAddressCity,
|
||||
vNewAddressCountry,
|
||||
showSummary,
|
||||
|
||||
products,
|
||||
fullPrice,
|
||||
fullProductsPrice,
|
||||
deliveryOption,
|
||||
currentDelivery,
|
||||
shippingPrice,
|
||||
defaultAddress,
|
||||
|
||||
changePrefix,
|
||||
getCheckout,
|
||||
@ -254,5 +368,8 @@ export const useCheckoutStore = defineStore("checkoutStore", () => {
|
||||
changeActive,
|
||||
uploadAddress,
|
||||
sendForm,
|
||||
getUserCart,
|
||||
getDeliveryOptions,
|
||||
getDefAddress,
|
||||
};
|
||||
});
|
||||
|
Reference in New Issue
Block a user