Unload order when order check fails #83

Merged
jsegarra merged 4 commits from wbuezas/hedera-web-mindshore:feature/UnloadOrder into 4922-vueMigration 2024-09-11 06:30:04 +00:00
1 changed files with 23 additions and 18 deletions

View File

@ -5,6 +5,7 @@ import { i18n } from 'src/boot/i18n';
import { useQuasar } from 'quasar';
const { notify } = useNotify();
const storageOrderName = 'hederaBasket';
export const useAppStore = defineStore('hedera', {
state: () => ({
@ -72,7 +73,7 @@ export const useAppStore = defineStore('hedera', {
},
getBasketOrderId() {
this.basketOrderId = localStorage.getItem('hederaBasket');
this.basketOrderId = localStorage.getItem(storageOrderName);
},
async checkOrder(orderId) {
@ -97,22 +98,21 @@ export const useAppStore = defineStore('hedera', {
await this.checkOrder(this.basketOrderId);
return true;
} catch (err) {
if (err.exception === 'Vn.Lib.UserError') {
switch (err.code) {
case 'orderConfirmed':
case 'orderNotOwnedByUser':
await this.redirect();
break;
default:
this.router.push({
name: 'checkout',
params: { id: this.basketOrderId },
query: { continue: checkoutContinue }
});
notify(err.message, 'negative');
}
return false;
} else throw err;
switch (err.code) {
case 'orderConfirmed':
case 'orderNotOwnedByUser':
this.unloadOrder();
await this.redirect();
break;
default:
this.router.push({
name: 'checkout',
params: { id: this.basketOrderId },
query: { continue: checkoutContinue }
});
notify(err.message, 'negative');
}
return false;
}
},
@ -131,9 +131,14 @@ export const useAppStore = defineStore('hedera', {
loadIntoBasket(orderId) {
if (this.basketOrderId !== orderId) {
this.basketOrderId = orderId;
localStorage.setItem('hederaBasket', orderId);
localStorage.setItem(storageOrderName, orderId);
notify('orderLoadedIntoBasket', 'positive');
}
},
unloadOrder() {
Review

Es una tontería, pero podemos definir como constante la palabra hederaBasket y reemplazar en las 3 ocurrencias?

Es una tontería, pero podemos definir como constante la palabra hederaBasket y reemplazar en las 3 ocurrencias?
Review

Aplicado.

Commit: 93e739f35c

Aplicado. Commit: https://gitea.verdnatura.es/verdnatura/hedera-web/commit/93e739f35c144e5452da9504135e6d9b8bffa6c2
localStorage.removeItem(storageOrderName);
this.basketOrderId = null;
}
},
getters: {