aboutsummaryrefslogtreecommitdiffstats
path: root/apps/settings/src/components/PersonalInfo/ProfileSection/ProfileCheckbox.vue
diff options
context:
space:
mode:
Diffstat (limited to 'apps/settings/src/components/PersonalInfo/ProfileSection/ProfileCheckbox.vue')
-rw-r--r--apps/settings/src/components/PersonalInfo/ProfileSection/ProfileCheckbox.vue79
1 files changed, 26 insertions, 53 deletions
diff --git a/apps/settings/src/components/PersonalInfo/ProfileSection/ProfileCheckbox.vue b/apps/settings/src/components/PersonalInfo/ProfileSection/ProfileCheckbox.vue
index d7e78915c5d..6eb7cf8c34c 100644
--- a/apps/settings/src/components/PersonalInfo/ProfileSection/ProfileCheckbox.vue
+++ b/apps/settings/src/components/PersonalInfo/ProfileSection/ProfileCheckbox.vue
@@ -1,49 +1,34 @@
<!--
- - @copyright 2021, Christopher Ng <chrng8@gmail.com>
- -
- - @author Christopher Ng <chrng8@gmail.com>
- -
- - @license GNU AGPL version 3 or any later version
- -
- - This program is free software: you can redistribute it and/or modify
- - it under the terms of the GNU Affero General Public License as
- - published by the Free Software Foundation, either version 3 of the
- - License, or (at your option) any later version.
- -
- - This program is distributed in the hope that it will be useful,
- - but WITHOUT ANY WARRANTY; without even the implied warranty of
- - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- - GNU Affero General Public License for more details.
- -
- - You should have received a copy of the GNU Affero General Public License
- - along with this program. If not, see <http://www.gnu.org/licenses/>.
- -
+ - SPDX-FileCopyrightText: 2021 Nextcloud GmbH and Nextcloud contributors
+ - SPDX-License-Identifier: AGPL-3.0-or-later
-->
<template>
<div class="checkbox-container">
- <input id="enable-profile"
- class="checkbox"
- type="checkbox"
- :checked="profileEnabled"
- @change="onEnableProfileChange">
- <label for="enable-profile">
- {{ t('settings', 'Enable Profile') }}
- </label>
+ <NcCheckboxRadioSwitch type="switch"
+ :checked.sync="isProfileEnabled"
+ :loading="loading"
+ @update:checked="saveEnableProfile">
+ {{ t('settings', 'Enable profile') }}
+ </NcCheckboxRadioSwitch>
</div>
</template>
<script>
-import { showError } from '@nextcloud/dialogs'
import { emit } from '@nextcloud/event-bus'
-import { savePrimaryAccountProperty } from '../../../service/PersonalInfo/PersonalInfoService'
-import { validateBoolean } from '../../../utils/validate'
-import { ACCOUNT_PROPERTY_ENUM } from '../../../constants/AccountPropertyConstants'
+import { savePrimaryAccountProperty } from '../../../service/PersonalInfo/PersonalInfoService.js'
+import { ACCOUNT_PROPERTY_ENUM } from '../../../constants/AccountPropertyConstants.js'
+import NcCheckboxRadioSwitch from '@nextcloud/vue/components/NcCheckboxRadioSwitch'
+import { handleError } from '../../../utils/handlers.ts'
export default {
name: 'ProfileCheckbox',
+ components: {
+ NcCheckboxRadioSwitch,
+ },
+
props: {
profileEnabled: {
type: Boolean,
@@ -53,25 +38,18 @@ export default {
data() {
return {
- initialProfileEnabled: this.profileEnabled,
+ isProfileEnabled: this.profileEnabled,
+ loading: false,
}
},
methods: {
- async onEnableProfileChange(e) {
- const isEnabled = e.target.checked
- this.$emit('update:profile-enabled', isEnabled)
-
- if (validateBoolean(isEnabled)) {
- await this.updateEnableProfile(isEnabled)
- }
- },
-
- async updateEnableProfile(isEnabled) {
+ async saveEnableProfile() {
+ this.loading = true
try {
- const responseData = await savePrimaryAccountProperty(ACCOUNT_PROPERTY_ENUM.PROFILE_ENABLED, isEnabled)
+ const responseData = await savePrimaryAccountProperty(ACCOUNT_PROPERTY_ENUM.PROFILE_ENABLED, this.isProfileEnabled)
this.handleResponse({
- isEnabled,
+ isProfileEnabled: this.isProfileEnabled,
status: responseData.ocs?.meta?.status,
})
} catch (e) {
@@ -82,19 +60,14 @@ export default {
}
},
- handleResponse({ isEnabled, status, errorMessage, error }) {
+ handleResponse({ isProfileEnabled, status, errorMessage, error }) {
if (status === 'ok') {
- // Ensure that local state reflects server state
- this.initialProfileEnabled = isEnabled
- emit('settings:profile-enabled:updated', isEnabled)
+ emit('settings:profile-enabled:updated', isProfileEnabled)
} else {
- showError(errorMessage)
- this.logger.error(errorMessage, error)
+ handleError(error, errorMessage)
}
+ this.loading = false
},
},
}
</script>
-
-<style lang="scss" scoped>
-</style>