2023-07-26 04:09:10 +02:00
|
|
|
<script setup lang="ts">
|
2023-07-27 17:54:29 +02:00
|
|
|
import { useForm } from 'vee-validate'
|
|
|
|
import { toTypedSchema } from '@vee-validate/yup'
|
2023-07-26 04:09:10 +02:00
|
|
|
import * as yup from 'yup'
|
2023-08-01 15:13:35 +02:00
|
|
|
import type { UserData } from '@/composables/api'
|
2023-07-26 04:09:10 +02:00
|
|
|
|
2023-08-28 15:10:25 +02:00
|
|
|
const { t } = useI18n()
|
2023-08-01 15:13:35 +02:00
|
|
|
const { userData, update } = await useUserInfo()
|
2023-07-26 04:09:10 +02:00
|
|
|
|
2023-08-28 15:10:25 +02:00
|
|
|
const loading: Ref<boolean | null> = ref(false)
|
|
|
|
const feedback: Ref<{
|
|
|
|
variant: 'success' | 'warning' | 'error'
|
|
|
|
icon: string
|
|
|
|
message: string
|
|
|
|
} | null> = ref(null)
|
|
|
|
|
|
|
|
const { handleSubmit, setFieldError, resetForm, meta } = useForm({
|
2023-07-27 17:54:29 +02:00
|
|
|
validationSchema: toTypedSchema(
|
|
|
|
yup.object({
|
2023-08-28 15:10:25 +02:00
|
|
|
// username: yup.string().required(),
|
2023-08-07 17:29:04 +02:00
|
|
|
fullname: yup.string().required().min(2),
|
2023-08-28 15:10:25 +02:00
|
|
|
mailalias: yup.array().of(yup.string().email().required()).required(),
|
|
|
|
mailforward: yup.array().of(yup.string().email().required()).required(),
|
2023-07-27 17:54:29 +02:00
|
|
|
}),
|
|
|
|
),
|
|
|
|
initialValues: {
|
2023-08-28 15:10:25 +02:00
|
|
|
// username: userData.value.username,
|
2023-08-01 15:13:35 +02:00
|
|
|
fullname: userData.value.fullname,
|
2023-08-28 15:10:25 +02:00
|
|
|
mailalias: userData.value.mailalias,
|
|
|
|
mailforward: userData.value.mailforward,
|
2023-07-27 17:54:29 +02:00
|
|
|
},
|
|
|
|
})
|
2023-07-26 04:09:10 +02:00
|
|
|
|
2023-08-28 15:10:25 +02:00
|
|
|
watch(
|
|
|
|
() => meta.value.touched,
|
|
|
|
(value) => {
|
|
|
|
// remove loading and feedback on edition
|
|
|
|
if (value) {
|
|
|
|
loading.value = null
|
|
|
|
feedback.value = null
|
|
|
|
}
|
|
|
|
},
|
|
|
|
)
|
|
|
|
|
2023-08-01 15:13:35 +02:00
|
|
|
const onSubmit = handleSubmit(async (form) => {
|
2023-08-28 15:10:25 +02:00
|
|
|
loading.value = true
|
|
|
|
|
|
|
|
const { error, data } = await useApi<
|
|
|
|
Pick<UserData, 'fullname' | 'mailalias' | 'mailforward'>
|
|
|
|
>('/update', {
|
2023-08-01 15:13:35 +02:00
|
|
|
method: 'PUT',
|
|
|
|
body: form,
|
|
|
|
})
|
|
|
|
|
|
|
|
if (error.value) {
|
2023-08-28 15:10:25 +02:00
|
|
|
const errData = error.value.data
|
|
|
|
if (errData.path) {
|
|
|
|
setFieldError(errData.path, errData.error)
|
|
|
|
} else {
|
|
|
|
feedback.value = {
|
|
|
|
variant: 'error',
|
|
|
|
icon: 'mdi:alert',
|
|
|
|
message: errData.error,
|
|
|
|
}
|
|
|
|
}
|
2023-08-01 15:13:35 +02:00
|
|
|
} else if (data.value) {
|
|
|
|
update(data.value)
|
2023-08-28 15:10:25 +02:00
|
|
|
resetForm({
|
|
|
|
values: data.value,
|
|
|
|
touched: Object.fromEntries(
|
|
|
|
['fullname', 'mailalias', 'mailforward'].map((key) => [key, false]),
|
|
|
|
),
|
|
|
|
})
|
|
|
|
feedback.value = {
|
|
|
|
variant: 'success',
|
|
|
|
icon: 'mdi:thumb-up',
|
|
|
|
message: t('user_profile_updated'),
|
|
|
|
}
|
2023-08-01 15:13:35 +02:00
|
|
|
}
|
2023-08-28 15:10:25 +02:00
|
|
|
loading.value = false
|
2023-07-27 17:54:29 +02:00
|
|
|
})
|
2023-07-26 04:09:10 +02:00
|
|
|
</script>
|
|
|
|
|
|
|
|
<template>
|
2023-08-06 16:27:24 +02:00
|
|
|
<div>
|
|
|
|
<PageTitle :text="$t('footerlink_edit')" />
|
2023-07-26 04:09:10 +02:00
|
|
|
|
2023-08-06 16:27:24 +02:00
|
|
|
<form novalidate class="my-10" @submit="onSubmit">
|
2023-08-28 15:10:25 +02:00
|
|
|
<BaseAlert v-show="feedback" v-bind="feedback" class="mb-10" />
|
|
|
|
|
|
|
|
<div class="lg:flex lg:justify-between">
|
|
|
|
<div class="lg:w-1/2 lg:me-20">
|
|
|
|
<!-- <FormField name="username" :label="$t('username')" class="mb-3">
|
2023-08-06 16:27:24 +02:00
|
|
|
<TextInput
|
|
|
|
name="username"
|
|
|
|
type="text"
|
|
|
|
:placeholder="$t('username')"
|
|
|
|
disabled
|
|
|
|
class="w-full"
|
|
|
|
/>
|
2023-08-28 15:10:25 +02:00
|
|
|
</FormField> -->
|
2023-08-06 16:27:24 +02:00
|
|
|
|
|
|
|
<FormField name="fullname" :label="$t('fullname')">
|
|
|
|
<TextInput
|
|
|
|
name="fullname"
|
|
|
|
type="text"
|
|
|
|
:placeholder="$t('fullname')"
|
|
|
|
autocomplete="name"
|
|
|
|
class="w-full"
|
|
|
|
/>
|
|
|
|
</FormField>
|
|
|
|
</div>
|
2023-07-26 04:09:10 +02:00
|
|
|
|
2023-08-28 15:10:25 +02:00
|
|
|
<div class="basis-1/2 mt-10 lg:mt-0">
|
2023-08-07 16:39:06 +02:00
|
|
|
<TextInputList
|
2023-08-01 15:13:35 +02:00
|
|
|
name="mailalias"
|
2023-08-07 16:39:06 +02:00
|
|
|
type="email"
|
2023-08-06 16:27:24 +02:00
|
|
|
:label="$t('mail_addresses')"
|
2023-08-07 16:39:06 +02:00
|
|
|
:input-label="$t('mail_address')"
|
|
|
|
:placeholder="$t('new_mail')"
|
2023-08-06 16:27:24 +02:00
|
|
|
class="mb-10"
|
2023-08-07 16:39:06 +02:00
|
|
|
/>
|
2023-07-26 04:09:10 +02:00
|
|
|
|
2023-08-07 16:39:06 +02:00
|
|
|
<TextInputList
|
|
|
|
name="mailforward"
|
|
|
|
type="email"
|
|
|
|
:label="$t('mail_forwards')"
|
|
|
|
:input-label="$t('mail_forward')"
|
|
|
|
:placeholder="$t('new_forward')"
|
|
|
|
/>
|
2023-08-06 16:27:24 +02:00
|
|
|
</div>
|
2023-07-26 04:09:10 +02:00
|
|
|
</div>
|
|
|
|
|
2023-08-28 15:10:25 +02:00
|
|
|
<!-- SR "loading" announcement -->
|
|
|
|
<BaseAlert
|
|
|
|
:message="loading ? $t('api.processing') : ''"
|
|
|
|
class="sr-only"
|
|
|
|
assertive
|
|
|
|
/>
|
|
|
|
|
2023-08-06 16:27:24 +02:00
|
|
|
<div class="flex mt-10">
|
|
|
|
<NuxtLink to="/password" class="btn btn-primary">
|
|
|
|
{{ $t('change_password') }}
|
|
|
|
</NuxtLink>
|
2023-08-28 15:10:25 +02:00
|
|
|
<NuxtLink to="/" class="btn ml-auto me-2">
|
2023-08-06 16:27:24 +02:00
|
|
|
{{ $t('cancel') }}
|
|
|
|
</NuxtLink>
|
2023-08-28 15:10:25 +02:00
|
|
|
<SubmitButton :loading="loading" variant="success" />
|
2023-08-06 16:27:24 +02:00
|
|
|
</div>
|
|
|
|
</form>
|
|
|
|
</div>
|
2023-07-26 04:09:10 +02:00
|
|
|
</template>
|