Skip to content

Commit

Permalink
wip: better group plan cancellation
Browse files Browse the repository at this point in the history
  • Loading branch information
paglias committed Apr 23, 2019
1 parent e4eca4b commit 8c67ad7
Show file tree
Hide file tree
Showing 6 changed files with 182 additions and 8 deletions.
3 changes: 3 additions & 0 deletions website/client/assets/svg/exclamation.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 6 additions & 1 deletion website/client/components/group-plans/billing.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<template lang="pug">
.row.standard-page(v-if='groupIsSubscribed && isLeader')
cancel-modal-confirm
.col-12.col-md-6.offset-md-3
table.table.alert.alert-info
tr(v-if='group.purchased.plan.dateTerminated')
Expand Down Expand Up @@ -29,15 +30,19 @@
.btn.btn-primary(v-if='!group.purchased.plan.dateTerminated && group.purchased.plan.paymentMethod === "Stripe"',
@click='showStripeEdit({groupId: group.id})') {{ $t('subUpdateCard') }}
.btn.btn-sm.btn-danger(v-if='!group.purchased.plan.dateTerminated',
@click='cancelSubscription({group: group})') {{ $t('cancelGroupSub') }}
@click='cancelGroupPlanSubscription({group: group})') {{ $t('cancelGroupSub') }}
</template>

<script>
import moment from 'moment';
import { mapState } from 'client/libs/store';
import paymentsMixin from 'client/mixins/payments';
import cancelModalConfirm from 'client/components/group-plans/cancelModalConfirm';
export default {
components: {
cancelModalConfirm,
},
mixins: [paymentsMixin],
props: ['groupId'],
data () {
Expand Down
158 changes: 158 additions & 0 deletions website/client/components/group-plans/cancelModalConfirm.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
<template lang="pug">
b-modal#group-plan-cancel-modal(
size='sm',
:hideFooter="true",
:modalClass="['modal-hidden-footer']"
)
div(slot="modal-header")
.warning-container.d-flex.align-items-center.justify-content-center
.svg-icon.warning(v-html="icons.warning", v-once)
.row
.col-12.modal-body-col
h2(v-once) {{ $t('cancelGroupSub') }}
span.cancel-text(v-once) {{ $t('confirmCancelGroupPlan') }}
button.btn.btn-danger.mt-4.mb-3(v-once, @click="cancelSubscription(config)") {{ $t('cancelGroupSub') }}
a.standard-link(v-once, @click="close()") {{ $t('neverMind') }}
</template>

<style lang="scss">
@import '~client/assets/scss/colors.scss';
#group-plan-cancel-modal .modal-content {
background: transparent;
}
#group-plan-cancel-modal.modal-hidden-footer .modal-body {
border-bottom-right-radius: 8px;
border-bottom-left-radius: 8px;
}
#group-plan-cancel-modal .modal-header {
justify-content: center;
padding-top: 24px;
padding-bottom: 0px;
border-top-right-radius: 8px;
border-top-left-radius: 8px;
border-bottom: none;
background: $white;
border-top: 8px solid $maroon-100;
.warning-container {
width: 64px;
height: 64px;
border-radius: 50%;
background: $maroon-100;
margin: 0 auto;
margin-bottom: 8px;
}
.warning {
width: 7px;
height: 38px;
color: white;
}
}
#group-plan-cancel-modal .modal-body {
padding-top: 16px;
padding-bottom: 24px;
background: white;
.modal-body-col {
display: flex;
flex-direction: column;
align-items: center;
text-align: center;
.btn.btn-primary {
margin-top: 24px;
}
}
h2 {
margin-bottom: 8px;
}
.cancel-text {
color: $gray-50;
line-height: 1.71;
}
.details-block {
background: $gray-700;
border-radius: 4px;
padding: 8px 24px;
margin-top: 16px;
display: flex;
flex-direction: row;
text-align: center;
&.gems {
padding: 12px 16px 12px 20px;
color: $green-10;
font-size: 24px;
font-weight: bold;
line-height: 1.33;
.svg-icon {
margin-right: 8px;
width: 32px;
height: 32px;
}
}
}
.auto-renew {
margin-top: 16px;
color: $orange-10;
font-style: normal;
}
}
#group-plan-cancel-modal .modal-footer {
background: $gray-700;
border-bottom-right-radius: 8px;
border-bottom-left-radius: 8px;
justify-content: center;
border-top: none;
.small-text {
font-style: normal;
}
}
</style>

