0
1
Fork 0

Merge pull request 'Unload order when order check fails' (!83) from wbuezas/hedera-web-mindshore:feature/UnloadOrder into 4922-vueMigration

Reviewed-on: verdnatura/hedera-web#83
This commit is contained in:
Javier Segarra 2024-09-11 06:30:03 +00:00
commit facb565d26
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() {
localStorage.removeItem(storageOrderName);
this.basketOrderId = null;
}
},
getters: {