inhaus-plugin-chat/resources/js/components/NewChatDialog.vue
Friederich Loheide 2844452002 Nachrichten-Plugin 1.0.0: Direktnachrichten, Gruppen, Anhänge, GIFs, Emojis
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-09-27 16:34:53 +00:00

84 lines
3 KiB
Vue
Raw Permalink 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 { ref, watch } from 'vue';
import { LoaderCircle } from '@lucide/vue';
import { Button, Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle, Input, Label, toast } from '@inhaus/ui';
import PeopleSelect from './PeopleSelect.vue';
import { api } from '../lib/api';
/** Neue Direktnachricht bzw. neue Gruppe */
const props = defineProps({
group: { type: Boolean, default: false },
me: { type: Object, required: true },
});
const open = defineModel('open', { type: Boolean, default: false });
const emit = defineEmits(['created']);
const name = ref('');
const people = ref([]);
const busy = ref(false);
watch(open, (value) => {
if (value) {
name.value = '';
people.value = [];
}
});
async function start(person) {
if (props.group) return;
busy.value = true;
try {
const data = await api.direct(person.id);
open.value = false;
emit('created', data);
} catch (error) {
toast.error(error.message);
} finally {
busy.value = false;
}
}
async function createGroup() {
busy.value = true;
try {
const data = await api.createGroup(name.value.trim(), people.value.map((p) => p.id));
open.value = false;
emit('created', data);
} catch (error) {
toast.error(error.message);
} finally {
busy.value = false;
}
}
</script>
<template>
<Dialog v-model:open="open">
<DialogContent class="ih:sm:max-w-md">
<DialogHeader>
<DialogTitle>{{ group ? 'Neue Gruppe' : 'Neue Nachricht' }}</DialogTitle>
<DialogDescription>{{ group ? 'Name und Mitglieder wählen – Sie verwalten die Gruppe.' : 'An wen möchten Sie schreiben?' }}</DialogDescription>
</DialogHeader>
<div class="ih:grid ih:gap-4">
<div v-if="group" class="ih:grid ih:gap-1.5">
<Label for="chat-group-name">Name der Gruppe</Label>
<Input id="chat-group-name" v-model="name" maxlength="100" placeholder="z. B. Station 3 – Frühdienst" />
</div>
<div class="ih:grid ih:gap-1.5">
<Label v-if="group">Mitglieder</Label>
<PeopleSelect v-model="people" :multiple="group" :exclude="[me.id]" autofocus @pick="start" />
</div>
<p v-if="busy && !group" class="ih:flex ih:items-center ih:gap-2 ih:text-sm ih:text-muted-foreground"><LoaderCircle class="ih:size-4 ih:animate-spin" /> Gespräch wird geöffnet …</p>
</div>
<DialogFooter v-if="group">
<Button variant="ghost" @click="open = false">Abbrechen</Button>
<Button :disabled="busy || !name.trim() || !people.length" @click="createGroup">
<LoaderCircle v-if="busy" class="ih:animate-spin" /> Gruppe erstellen
</Button>
</DialogFooter>
</DialogContent>
</Dialog>
</template>