Skip to content

Commit

Permalink
Merge pull request #705 from ivpn/bugfix/replace-change-plan-logic
Browse files Browse the repository at this point in the history
Bugfix/replace change plan logic
  • Loading branch information
nathanrod authored Oct 26, 2023
2 parents 78c6a6e + 013e42f commit 9b4ea90
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 35 deletions.
12 changes: 12 additions & 0 deletions src/themes/ivpn-v3/assets/js/api/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,18 @@ export default {

},

async changeProductDetails(newProductName) {
let product = await this.Post(
'/web/accounts/change-product-details',
{
new_product: newProductName.product
}
)

return product

},


async setEmailAuth(email, password) {
await this.Post(
Expand Down
9 changes: 9 additions & 0 deletions src/themes/ivpn-v3/assets/js/store/module_product.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,15 @@ export default {
context.commit('failed', { error })
}
},
async changeDetails(context, newProductName) {
context.commit('started')
try {
context.commit('done')
return await Api.changeProductDetails(newProductName);
} catch (error) {
context.commit('failed', { error })
}
},
},
getters: {

Expand Down
20 changes: 17 additions & 3 deletions src/themes/ivpn-v3/assets/js/views/Account/Account.vue
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
<label>Product</label>
<div class="value">{{ account.product.name }}</div>
</div>
<div class="product-action">
<div class="product-action" v-if="canChange">
<router-link :to="{ name: 'change-product' }"
>Change</router-link
>
Expand Down Expand Up @@ -113,7 +113,8 @@ export default {
data() {
return {
isLight : false
isLight : false,
canChange: false,
};
},
Expand All @@ -124,13 +125,26 @@ export default {
},
beforeMount(){
async beforeMount(){
if( this.$store.state.auth.account.product.name == "IVPN Light"){
this.isLight = true;
window.location = "/light";
}
if( !this.$store.state.auth.account.is_new){
let product= await this.calculateForProduct(this.$store.state.auth.account.product.name).then(response => response);
this.canChange = !product.is_locked;
}
},
methods:{
async calculateForProduct(newProduct) {
return await this.$store.dispatch("product/changeDetails", {
product: newProduct,
});
}
}
};
</script>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<template>
<div>
<div v-if="!isLocked">
<div class="back-link">
<router-link :to="{name:'account'}">
<span class="icon-back"></span>Back to account
Expand Down Expand Up @@ -36,7 +36,7 @@
<div class="label" v-else>Will be active until:</div>

<div class="value">
{{ $filters.formatActiveUntil(activeUntilStandard) }}
{{ standardActiveUntil }}
<sup
v-if="account.product.name != 'IVPN Standard'"
>*</sup>
Expand Down Expand Up @@ -66,7 +66,7 @@
<div class="label" v-else>Will be active until:</div>

<div class="value">
{{ $filters.formatActiveUntil(activeUntilPro) }}
{{ proActiveUntil }}
<sup
v-if="account.product.name != 'IVPN Pro'"
>*</sup>
Expand All @@ -90,11 +90,31 @@ import { add, differenceInMinutes } from "date-fns";
import { mapState } from "vuex";
export default {
data() {
return {
standardActiveUntil: null,
proActiveUntil: null,
isLocked: true,
};
},
components: {
// SignupSection,
PriceBox
},
async beforeMount() {
let standardActiveUntil = await this.calculateForProduct("IVPN Standard").then(response => response.active_until);
let proPlan = await this.calculateForProduct("IVPN Pro").then(response => response);
this.standardActiveUntil =this.$filters.formatActiveUntil(standardActiveUntil);
this.proActiveUntil = this.$filters.formatActiveUntil(proPlan.active_until);
this.isLocked = proPlan.is_locked;
if( proPlan.is_locked ){
window.location = "/account";
}
},
methods: {
async selected(newProductName) {
await this.$store.dispatch("product/change", newProductName);
Expand All @@ -111,44 +131,20 @@ export default {
this.$router.push({ name: "account" });
},
calculateForProduct(newProduct) {
let now = new Date();
let minutesLeft = differenceInMinutes(
new Date(this.account.active_until),
now
);
if (!this.account.is_active || minutesLeft < 0) {
return this.account.active_until;
}
let currentProduct = this.account.product.name;
if (currentProduct == "IVPN Standard" && newProduct == "IVPN Pro") {
return add(now, { minutes: minutesLeft * 0.6 });
}
if (currentProduct == "IVPN Pro" && newProduct == "IVPN Standard") {
return add(now, { minutes: minutesLeft / 0.6 });
}
return this.account.active_until;
async calculateForProduct(newProduct) {
return await this.$store.dispatch("product/changeDetails", {
product: newProduct,
});
}
},
computed: {
...mapState({
account: state => state.auth.account,
products: state => state.product.all,
inProgress: state => state.product.inProgress,
error: state => state.product.error
}),
activeUntilStandard() {
return this.calculateForProduct("IVPN Standard");
},
activeUntilPro() {
return this.calculateForProduct("IVPN Pro");
}
}
};
</script>
Expand Down

0 comments on commit 9b4ea90

Please sign in to comment.