Ask for confirmation when buying quests (#11251)

* Trigger confirmation modal for quests that have a currency of gems

https://github.com/HabitRPG/habitica/issues/11244

* Trigger purchase confirmation dialog for gold-purchasable quests

* Refactor to use confirmPurchase method
This commit is contained in:
Dominick Triola 2019-07-12 08:09:49 -07:00 committed by Matteo Pagliazzi
parent 2e227909a4
commit 631efd1adc
4 changed files with 16 additions and 7 deletions

View file

@ -402,13 +402,8 @@
return;
}
if (this.item.currency === 'gems' &&
!confirm(this.$t('purchaseFor', { cost: this.item.value * this.selectedAmountToBuy }))) {
return;
}
if (this.item.currency === 'hourglasses' &&
!confirm(this.$t('purchaseForHourglasses', { cost: this.item.value }))) {
const shouldConfirmPurchase = this.item.currency === 'gems' || this.item.currency === 'hourglasses';
if (shouldConfirmPurchase && !this.confirmPurchase(this.item.currency, this.item.value * this.selectedAmountToBuy)) {
return;
}

View file

@ -265,6 +265,9 @@
this.$emit('change', $event);
},
buyItem () {
if (!this.confirmPurchase(this.item.currency, this.item.value * this.selectedAmountToBuy)) {
return;
}
this.makeGenericPurchase(this.item, 'buyQuestModal', this.selectedAmountToBuy);
this.purchased(this.item.text);
this.hideDialog();

View file

@ -32,5 +32,15 @@ export default {
this.$root.$emit('buyModal::boughtItem', item);
},
confirmPurchase (currency, cost) {
const currencyToPurchaseForKey = {
gems: 'purchaseFor',
gold: 'purchaseForGold',
hourglasses: 'purchaseForHourglasses',
};
const purchaseForKey = currencyToPurchaseForKey[currency];
return confirm(this.$t(purchaseForKey, { cost }));
},
},
};

View file

@ -169,6 +169,7 @@
"dieText": "You've lost a Level, all your Gold, and a random piece of Equipment. Arise, Habiteer, and try again! Curb those negative Habits, be vigilant in completion of Dailies, and hold death at arm's length with a Health Potion if you falter!",
"sureReset": "Are you sure? This will reset your character's class and allocated Stat Points (you'll get them all back to re-allocate), and costs 3 Gems.",
"purchaseFor": "Purchase for <%= cost %> Gems?",
"purchaseForGold": "Purchase for <%= cost %> Gold?",
"purchaseForHourglasses": "Purchase for <%= cost %> Hourglasses?",
"notEnoughMana": "Not enough mana.",
"invalidTarget": "You can't cast a skill on that.",