yunohost-portal/pages/edit.vue

104 lines
2.8 KiB
Vue
Raw Normal View History

2023-07-26 04:09:10 +02:00
<script setup lang="ts">
import { useForm } from 'vee-validate'
import { toTypedSchema } from '@vee-validate/yup'
2023-07-26 04:09:10 +02:00
import * as yup from 'yup'
import type { UserData } from '@/composables/api'
2023-07-26 04:09:10 +02:00
const { userData, update } = await useUserInfo()
2023-07-26 04:09:10 +02:00
const { handleSubmit, setFieldError } = useForm({
validationSchema: toTypedSchema(
yup.object({
username: yup.string().required(),
2023-08-07 17:29:04 +02:00
fullname: yup.string().required().min(2),
mailalias: yup.array().of(yup.string().email().required()),
mailforward: yup.array().of(yup.string().email().required()),
}),
),
initialValues: {
username: userData.value.username,
fullname: userData.value.fullname,
mailalias: userData.value.mailalias.length
? userData.value.mailalias
: [''],
mailforward: userData.value.mailforward.length
? userData.value.mailforward
: [''],
},
})
2023-07-26 04:09:10 +02:00
const onSubmit = handleSubmit(async (form) => {
const { data, error } = await useApi<UserData>('/update', {
method: 'PUT',
body: form,
})
if (error.value) {
setFieldError(error.value.data.path, error.value.data.error_key)
} else if (data.value) {
update(data.value)
}
})
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">
<div class="sm:flex sm:justify-between">
<div class="sm:w-1/3">
<FormField name="username" :label="$t('username')" class="mb-3">
<TextInput
name="username"
type="text"
:placeholder="$t('username')"
disabled
class="w-full"
/>
</FormField>
<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-06 16:27:24 +02:00
<div class="basis-1/2 mt-10 sm:mt-0">
2023-08-07 16:39:06 +02:00
<TextInputList
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-06 16:27:24 +02:00
<div class="flex mt-10">
<NuxtLink to="/password" class="btn btn-primary">
{{ $t('change_password') }}
</NuxtLink>
<NuxtLink to="/" class="btn ml-auto mr-2">
{{ $t('cancel') }}
</NuxtLink>
<YButton :text="$t('save')" type="submit" variant="success" />
</div>
</form>
</div>
2023-07-26 04:09:10 +02:00
</template>