feat: create new order

This commit is contained in:
Nikita Kiselev
2025-07-31 23:48:11 +03:00
parent eb1f1dc9c1
commit c057f4be76
24 changed files with 891 additions and 319 deletions

View File

@@ -0,0 +1,44 @@
import {defineStore} from "pinia";
import {isNotEmpty} from "@/helpers.js";
import {storeOrder} from "@/utils/ftch.js";
import {useCartStore} from "@/stores/CartStore.js";
export const useCheckoutStore = defineStore('checkout', {
state: () => ({
customer: {
firstName: "Иван",
lastName: "Васильевич",
email: "ival_vasil@mail.ru",
phone: "+79999999999",
address: "Москва, Красная площадь, 1",
comment: "Доставить срочно❗️",
},
validationErrors: {},
}),
getters: {
hasError: (state) => {
return (field) => isNotEmpty(state.validationErrors[field]);
},
},
actions: {
async makeOrder() {
await storeOrder(this.customer)
.catch(error => {
if (error.response?.status === 422) {
this.validationErrors = error.response._data.data;
} else {
console.error('Unexpected error', error);
}
});
await useCartStore().getProducts();
},
clearError(field) {
this.validationErrors[field] = null;
}
},
});