inhaus-plugin-gruppen/resources/js/components/GroupDialog.vue
Friederich Loheide 5bdfb8a082 Gruppen-Plugin 1.0.0
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-09-27 17:17:10 +00:00

60 lines
3.7 KiB
Vue
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<script setup>
import { watch } from 'vue';
import { useForm } from '@inertiajs/vue3';
import { LoaderCircle } from '@lucide/vue';
import { Button, Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle, FormField, Input, Textarea } from '@inhaus/ui';
/** Gruppe gründen bzw. bearbeiten */
const props = defineProps({
group: { type: Object, default: null },
privacy: { type: Object, required: true },
privacyHints: { type: Object, required: true },
});
const open = defineModel('open', { type: Boolean, default: false });
const form = useForm({ name: '', description: '', privacy: 'open', cover: null, remove_cover: false });
watch(open, (value) => {
if (!value) return;
form.clearErrors();
form.defaults({ name: props.group?.name ?? '', description: props.group?.description ?? '', privacy: props.group?.privacy ?? 'open', cover: null, remove_cover: false });
form.reset();
});
function submit() {
form.post(props.group ? `/gruppen/${props.group.slug}` : '/gruppen', { forceFormData: true, preserveScroll: true, onSuccess: () => (open.value = false) });
}
</script>
<template>
<Dialog v-model:open="open">
<DialogContent class="ih:sm:max-w-lg">
<DialogHeader>
<DialogTitle>{{ group ? 'Gruppe bearbeiten' : 'Gruppe gründen' }}</DialogTitle>
<DialogDescription>{{ group ? 'Name, Beschreibung, Art und Titelbild.' : 'Zu einem Thema, einem Hobby oder einem Projekt – Sie verwalten die Gruppe.' }}</DialogDescription>
</DialogHeader>
<form id="group-form" class="ih:grid ih:gap-4" @submit.prevent="submit">
<FormField id="g-name" label="Name" :error="form.errors.name">
<Input id="g-name" v-model="form.name" maxlength="100" placeholder="z. B. Laufgruppe Mainz" />
</FormField>
<FormField id="g-description" label="Worum geht es? (optional)" :error="form.errors.description">
<Textarea id="g-description" v-model="form.description" rows="3" maxlength="2000" />
</FormField>
<fieldset class="ih:grid ih:gap-2">
<legend class="ih:mb-1 ih:text-sm ih:font-medium">Wer darf rein?</legend>
<label v-for="(label, key) in privacy" :key="key" class="ih:flex ih:cursor-pointer ih:items-start ih:gap-3 ih:rounded-md ih:border ih:p-3 ih:text-sm ih:has-[:checked]:border-brand ih:has-[:checked]:bg-brand-soft/50">
<input v-model="form.privacy" type="radio" name="privacy" :value="key" class="ih:mt-0.5 ih:size-4 ih:accent-[var(--color-brand)]" />
<span><span class="ih:font-medium">{{ label }}</span><span class="ih:block ih:text-xs ih:text-muted-foreground">{{ privacyHints[key] }}</span></span>
</label>
</fieldset>
<FormField id="g-cover" label="Titelbild (optional)" :error="form.errors.cover">
<input id="g-cover" type="file" accept="image/jpeg,image/png,image/webp" class="ih:text-sm" @change="form.cover = $event.target.files[0] ?? null" />
</FormField>
<label v-if="group?.cover_url" class="ih:flex ih:items-center ih:gap-2 ih:text-sm"><input v-model="form.remove_cover" type="checkbox" /> Titelbild entfernen</label>
</form>
<DialogFooter>
<Button variant="ghost" @click="open = false">Abbrechen</Button>
<Button type="submit" form="group-form" :disabled="form.processing || !form.name.trim()"><LoaderCircle v-if="form.processing" class="ih:animate-spin" /> {{ group ? 'Speichern' : 'Gründen' }}</Button>
</DialogFooter>
</DialogContent>
</Dialog>
</template>