WIP
This commit is contained in:
@@ -16,7 +16,7 @@ export const useCartStore = defineStore('cart', {
|
||||
|
||||
getters: {
|
||||
canCheckout: (state) => {
|
||||
if (state.isLoading) {
|
||||
if (state.isLoading || state.error_warning.length > 0) {
|
||||
return false;
|
||||
}
|
||||
},
|
||||
|
||||
@@ -15,6 +15,7 @@ export const useCheckoutStore = defineStore('checkout', {
|
||||
tgData: null,
|
||||
},
|
||||
|
||||
isLoading: false,
|
||||
validationErrors: {},
|
||||
}),
|
||||
|
||||
@@ -27,19 +28,28 @@ export const useCheckoutStore = defineStore('checkout', {
|
||||
actions: {
|
||||
async makeOrder() {
|
||||
try {
|
||||
this.isLoading = true;
|
||||
const data = window.Telegram.WebApp.initDataUnsafe;
|
||||
|
||||
if (! data.allows_write_to_pm) {
|
||||
await window.Telegram.WebApp.requestWriteAccess((granted) => {
|
||||
if (granted) {
|
||||
console.log('Пользователь разрешил отправку сообщений');
|
||||
} else {
|
||||
alert('Вы не дали разрешение — бот не сможет отправлять вам уведомления');
|
||||
}
|
||||
console.log("Allows write to PM: ", data.user.allows_write_to_pm);
|
||||
|
||||
if (! data.user.allows_write_to_pm) {
|
||||
console.log("Sending request");
|
||||
const granted = await new Promise(resolve => {
|
||||
window.Telegram.WebApp.requestWriteAccess((granted) => {
|
||||
resolve(granted);
|
||||
});
|
||||
});
|
||||
|
||||
if (granted) {
|
||||
data.user.allows_write_to_pm = true;
|
||||
console.log('Пользователь разрешил отправку сообщений');
|
||||
} else {
|
||||
alert('Вы не дали разрешение — бот не сможет отправлять вам уведомления');
|
||||
}
|
||||
}
|
||||
|
||||
this.customer.tgData = data.user;
|
||||
this.customer.tgData = data;
|
||||
await storeOrder(this.customer);
|
||||
await window.Telegram.WebApp.HapticFeedback.notificationOccurred('success');
|
||||
await useCartStore().getProducts();
|
||||
@@ -53,6 +63,8 @@ export const useCheckoutStore = defineStore('checkout', {
|
||||
window.Telegram.WebApp.HapticFeedback.notificationOccurred('error');
|
||||
|
||||
throw error;
|
||||
} finally {
|
||||
this.isLoading = false;
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
Reference in New Issue
Block a user