@fy-/fws-vue 2.3.50 → 2.3.51
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -48,6 +48,9 @@ const state = reactive({
|
|
|
48
48
|
PublicBio: userData.value?.UserProfile?.PublicBio || false,
|
|
49
49
|
PublicBirthdate: userData.value?.UserProfile?.PublicBirthdate || false,
|
|
50
50
|
},
|
|
51
|
+
usernameUpdate: {
|
|
52
|
+
Username: userData.value?.UserProfile?.Username || '',
|
|
53
|
+
},
|
|
51
54
|
})
|
|
52
55
|
watchEffect(() => {
|
|
53
56
|
state.userData = {
|
|
@@ -78,6 +81,11 @@ const rules = {
|
|
|
78
81
|
PublicBio: {},
|
|
79
82
|
PublicBirthdate: {},
|
|
80
83
|
},
|
|
84
|
+
usernameUpdate: {
|
|
85
|
+
Username: {
|
|
86
|
+
required,
|
|
87
|
+
},
|
|
88
|
+
},
|
|
81
89
|
}
|
|
82
90
|
const v$ = useVuelidate(rules, state)
|
|
83
91
|
|
|
@@ -111,6 +119,36 @@ const cropResult = reactive({
|
|
|
111
119
|
blobURL: '',
|
|
112
120
|
})
|
|
113
121
|
const uploader = ref(new Uploader())
|
|
122
|
+
const canUpdateUsername = computed(() => {
|
|
123
|
+
// If user and UserProfile and UserProfile.UsernameChangedAt > 30 days
|
|
124
|
+
if (userData.value?.UserProfile?.UsernameChangedAt?.unixms) {
|
|
125
|
+
const date = new Date(userData.value?.UserProfile?.UsernameChangedAt.unixms)
|
|
126
|
+
const now = new Date()
|
|
127
|
+
const diff = Math.abs(now.getTime() - date.getTime())
|
|
128
|
+
const diffDays = Math.ceil(diff / (1000 * 3600 * 24))
|
|
129
|
+
return diffDays > 30
|
|
130
|
+
}
|
|
131
|
+
return true
|
|
132
|
+
})
|
|
133
|
+
const lastUsernameError = ref('')
|
|
134
|
+
async function updateUsername() {
|
|
135
|
+
eventBus.emit('main-loading', true)
|
|
136
|
+
if (await v$.value.usernameUpdate.$validate()) {
|
|
137
|
+
const data = { ...state.usernameUpdate }
|
|
138
|
+
const response = await rest('User/_Username', 'PATCH', data).catch((err) => {
|
|
139
|
+
eventBus.emit('main-loading', false)
|
|
140
|
+
lastUsernameError.value = err.message
|
|
141
|
+
})
|
|
142
|
+
if (response && response.result === 'success') {
|
|
143
|
+
if (props.onCompleted) {
|
|
144
|
+
props.onCompleted(response)
|
|
145
|
+
}
|
|
146
|
+
eventBus.emit('user:refresh', true)
|
|
147
|
+
eventBus.emit('updateUsernameModal', false)
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
eventBus.emit('main-loading', false)
|
|
151
|
+
}
|
|
114
152
|
|
|
115
153
|
async function getCropResult() {
|
|
116
154
|
if (!cropper) return
|
|
@@ -161,6 +199,30 @@ function selectFile(e: Event) {
|
|
|
161
199
|
|
|
162
200
|
<template>
|
|
163
201
|
<form class="space-y-4" @submit.prevent="patchUser">
|
|
202
|
+
<DefaultModal id="updateUsername" :title="$t('fws_username_update_title')">
|
|
203
|
+
<div class="flex flex-col gap-4">
|
|
204
|
+
<DefaultInput
|
|
205
|
+
id="usernameFWS"
|
|
206
|
+
v-model="state.usernameUpdate.Username"
|
|
207
|
+
type="text"
|
|
208
|
+
:label="$t('fws_username_label')"
|
|
209
|
+
:help="$t('fws_username_help')"
|
|
210
|
+
:error-vuelidate="v$.usernameUpdate.Username.$errors"
|
|
211
|
+
:disabled="!canUpdateUsername"
|
|
212
|
+
/>
|
|
213
|
+
<div v-if="lastUsernameError" class="text-xs text-red-500">
|
|
214
|
+
{{ lastUsernameError }}
|
|
215
|
+
</div>
|
|
216
|
+
<div class="flex justify-end pt-2">
|
|
217
|
+
<button type="submit" class="btn defaults primary flex items-center gap-2" @click="updateUsername">
|
|
218
|
+
<svg xmlns="http://www.w3.org/2000/svg" class="h-5 w-5" viewBox="0 0 20 20" fill="currentColor">
|
|
219
|
+
<path fill-rule="evenodd" d="M16.707 5.293a1 1 0 010 1.414l-8 8a1 1 0 01-1.414 0l-4-4a1 1 0 011.414-1.414L8 12.586l7.293-7.293a1 1 0 011.414 0z" clip-rule="evenodd" />
|
|
220
|
+
</svg>
|
|
221
|
+
{{ $t("fws_save_user_cta") }}
|
|
222
|
+
</button>
|
|
223
|
+
</div>
|
|
224
|
+
</div>
|
|
225
|
+
</DefaultModal>
|
|
164
226
|
<div class="bg-white dark:bg-fv-neutral-900 p-4 sm:p-6 rounded-lg shadow-sm border border-fv-neutral-200 dark:border-fv-neutral-700">
|
|
165
227
|
<h3 class="text-lg font-semibold text-fv-neutral-900 dark:text-white mb-4 pb-2 border-b border-fv-neutral-200 dark:border-fv-neutral-700">
|
|
166
228
|
{{ $t('fws_profile_heading') || $t('fws_your_profile') }}
|
|
@@ -221,6 +283,18 @@ function selectFile(e: Event) {
|
|
|
221
283
|
:error-vuelidate="v$.userData.Username.$errors"
|
|
222
284
|
:disabled="userData?.UserProfile?.HasUsernameAndSlug ? true : false"
|
|
223
285
|
/>
|
|
286
|
+
<div v-if="!canUpdateUsername" class="text-xs text-fv-neutral-500 dark:text-fv-neutral-400 mt-1">
|
|
287
|
+
{{ $t('fws_username_update_help') }}
|
|
288
|
+
</div>
|
|
289
|
+
<div v-else>
|
|
290
|
+
<button
|
|
291
|
+
type="button"
|
|
292
|
+
class="btn small primary mt-1"
|
|
293
|
+
@click="$eventBus.emit('updateUsernameModal', true)"
|
|
294
|
+
>
|
|
295
|
+
{{ $t('fws_username_update_cta') }}
|
|
296
|
+
</button>
|
|
297
|
+
</div>
|
|
224
298
|
</div>
|
|
225
299
|
</div>
|
|
226
300
|
|