fix(admin): reactivity with subscriptions

This commit is contained in:
SabreCat
2022-09-13 15:52:03 -05:00
parent 0081bad831
commit fb780c9a2d
2 changed files with 8 additions and 22 deletions

View File

@@ -8,7 +8,7 @@
Subscription, Monthly Perks Subscription, Monthly Perks
</h3> </h3>
<div v-if="expand"> <div v-if="expand">
<form @submit.prevent="saveSubscriptionData()"> <form @submit.prevent="saveHero({ hero, msg: 'Subscription Perks' })">
<div v-if="hero.purchased.plan.paymentMethod"> <div v-if="hero.purchased.plan.paymentMethod">
Payment method: Payment method:
<strong>{{ hero.purchased.plan.paymentMethod }}</strong> <strong>{{ hero.purchased.plan.paymentMethod }}</strong>
@@ -34,7 +34,7 @@
<label> <label>
Consecutive months: Consecutive months:
<input <input
v-model="consecutiveMonths" v-model="hero.purchased.plan.consecutive.count"
class="form-control" class="form-control"
type="number" type="number"
min="0" min="0"
@@ -115,7 +115,6 @@
</template> </template>
<script> <script>
import clone from 'lodash/clone';
import moment from 'moment'; import moment from 'moment';
import saveHero from '../mixins/saveHero'; import saveHero from '../mixins/saveHero';
import { getPlanContext } from '@/../../common/script/cron'; import { getPlanContext } from '@/../../common/script/cron';
@@ -130,43 +129,27 @@ export default {
}, },
data () { data () {
return { return {
consecutiveMonths: 0,
expand: false, expand: false,
}; };
}, },
computed: { computed: {
nextHourglassDate () { nextHourglassDate () {
const pendingHero = clone(this.hero); const currentPlanContext = getPlanContext(this.hero, new Date());
pendingHero.purchased.plan.consecutive.count = this.consecutiveMonths;
const currentPlanContext = getPlanContext(pendingHero, new Date());
return currentPlanContext.nextHourglassDate.format('MMMM'); return currentPlanContext.nextHourglassDate.format('MMMM');
}, },
}, },
watch: { watch: {
consecutiveMonths () { 'hero.purchased.plan.consecutive.count' () { // eslint-disable-line object-shorthand
this.hero.purchased.plan.consecutive.gemCapExtra = Math.min( this.hero.purchased.plan.consecutive.gemCapExtra = Math.min(
Math.floor(this.consecutiveMonths / 3) * 5, 25, Math.floor(this.hero.purchased.plan.consecutive.count / 3) * 5, 25,
); );
if (this.hero.purchased.plan.gemsBought
> this.hero.purchased.plan.consecutive.gemCapExtra + 25) {
this.hero.purchased.plan.gemsBought = this.hero.purchased.plan.consecutive.gemCapExtra + 25;
}
}, },
}, },
mounted () {
this.consecutiveMonths = clone(this.hero.purchased.plan.consecutive.count);
},
methods: { methods: {
dateFormat (date) { dateFormat (date) {
return moment(date).format('YYYY/MM/DD'); return moment(date).format('YYYY/MM/DD');
}, },
saveSubscriptionData () {
if (this.consecutiveMonths !== this.hero.purchased.plan.consecutive.count) {
this.hero.purchased.plan.consecutive.count = this.consecutiveMonths;
}
this.saveHero({ hero: this.hero, msg: 'Subscription Perks' });
},
}, },
}; };
</script> </script>

View File

@@ -289,6 +289,9 @@ api.updateHero = {
if (updateData.purchased.plan.consecutive.gemCapExtra) { if (updateData.purchased.plan.consecutive.gemCapExtra) {
hero.purchased.plan.consecutive.gemCapExtra = updateData.purchased.plan.consecutive.gemCapExtra; // eslint-disable-line max-len hero.purchased.plan.consecutive.gemCapExtra = updateData.purchased.plan.consecutive.gemCapExtra; // eslint-disable-line max-len
} }
if (updateData.purchased.plan.consecutive.count) {
hero.purchased.plan.consecutive.count = updateData.purchased.plan.consecutive.count; // eslint-disable-line max-len
}
} }
} }