+
+
{{
- t('ecloud-accounts', 'We are going to proceed with your cloud account suppression.')
+ t(appName, 'We are going to proceed with your cloud account suppression.')
}}
-
+
{{
- t('ecloud-accounts', 'Check the box below if you also want to delete the associated shop account.')
+ t(appName, 'Check the box below if you also want to delete the associated shop account(s).')
}}
+
-
+
+
+ {{
+ t(appName, 'A subscription is active in this account. Please cancel it or let it expire before deleting your account.')
+ }}
+
+
+
-
- {{
- t(
- "drop_account",
- "You are the only user of this instance, you can't delete your account."
- )
- }}
-
-
- {{
- t(
- "drop_account",
- "You are the only admin of this instance, you can't delete your account."
- )
- }}
-
@@ -82,55 +69,48 @@ import Axios from '@nextcloud/axios'
import { generateUrl } from '@nextcloud/router'
import { showError } from '@nextcloud/dialogs'
+const APPLICATION_NAME = 'ecloud-accounts'
+
export default {
- name: 'PersonalSettings',
+ name: 'DeleteShopAccountSetting',
components: {
SettingsSection,
},
data() {
return {
- shopUserExists: false,
- shopUser: {},
- deleteShopAccount: false,
- shopEmailPostDelete: '',
- shopEmailDefault: '',
- appName: 'ecloud-accounts',
- userEmail: '',
- onlyAdmin: false,
- onlyUser: false,
- orderCount: 0,
- subscriptionCount: 0,
- ordersDescription: this.t('ecloud-accounts', "For your information you have %d order(s) in
your account."),
- subscriptionDescription: this.t('ecloud-accounts', 'A subscription is active in this account. Please cancel it or let it expire before deleting your account.'),
- loading: true,
+ shopUsers: [],
+ deleteShopAccount: loadState(APPLICATION_NAME, 'delete_shop_account'),
+ shopEmailPostDelete: loadState(APPLICATION_NAME, 'shop_email_post_delete'),
+ appName: APPLICATION_NAME,
+ userEmail: loadState(APPLICATION_NAME, 'email'),
showError: false,
allowDelete: true,
+ ordersDescription: ''
}
},
- created() {
- try {
- this.onlyUser = loadState(this.appName, 'only_user')
- this.onlyAdmin = loadState(this.appName, 'only_admin')
- this.deleteShopAccount = loadState(this.appName, 'delete_shop_account')
- this.shopEmailPostDelete = loadState(this.appName, 'shop_email_post_delete')
- this.shopEmailDefault = loadState(this.appName, 'shop_email_post_delete')
- this.userEmail = loadState(this.appName, 'email')
- this.getShopUser().then(() => {
- if (this.shopUserExists) {
- this.getOrdersInfo()
- this.getSubscriptionInfo()
- } else {
- this.disableOrEnableDeleteAccount()
+ computed: {
+ hasActiveSubscription() {
+ for (let index = 0; index < this.shopUsers.length; index++) {
+ if (this.shopUsers[index].has_active_subscription) {
+ return true
}
-
- })
- } catch (e) {
- console.error('Error fetching initial state', e)
+ }
+ return false
+ },
+ orderCount() {
+ return this.shopUsers.reduce((accumulator, user) => {
+ return accumulator + user.order_count
+ }, 0)
}
},
+ mounted() {
+ this.getShopUsers()
+ },
methods: {
async disableOrEnableDeleteAccount() {
- if (this.shopUserExists && !this.deleteShopAccount) {
+ if (!this.allowDelete || this.hasActiveSubscription) {
+ this.disableDeleteAccountEvent()
+ } else if (this.shopUsers.length > 0 && !this.deleteShopAccount) {
this.disableDeleteAccountEvent()
const status = await this.checkShopEmailPostDelete()
if (status === 200) {
@@ -159,60 +139,40 @@ export default {
return err.response.status
}
},
- async getShopUser() {
- try {
- const url = generateUrl(
- `/apps/${this.appName}/shop-accounts/user`
- )
- const { status, data } = await Axios.get(url)
- if (status === 200) {
- this.shopUserExists = true
- this.shopUser = data
- }
- if (status === 400) {
- this.enableDeleteAccountEvent()
- }
- } catch (e) {
+ setOrderDescription() {
+ if (this.shopUsers.length === 1) {
+ const ordersDescription = this.t(APPLICATION_NAME, "For your information you have %d order(s) in
your account.")
+ const myOrdersUrl = this.shopUsers[0].my_orders_url
+ this.ordersDescription = ordersDescription.replace('%d', this.orderCount).replace('%s', myOrdersUrl)
+ } else if (this.shopUsers.length >= 1) {
+ let ordersDescription = this.t(APPLICATION_NAME, 'For your information you have %d order(s) in your accounts: ')
+
+ ordersDescription = ordersDescription.replace('%d', this.orderCount)
+
+ const links = this.shopUsers.map((user, index) => {
+ return `
[${index}]`
+ })
+ this.ordersDescription = ordersDescription + links.join(' ')
}
},
- async getOrdersInfo() {
+ async getShopUsers() {
try {
const url = generateUrl(
- `/apps/${this.appName}/shop-accounts/order_info?userId=${this.shopUser.id}`
+ `/apps/${this.appName}/shop-accounts/users`
)
- const { status, data } = await Axios.get(url)
- if (status === 200) {
- this.orderCount = data.order_count
- if (this.orderCount) {
- this.ordersDescription = this.ordersDescription.replace('%d', this.orderCount).replace('%s', data.my_orders_url)
- }
- }
- this.loading = false
+ const { data } = await Axios.get(url)
+ this.shopUsers = data
+ this.setOrderDescription()
} catch (e) {
- this.loading = false
- }
- },
- async getSubscriptionInfo() {
- try {
- const url = generateUrl(
- `/apps/${this.appName}/shop-accounts/subscription_info?userId=${this.shopUser.id}`
- )
- const { status, data } = await Axios.get(url)
- if (status === 200) {
- this.subscriptionCount = data.subscription_count
- if (this.subscriptionCount > 0) {
- this.disableDeleteAccountEvent()
- }
+ if (e.response.status !== 404) {
+ this.disableDeleteAccountEvent()
+ showError(
+ t(APPLICATION_NAME, 'Temporary error contacting murena.com; please try again later!')
+ )
+ this.allowDelete = false
}
- this.loading = false
- } catch (e) {
- this.disableDeleteAccountEvent()
- showError(
- t('ecloud-accounts', 'Temporary error contacting murena.com; please try again later!')
- )
- this.loading = false
- this.allowDelete = false
}
+ this.disableOrEnableDeleteAccount()
},
async updateDeleteShopPreference() {
await this.disableOrEnableDeleteAccount()
@@ -225,12 +185,12 @@ export default {
})
if (status !== 200) {
showError(
- t('ecloud-accounts', 'Error while setting shop delete preference')
+ t(APPLICATION_NAME, 'Error while setting shop delete preference')
)
}
} catch (e) {
showError(
- t('ecloud-accounts', 'Error while setting shop delete preference')
+ t(APPLICATION_NAME, 'Error while setting shop delete preference')
)
}
},
@@ -254,7 +214,7 @@ export default {
if (this.shopEmailPostDelete === this.userEmail) {
showError(
t(
- 'ecloud-accounts',
+ APPLICATION_NAME,
"Murena.com email cannot be same as this account's email."
)
)
@@ -264,7 +224,7 @@ export default {
this.disableDeleteAccountEvent()
showError(
t(
- 'ecloud-accounts',
+ APPLICATION_NAME,
data.message
)
)
diff --git a/src/delete-account-listeners.js b/src/delete-account-listeners.js
index 6710f7ffb1a6cb2a0cff32bc1155db3aa49a0c1b..a8a190b83c9493afcb9b2760df29a3b2d42a4fb1 100644
--- a/src/delete-account-listeners.js
+++ b/src/delete-account-listeners.js
@@ -1,17 +1,19 @@
document.addEventListener('DOMContentLoaded', function() {
+ const checkboxSelector = '#delete-account-settings .checkbox-radio-switch__input'
+ const buttonSelector = '#delete-account-settings .delete-button-wrapper .button-vue'
// Disable initially
- document.getElementById('drop_account_confirm').disabled = true
- document.getElementById('deleteaccount').disabled = true
+ document.querySelector(checkboxSelector).disabled = true
+ document.querySelector(buttonSelector).disabled = true
const elem = document.getElementById('body-settings')
elem.addEventListener('disable-delete-account', function() {
- document.getElementById('deleteaccount').disabled = true
- document.getElementById('drop_account_confirm').disabled = true
+ document.querySelector(checkboxSelector).disabled = true
+ document.querySelector(buttonSelector).disabled = true
})
elem.addEventListener('enable-delete-account', function() {
- document.getElementById('drop_account_confirm').disabled = false
- const enableDeleteAccount = document.getElementById('drop_account_confirm').checked
- document.getElementById('deleteaccount').disabled = !enableDeleteAccount
+ document.querySelector(checkboxSelector).disabled = false
+ const enableDeleteAccount = document.querySelector(checkboxSelector).checked
+ document.querySelector(buttonSelector).disabled = !enableDeleteAccount
})
})
diff --git a/src/personal.js b/src/delete-shop-account-setting.js
similarity index 69%
rename from src/personal.js
rename to src/delete-shop-account-setting.js
index ad8127b06dc7209c7e76a4d158b16ca4332333c8..4ab00df513b1b2bbc41605a2e6a1346f3d1529df 100644
--- a/src/personal.js
+++ b/src/delete-shop-account-setting.js
@@ -1,6 +1,6 @@
import Vue from 'vue'
import './common.js'
-import PersonalSettings from './PersonalSettings.vue'
+import PersonalSettings from './DeleteShopAccountSetting.vue'
export default new Vue({
el: '#ecloud-accounts-settings',
diff --git a/webpack.config.js b/webpack.config.js
index ea2fb2f24f4bfa34237c2e5730ccd414046f241a..b2b5fbb06e3dab6d263b633238ec3df4ac9b523d 100644
--- a/webpack.config.js
+++ b/webpack.config.js
@@ -6,7 +6,7 @@ const path = require('path')
module.exports = {
...webpackConfig,
entry: {
- 'personal-settings': path.join(__dirname, 'src/personal.js'),
+ 'delete-shop-account-setting': path.join(__dirname, 'src/delete-shop-account-setting.js'),
'delete-account-listeners': path.join(__dirname, 'src/delete-account-listeners.js'),
'beta-user-setting': path.join(__dirname, 'src/beta-user-setting.js'),
},