success modal and fix redirects

This commit is contained in:
Matteo Pagliazzi
2018-12-02 17:33:21 +01:00
parent e212842b50
commit b9e12aca3e
5 changed files with 110 additions and 21 deletions

View File

@@ -36,6 +36,7 @@ import { mapState } from 'client/libs/store';
import { CONSTANTS, setLocalSetting } from 'client/libs/userlocalManager';
const AMAZON_PAYMENTS = process.env.AMAZON_PAYMENTS; // eslint-disable-line
const habiticaUrl = `${location.protocol}//${location.host}`;
export default {
data () {
@@ -187,13 +188,17 @@ export default {
new this.OffAmazonPayments.Widgets.Wallet(walletParams).bind('AmazonPayWallet');
},
storePaymentStatusAndReload () {
storePaymentStatusAndReload (url) {
const appState = {
paymentMethod: 'amazon',
paymentCompleted: true,
};
setLocalSetting(CONSTANTS.savedAppStateValues.SAVED_APP_STATE, JSON.stringify(appState));
window.location.reload(true);
if (url) {
window.location.assign(url);
} else {
window.location.reload(true);
}
},
async amazonCheckOut () {
this.amazonButtonEnabled = false;
@@ -239,8 +244,6 @@ export default {
if (newGroup && newGroup._id) {
// Handle new user signup
if (!this.$store.state.isUserLoggedIn) {
const habiticaUrl = `${location.protocol}//${location.host}`;
Analytics.track({
hitType: 'event',
eventCategory: 'group-plans-static',
@@ -248,21 +251,17 @@ export default {
eventLabel: 'paid-with-amazon',
});
location.href = `${habiticaUrl}/group-plans/${newGroup._id}/task-information?showGroupOverview=true`;
this.storePaymentStatusAndReload();
this.storePaymentStatusAndReload(`${habiticaUrl}/group-plans/${newGroup._id}/task-information?showGroupOverview=true`);
return;
}
// @TODO: Just append? or $emit?
this.$router.push(`/group-plans/${newGroup._id}/task-information`);
this.user.guilds.push(newGroup._id);
this.storePaymentStatusAndReload();
this.storePaymentStatusAndReload(`${habiticaUrl}/group-plans/${newGroup._id}/task-information`);
return;
}
if (this.amazonPayments.groupId) {
this.$router.push(`/group-plans/${this.amazonPayments.groupId}/task-information`);
this.storePaymentStatusAndReload();
this.storePaymentStatusAndReload(`${habiticaUrl}/group-plans/${this.amazonPayments.groupId}/task-information`);
return;
}