-
-
Notifications
You must be signed in to change notification settings - Fork 5.1k
Expand file tree
/
Copy pathEditUserDialog.vue
More file actions
172 lines (154 loc) · 3.94 KB
/
Copy pathEditUserDialog.vue
File metadata and controls
172 lines (154 loc) · 3.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
<!--
- SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors
- SPDX-License-Identifier: AGPL-3.0-or-later
-->
<template>
<NcDialog
class="edit-dialog"
size="small"
:name="t('settings', 'Edit account')"
outTransition
:noClose="saving"
@closing="$emit('closing')">
<form
id="edit-user-form"
class="edit-dialog__form"
data-test="form"
:inert="saving"
:aria-busy="saving ? 'true' : 'false'"
@submit.prevent="save">
<UserFormFields
:fieldConfig="fieldConfig"
:errors="fieldErrors"
:quotaOptions="quotaOptions" />
</form>
<template #actions>
<NcButton
class="edit-dialog__submit"
data-test="submit"
form="edit-user-form"
variant="primary"
type="submit"
:aria-disabled="saving ? 'true' : 'false'">
<template v-if="saving" #icon>
<NcLoadingIcon />
</template>
{{ saving ? t('settings', 'Saving\u00A0…') : t('settings', 'Save') }}
</NcButton>
</template>
</NcDialog>
</template>
<script>
import { showError, showSuccess } from '@nextcloud/dialogs'
import { confirmPassword } from '@nextcloud/password-confirmation'
import NcButton from '@nextcloud/vue/components/NcButton'
import NcDialog from '@nextcloud/vue/components/NcDialog'
import NcLoadingIcon from '@nextcloud/vue/components/NcLoadingIcon'
import UserFormFields from './UserFormFields.vue'
import logger from '../../logger.ts'
import { diffPayload, userToFormData } from './userFormUtils.ts'
export default {
name: 'EditUserDialog',
components: {
NcButton,
NcDialog,
NcLoadingIcon,
UserFormFields,
},
// Children inject this reactive object and mutate its properties via v-model.
// Do not reassign editedUser entirely, the injected reference would go stale.
provide() {
return {
formData: this.editedUser,
}
},
props: {
user: {
type: Object,
required: true,
},
quotaOptions: {
type: Array,
required: true,
},
},
emits: ['closing'],
data() {
const allGroups = this.$store.getters.getGroups
const serverLanguages = this.$store.getters.getServerData.languages
const formData = userToFormData(this.user, allGroups, this.quotaOptions, serverLanguages)
return {
/** Snapshot of initial state for diffing */
initialData: structuredClone(formData),
/** Mutable form state */
editedUser: formData,
saving: false,
fieldErrors: {},
}
},
computed: {
settings() {
return this.$store.getters.getServerData
},
fieldConfig() {
return {
username: {
show: true,
disabled: true,
label: t('settings', 'Account name'),
},
password: {
show: this.settings.canChangePassword && this.user.backendCapabilities.setPassword,
label: t('settings', 'New password'),
},
}
},
},
methods: {
async save() {
// Guard against re-submit while a request is already running. The
// button is only aria-disabled (not disabled), so it can still fire.
if (this.saving) {
return
}
this.fieldErrors = {}
const payload = diffPayload(this.initialData, this.editedUser)
if (Object.keys(payload).length === 0) {
this.$emit('closing')
return
}
this.saving = true
try {
await confirmPassword()
await this.$store.dispatch('editUserMultiField', {
userid: this.user.id,
payload,
})
showSuccess(t('settings', 'Account updated'))
this.$emit('closing')
} catch (error) {
const errors = error.response?.data?.ocs?.data?.errors
if (errors && typeof errors === 'object') {
this.fieldErrors = errors
} else {
logger.error('Failed to update account', { error })
showError(t('settings', 'Failed to update account'))
}
} finally {
this.saving = false
}
},
},
}
</script>
<style lang="scss" scoped>
.edit-dialog {
:deep(.dialog__actions) {
margin-block-start: calc(var(--default-grid-baseline, 4px) * 3);
}
}
// Visually communicate the locked/busy form while the account is saved.
.edit-dialog__form[aria-busy='true'] {
opacity: 0.5;
}
</style>