Some checks failed
CI / PHP 8.3 / mariadb:10.6 (pull_request) Successful in 3m46s
CI / PHP 8.4 / mariadb:10.6 (pull_request) Successful in 3m49s
CI / PHP 8.3 / mariadb:11.4 (pull_request) Successful in 4m7s
CI / PHP 8.4 / mariadb:11.4 (pull_request) Successful in 4m8s
CI / PHP 8.3 / mysql:8.0 (pull_request) Failing after 5m51s
CI / PHP 8.4 / mysql:8.0 (pull_request) Failing after 6m29s
CI / PHP 8.3 / mysql:8.4 (pull_request) Failing after 6m12s
CI / Build-Artefakte aktuell (pull_request) Successful in 1m11s
CI / PHP 8.4 / mysql:8.4 (pull_request) Failing after 5m33s
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
242 lines
11 KiB
Vue
242 lines
11 KiB
Vue
<script setup>
|
|
import { pluginComponent } from '@/lib/pluginComponents';
|
|
import { defineAsyncComponent, ref } from 'vue';
|
|
import { router, useForm } from '@inertiajs/vue3';
|
|
import { Camera, LoaderCircle, Trash2 } from '@lucide/vue';
|
|
import { toast } from 'vue-sonner';
|
|
import { Button } from '@/components/ui/button';
|
|
import { Input } from '@/components/ui/input';
|
|
import { Textarea } from '@/components/ui/textarea';
|
|
import FormField from '@/components/FormField.vue';
|
|
import Panel from '@/components/Panel.vue';
|
|
import PersonAvatar from '@/components/PersonAvatar.vue';
|
|
import AppLayout from '@/layouts/AppLayout.vue';
|
|
|
|
const props = defineProps({
|
|
profile: { type: Object, required: true },
|
|
managed: { type: Array, default: () => [] },
|
|
customFields: { type: Array, default: () => [] },
|
|
sections: { type: Array, default: () => [] },
|
|
});
|
|
|
|
// Abschnitte aus Plugins (App\Profile\ProfileSections): „<plugin>::Name“ aus plugins-core/<plugin>/resources/js/profile
|
|
const sectionLoaders = import.meta.glob('../../../../plugins-core/*/resources/js/profile/*.vue');
|
|
const sectionComponents = Object.fromEntries(Object.entries(sectionLoaders).map(([path, loader]) => [
|
|
`${path.match(/plugins-core\/([^/]+)\//)[1]}::${path.split('/').pop().replace('.vue', '')}`,
|
|
defineAsyncComponent(loader),
|
|
]));
|
|
|
|
const isManaged = (field) => props.managed.includes(field);
|
|
|
|
// Stammdaten
|
|
const form = useForm({
|
|
first_name: props.profile.first_name ?? '',
|
|
last_name: props.profile.last_name ?? '',
|
|
email: props.profile.email,
|
|
job_title: props.profile.job_title ?? '',
|
|
department: props.profile.department ?? '',
|
|
location: props.profile.location ?? '',
|
|
phone: props.profile.phone ?? '',
|
|
mobile: props.profile.mobile ?? '',
|
|
about: props.profile.about ?? '',
|
|
custom_fields: Object.fromEntries(props.customFields.map((field) => [field.key, field.value ?? ''])),
|
|
});
|
|
|
|
const inputTypes = { email: 'email', phone: 'tel', url: 'url', date: 'date' };
|
|
|
|
function customHint(field) {
|
|
const hints = [];
|
|
|
|
if (field.managed) hints.push('Wird aus Microsoft Entra ID übernommen.');
|
|
else if (field.readonly) hints.push('Wird von der Personalverwaltung gepflegt.');
|
|
if (field.restricted) hints.push('Nur für Sie und die Personalverwaltung sichtbar.');
|
|
if (field.help) hints.push(field.help);
|
|
|
|
return hints.join(' ');
|
|
}
|
|
|
|
function saveProfile() {
|
|
form.put('/profil', {
|
|
preserveScroll: true,
|
|
onSuccess: () => {
|
|
form.defaults();
|
|
toast.success('Profil gespeichert');
|
|
},
|
|
});
|
|
}
|
|
|
|
const fields = [
|
|
{ key: 'first_name', label: 'Vorname', autocomplete: 'given-name' },
|
|
{ key: 'last_name', label: 'Nachname', autocomplete: 'family-name' },
|
|
{ key: 'email', label: 'E-Mail-Adresse', type: 'email', autocomplete: 'email', wide: true },
|
|
{ key: 'job_title', label: 'Funktion', autocomplete: 'organization-title' },
|
|
{ key: 'department', label: 'Abteilung' },
|
|
{ key: 'location', label: 'Standort' },
|
|
{ key: 'phone', label: 'Telefon', type: 'tel', autocomplete: 'tel' },
|
|
{ key: 'mobile', label: 'Mobil', type: 'tel' },
|
|
];
|
|
|
|
// Profilbild
|
|
const avatarInput = ref(null);
|
|
const avatarForm = useForm({ avatar: null });
|
|
|
|
function uploadAvatar(event) {
|
|
const file = event.target.files?.[0];
|
|
|
|
if (!file) return;
|
|
|
|
avatarForm.avatar = file;
|
|
avatarForm.post('/profil/bild', {
|
|
preserveScroll: true,
|
|
forceFormData: true,
|
|
onSuccess: () => toast.success('Profilbild aktualisiert'),
|
|
onFinish: () => {
|
|
event.target.value = '';
|
|
},
|
|
});
|
|
}
|
|
|
|
function removeAvatar() {
|
|
router.delete('/profil/bild', {
|
|
preserveScroll: true,
|
|
onSuccess: () => toast.success('Profilbild entfernt'),
|
|
});
|
|
}
|
|
|
|
// Passwort
|
|
const passwordForm = useForm({
|
|
current_password: '',
|
|
password: '',
|
|
password_confirmation: '',
|
|
});
|
|
|
|
function savePassword() {
|
|
passwordForm.put('/user/password', {
|
|
preserveScroll: true,
|
|
errorBag: 'updatePassword',
|
|
onSuccess: () => {
|
|
passwordForm.reset();
|
|
toast.success('Passwort geändert');
|
|
},
|
|
});
|
|
}
|
|
</script>
|
|
|
|
<template>
|
|
<AppLayout title="Profil bearbeiten">
|
|
<h1 class="mb-6 text-2xl font-semibold tracking-tight">Profil bearbeiten</h1>
|
|
|
|
<div class="grid gap-6 lg:grid-cols-12">
|
|
<div class="lg:col-span-4">
|
|
<Panel title="Profilbild">
|
|
<div class="flex flex-col items-center text-center">
|
|
<PersonAvatar :person="profile" class="size-32 text-3xl" />
|
|
<input ref="avatarInput" type="file" accept="image/jpeg,image/png,image/webp" class="hidden" @change="uploadAvatar" />
|
|
<div class="mt-5 flex flex-wrap justify-center gap-2">
|
|
<Button variant="outline" :disabled="avatarForm.processing" @click="avatarInput?.click()">
|
|
<LoaderCircle v-if="avatarForm.processing" class="animate-spin" />
|
|
<Camera v-else />
|
|
{{ profile.avatar_url ? 'Bild ändern' : 'Bild hochladen' }}
|
|
</Button>
|
|
<Button v-if="profile.avatar_url" variant="ghost" class="text-destructive hover:text-destructive" @click="removeAvatar">
|
|
<Trash2 /> Entfernen
|
|
</Button>
|
|
</div>
|
|
<p v-if="avatarForm.errors.avatar" class="mt-3 text-[13px] text-destructive">{{ avatarForm.errors.avatar }}</p>
|
|
<p class="mt-3 text-[13px] text-muted-foreground">JPG, PNG oder WebP, höchstens 8 MB. Das Bild wird quadratisch zugeschnitten.</p>
|
|
</div>
|
|
</Panel>
|
|
</div>
|
|
|
|
<div class="grid content-start gap-6 lg:col-span-8">
|
|
<Panel title="Persönliche Angaben">
|
|
<form class="grid gap-5" @submit.prevent="saveProfile">
|
|
<div class="grid gap-5 sm:grid-cols-2">
|
|
<FormField
|
|
v-for="field in fields"
|
|
:id="field.key"
|
|
:key="field.key"
|
|
:label="field.label"
|
|
:error="form.errors[field.key]"
|
|
:hint="isManaged(field.key) ? 'Wird aus Microsoft Entra ID übernommen.' : ''"
|
|
:class="{ 'sm:col-span-2': field.wide }"
|
|
>
|
|
<Input
|
|
:id="field.key"
|
|
v-model="form[field.key]"
|
|
:type="field.type ?? 'text'"
|
|
:autocomplete="field.autocomplete"
|
|
:disabled="isManaged(field.key)"
|
|
:aria-invalid="!!form.errors[field.key]"
|
|
/>
|
|
</FormField>
|
|
<FormField id="about" label="Über mich" :error="form.errors.about" hint="Aufgaben, Themen, bei denen man Sie ansprechen kann." class="sm:col-span-2">
|
|
<Textarea id="about" v-model="form.about" rows="4" maxlength="2000" />
|
|
</FormField>
|
|
</div>
|
|
<div v-if="customFields.length" class="grid gap-5 border-t pt-5">
|
|
<h3 class="text-sm font-semibold">Weitere Angaben</h3>
|
|
<div class="grid gap-5 sm:grid-cols-2">
|
|
<FormField
|
|
v-for="field in customFields"
|
|
:id="`custom-${field.key}`"
|
|
:key="field.key"
|
|
:label="field.label"
|
|
:error="form.errors[`custom_fields.${field.key}`]"
|
|
:hint="customHint(field)"
|
|
:class="{ 'sm:col-span-2': field.type === 'textarea' }"
|
|
>
|
|
<Textarea
|
|
v-if="field.type === 'textarea'"
|
|
:id="`custom-${field.key}`"
|
|
v-model="form.custom_fields[field.key]"
|
|
rows="3"
|
|
:disabled="field.readonly"
|
|
/>
|
|
<Input
|
|
v-else
|
|
:id="`custom-${field.key}`"
|
|
v-model="form.custom_fields[field.key]"
|
|
:type="inputTypes[field.type] ?? 'text'"
|
|
:disabled="field.readonly"
|
|
:aria-invalid="!!form.errors[`custom_fields.${field.key}`]"
|
|
/>
|
|
</FormField>
|
|
</div>
|
|
</div>
|
|
<div class="flex justify-end border-t pt-5">
|
|
<Button type="submit" :disabled="form.processing || !form.isDirty">
|
|
<LoaderCircle v-if="form.processing" class="animate-spin" />
|
|
Speichern
|
|
</Button>
|
|
</div>
|
|
</form>
|
|
</Panel>
|
|
|
|
<component :is="sectionComponents[section.component] ?? pluginComponent(section.component, 'profile')" v-for="section in sections" :key="section.key" v-bind="section.props" />
|
|
|
|
<Panel v-if="profile.has_password" title="Passwort ändern">
|
|
<form class="grid gap-5" @submit.prevent="savePassword">
|
|
<FormField id="current_password" label="Aktuelles Passwort" :error="passwordForm.errors.current_password" class="sm:max-w-sm">
|
|
<Input id="current_password" v-model="passwordForm.current_password" type="password" autocomplete="current-password" />
|
|
</FormField>
|
|
<div class="grid gap-5 sm:grid-cols-2">
|
|
<FormField id="password" label="Neues Passwort" :error="passwordForm.errors.password" hint="Mindestens 10 Zeichen, mit Buchstaben und Ziffern.">
|
|
<Input id="password" v-model="passwordForm.password" type="password" autocomplete="new-password" />
|
|
</FormField>
|
|
<FormField id="password_confirmation" label="Neues Passwort wiederholen">
|
|
<Input id="password_confirmation" v-model="passwordForm.password_confirmation" type="password" autocomplete="new-password" />
|
|
</FormField>
|
|
</div>
|
|
<div class="flex justify-end border-t pt-5">
|
|
<Button type="submit" :disabled="passwordForm.processing">
|
|
<LoaderCircle v-if="passwordForm.processing" class="animate-spin" />
|
|
Passwort ändern
|
|
</Button>
|
|
</div>
|
|
</form>
|
|
</Panel>
|
|
</div>
|
|
</div>
|
|
</AppLayout>
|
|
</template>
|