From 55c7bcf91c5475b8a9832e8989dc58fe91f98cdc Mon Sep 17 00:00:00 2001 From: Natanael Rodriguez Ramos Date: Wed, 25 Oct 2023 12:17:28 +0100 Subject: [PATCH 1/3] bug: Fixed product switch logic --- src/themes/ivpn-v3/assets/js/api/api.js | 12 ++++ .../ivpn-v3/assets/js/store/module_product.js | 9 +++ .../Account/ChangeProduct/ChangeProduct.vue | 59 ++++++++----------- 3 files changed, 47 insertions(+), 33 deletions(-) diff --git a/src/themes/ivpn-v3/assets/js/api/api.js b/src/themes/ivpn-v3/assets/js/api/api.js index dd22c9f98..71d2da53d 100644 --- a/src/themes/ivpn-v3/assets/js/api/api.js +++ b/src/themes/ivpn-v3/assets/js/api/api.js @@ -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( diff --git a/src/themes/ivpn-v3/assets/js/store/module_product.js b/src/themes/ivpn-v3/assets/js/store/module_product.js index b948febda..cd7d3a638 100644 --- a/src/themes/ivpn-v3/assets/js/store/module_product.js +++ b/src/themes/ivpn-v3/assets/js/store/module_product.js @@ -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: { diff --git a/src/themes/ivpn-v3/assets/js/views/Account/ChangeProduct/ChangeProduct.vue b/src/themes/ivpn-v3/assets/js/views/Account/ChangeProduct/ChangeProduct.vue index 184785079..03736d38f 100644 --- a/src/themes/ivpn-v3/assets/js/views/Account/ChangeProduct/ChangeProduct.vue +++ b/src/themes/ivpn-v3/assets/js/views/Account/ChangeProduct/ChangeProduct.vue @@ -15,7 +15,7 @@
@@ -36,7 +36,7 @@
Will be active until:
- {{ $filters.formatActiveUntil(activeUntilStandard) }} + {{ standardActiveUntil }} * @@ -47,7 +47,7 @@ @@ -66,7 +66,7 @@
Will be active until:
- {{ $filters.formatActiveUntil(activeUntilPro) }} + {{ proActiveUntil }} * @@ -90,11 +90,28 @@ import { add, differenceInMinutes } from "date-fns"; import { mapState } from "vuex"; export default { + data() { + return { + standardActiveUntil: null, + proActiveUntil: null, + lockedPlan : false, + }; + }, 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.lockedPlan = proPlan.is_locked; + this.standardActiveUntil =this.$filters.formatActiveUntil(standardActiveUntil); + this.proActiveUntil = this.$filters.formatActiveUntil(proPlan.active_until); + }, + + methods: { async selected(newProductName) { await this.$store.dispatch("product/change", newProductName); @@ -111,44 +128,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"); - } } }; From b15b8e8180b9f32129584c65fdf0c0b18a60eca3 Mon Sep 17 00:00:00 2001 From: Natanael Rodriguez Ramos Date: Thu, 26 Oct 2023 10:42:41 +0100 Subject: [PATCH 2/3] bug: Fixed product switch logic --- .../assets/js/views/Account/Account.vue | 18 +++++++++++++++--- .../Account/ChangeProduct/ChangeProduct.vue | 13 ++++++++----- 2 files changed, 23 insertions(+), 8 deletions(-) diff --git a/src/themes/ivpn-v3/assets/js/views/Account/Account.vue b/src/themes/ivpn-v3/assets/js/views/Account/Account.vue index 13d51520e..65d3d1d36 100644 --- a/src/themes/ivpn-v3/assets/js/views/Account/Account.vue +++ b/src/themes/ivpn-v3/assets/js/views/Account/Account.vue @@ -46,7 +46,7 @@
{{ account.product.name }}
-
+
Change @@ -113,7 +113,8 @@ export default { data() { return { - isLight : false + isLight : false, + canChange: false, }; }, @@ -124,13 +125,24 @@ export default { }, - beforeMount(){ + async beforeMount(){ if( this.$store.state.auth.account.product.name == "IVPN Light"){ this.isLight = true; window.location = "/light"; } + 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, + }); + } + + } + }; diff --git a/src/themes/ivpn-v3/assets/js/views/Account/ChangeProduct/ChangeProduct.vue b/src/themes/ivpn-v3/assets/js/views/Account/ChangeProduct/ChangeProduct.vue index 03736d38f..2067f0da0 100644 --- a/src/themes/ivpn-v3/assets/js/views/Account/ChangeProduct/ChangeProduct.vue +++ b/src/themes/ivpn-v3/assets/js/views/Account/ChangeProduct/ChangeProduct.vue @@ -1,5 +1,5 @@