cart pop-up

This commit is contained in:
2025-06-24 15:53:07 +02:00
parent 5de09aa13b
commit 98a4125804
5 changed files with 101 additions and 70 deletions

View File

@ -1,6 +1,11 @@
import { useMyFetch } from "#imports";
import { usePB } from "~/composables/usePB";
import type { componentsListType, GenericResponse, PBPageItem, PlanPrediction } from "~/types";
import type {
componentsListType,
GenericResponse,
PBPageItem,
PlanPrediction,
} from "~/types";
// import { useI18n } from "vue-i18n";
export const useStore = defineStore("store", () => {
@ -11,20 +16,21 @@ export const useStore = defineStore("store", () => {
// calculator
const monthlySavings = ref(137);
const storagePeriod = ref(10);
const totalInvestment:Ref<number> = ref(0)
const minValue = ref()
const totalInvestment: Ref<number> = ref(0);
const minValue = ref();
// login
const email = ref()
const password = ref()
const email = ref();
const password = ref();
const components = ref({} as PBPageItem[]);
const getSections = async (id: string) => {
pb.cancelRequest("menu_view");
components.value = (
await pb.collection<PBPageItem>("page_view").getList(1, 50, {
filter: `id="${id}"&&(section_lang_id_lang="${$i18n.locale.value
}"||section_is_no_lang=${true})`,
filter: `id="${id}"&&(section_lang_id_lang="${
$i18n.locale.value
}"||section_is_no_lang=${true})`,
sort: "page_section_id_position",
})
).items as PBPageItem[];
@ -72,18 +78,19 @@ export const useStore = defineStore("store", () => {
async function getCalculator() {
try {
const {data} = await useMyFetch<GenericResponse<PlanPrediction>>(
const { data } = await useMyFetch<GenericResponse<PlanPrediction>>(
`/api/public/plan-prediction/easy/calculate?monthly_deposit=${monthlySavings.value}&years=${storagePeriod.value}`,
{
headers: {
"Content-Type": "application/json",
},
onErrorOccured: (_, status) => { throw new Error(`HTTP error: ${status}`) },
onErrorOccured: (_, status) => {
throw new Error(`HTTP error: ${status}`);
},
}
);
totalInvestment.value = data.total_investement_value
totalInvestment.value = data.total_investement_value;
} catch (error) {
console.error("getList error:", error);
}
@ -91,13 +98,15 @@ export const useStore = defineStore("store", () => {
async function getMinValue() {
try {
const {data} = await useMyFetch<GenericResponse<number>>(
'/api/public/plan-prediction/free/minimum',
const { data } = await useMyFetch<GenericResponse<number>>(
"/api/public/plan-prediction/free/minimum",
{
headers: {
"Content-Type": "application/json",
},
onErrorOccured: (_, status) => { throw new Error(`HTTP error: ${status}`) },
onErrorOccured: (_, status) => {
throw new Error(`HTTP error: ${status}`);
},
}
);
@ -106,8 +115,7 @@ export const useStore = defineStore("store", () => {
// }
// const data = await res.json();
minValue.value = data
minValue.value = data;
} catch (error) {
console.error("getList error:", error);
}
@ -115,34 +123,31 @@ export const useStore = defineStore("store", () => {
async function logIn() {
try {
const res = await fetch(
'http://127.0.0.1:4000/api/public/user/session/start',
const { data } = await useMyFetch<GenericResponse<object>>(
`/api/public/user/session/start`,
{
method: 'POST',
method: "POST",
body: JSON.stringify({
mail: email.value,
password: password.value
password: password.value,
}),
headers: {
"Content-Type": "application/json",
},
onErrorOccured: (_, status) => {
throw new Error(`HTTP error: ${status}`);
},
}
);
if (!res.ok) {
throw new Error(`HTTP error: ${res.status}`);
}
const data = await res.json();
minValue.value = data.data
minValue.value = data;
} catch (error) {
console.error("getList error:", error);
}
}
getCalculator()
getMinValue()
getCalculator();
getMinValue();
return {
currentPageID,