<script>
import warningIcon from 'assets/svg/exclamation.svg';
import paymentsMixin from 'client/mixins/payments';
import { mapState } from 'client/libs/store';
export default {
mixins: [paymentsMixin],
data () {
return {
icons: Object.freeze({
warning: warningIcon,
}),
config: null,
};
},
computed: {
...mapState({user: 'user.data'}),
},
mounted () {
this.$root.$on('habitica:cancel-group-plan', (config) => {
this.config = config;
this.$root.$emit('bv::show::modal', 'group-plan-cancel-modal');
});
},
destroyed () {
this.$root.$off('habitica:cancel-group-plan');
},
methods: {
close () {
this.$root.$emit('bv::hide::modal', 'group-plan-cancel-modal');
},
},
};
</script>
18 changes: 13 additions & 5 deletions website/client/mixins/payments.js
Original file line number Diff line number Diff line change
Expand Up @@ -275,9 +275,13 @@ export default {
this.amazonPayments.groupToCreate = null;
this.amazonPayments.group = null;
},
cancelGroupPlanSubscription (config) {
this.$root.$emit('habitica:cancel-group-plan', config);
},
async cancelSubscription (config) {
if (config && config.group && !confirm(this.$t('confirmCancelGroupPlan'))) return;
if (!confirm(this.$t('sureCancelSub'))) return;
if (!config || !config.group) {
if (!confirm(this.$t('sureCancelSub'))) return;
}

this.loading = true;

Expand Down Expand Up @@ -309,9 +313,13 @@ export default {
const cancelUrl = `/${paymentMethod}/subscribe/cancel?${encodeParams(queryParams)}`;
await axios.get(cancelUrl);

alert(this.$t('paypalCanceled'));
// @TODO: We should probably update the api to return the new sub data eventually.
await this.$store.dispatch('user:fetch', {forceLoad: true});
if (!config || !config.group) {
alert(this.$t('paypalCanceled'));
// @TODO: We should probably update the api to return the new sub data eventually.
await this.$store.dispatch('user:fetch', {forceLoad: true});
} else {

}

this.loading = false;
} catch (e) {
Expand Down
2 changes: 1 addition & 1 deletion website/common/locales/en/generic.json
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@
"continue": "Continue",
"accept": "Accept",
"reject": "Reject",
"neverMind": "Never mind",
"neverMind": "Nevermind",
"buyMoreGems": "Buy More Gems",
"notEnoughGems": "Not enough Gems",
"alreadyHave": "Whoops! You already have this item. No need to buy it again!",
Expand Down
2 changes: 1 addition & 1 deletion website/common/locales/en/groups.json
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@
"leaderCannotLeaveGroupWithActiveGroup": "A leader can not leave a group while the group has an active plan",
"youHaveGroupPlan": "You have a free subscription because you are a member of a group that has a Group Plan. This will end when you are no longer in the group that has a Group Plan. Any months of extra subscription credit you have will be applied at the end of the Group Plan.",
"cancelGroupSub": "Cancel Group Plan",
"confirmCancelGroupPlan": "Are you sure you want to cancel the group plan and remove its benefits from all members, including their free subscriptions?",
"confirmCancelGroupPlan": "Are you sure you want to cancel your Group Plan? All Group members will lose their subscription and benefits.",
"canceledGroupPlan": "Canceled Group Plan",
"groupPlanCanceled": "Group Plan will become inactive on",
"purchasedGroupPlanPlanExtraMonths": "You have <%= months %> months of extra group plan credit.",
Expand Down

0 comments on commit 8c67ad7

Please sign in to comment.