128 lines
8 KiB
Vue
128 lines
8 KiB
Vue
<script setup>
|
||
import { ref, watch } from 'vue';
|
||
import { Link, useForm, usePage } from '@inertiajs/vue3';
|
||
import { CalendarDays, Check, ChevronLeft, ImageOff, Inbox, LoaderCircle, MapPin, MessageSquareText, X } from '@lucide/vue';
|
||
import {
|
||
AppLayout,
|
||
Button,
|
||
Dialog,
|
||
DialogContent,
|
||
DialogDescription,
|
||
DialogFooter,
|
||
DialogHeader,
|
||
DialogTitle,
|
||
EmptyState,
|
||
FormField,
|
||
PageHeader,
|
||
PersonAvatar,
|
||
Textarea,
|
||
formatDate,
|
||
formatRelative,
|
||
toast,
|
||
} from '@inhaus/ui';
|
||
import StatusBadge from '../components/StatusBadge.vue';
|
||
|
||
defineProps({
|
||
pending: { type: Array, required: true },
|
||
recent: { type: Array, default: () => [] },
|
||
labels: { type: Object, required: true },
|
||
});
|
||
|
||
const page = usePage();
|
||
watch(() => page.props.flash?.status, (status) => status && toast.success(status), { immediate: true });
|
||
|
||
// Zusagen / Absagen mit optionalem Hinweis
|
||
const deciding = ref(null); // { request, accept }
|
||
const form = useForm({ note: '' });
|
||
|
||
function open(request, accept) {
|
||
form.reset();
|
||
form.clearErrors();
|
||
deciding.value = { request, accept };
|
||
}
|
||
|
||
function submit() {
|
||
const { request, accept } = deciding.value;
|
||
form.post(`/verleih/anfragen/${request.id}/${accept ? 'zusagen' : 'absagen'}`, { preserveScroll: true, onSuccess: () => (deciding.value = null) });
|
||
}
|
||
|
||
const period = (r) => [r.from ? `ab ${formatDate(r.from)}` : null, r.until ? `bis ${formatDate(r.until)}` : null].filter(Boolean).join(' ');
|
||
</script>
|
||
|
||
<template>
|
||
<AppLayout title="Anfragen">
|
||
<Link href="/verleih" class="ih:mb-4 ih:inline-flex ih:items-center ih:gap-1 ih:text-sm ih:font-medium ih:text-muted-foreground ih:hover:text-foreground"><ChevronLeft class="ih:size-4" /> {{ labels.title }}</Link>
|
||
<PageHeader title="Anfragen" :description="`Zusagen trägt das ${labels.singular} gleich als verliehen ein – mit Wunschort und Person. Die anfragende Person wird benachrichtigt.`" />
|
||
|
||
<section aria-labelledby="offen" class="ih:mb-8">
|
||
<h2 id="offen" class="ih:mb-3 ih:text-sm ih:font-semibold">Offen <span class="ih:text-muted-foreground">({{ pending.length }})</span></h2>
|
||
<div v-if="pending.length" class="ih:grid ih:gap-3">
|
||
<article v-for="request in pending" :key="request.id" class="ih:grid ih:gap-4 ih:rounded-lg ih:border ih:bg-card ih:p-4 ih:sm:grid-cols-[7rem_minmax(0,1fr)_auto] ih:sm:items-center">
|
||
<Link :href="request.item?.url ?? '#'" class="ih:grid ih:aspect-[4/3] ih:w-28 ih:place-items-center ih:overflow-hidden ih:rounded-md ih:bg-muted ih:p-1.5">
|
||
<img v-if="request.item?.thumb_url" :src="request.item.thumb_url" :alt="request.item.title" class="ih:size-full ih:object-contain" />
|
||
<ImageOff v-else class="ih:size-6 ih:text-muted-foreground" />
|
||
</Link>
|
||
<div class="ih:grid ih:min-w-0 ih:gap-1.5">
|
||
<div class="ih:flex ih:flex-wrap ih:items-center ih:gap-2">
|
||
<Link :href="request.item?.url ?? '#'" class="ih:font-semibold ih:hover:underline">{{ request.item?.title }}</Link>
|
||
<StatusBadge v-if="request.item" :lent="request.item.lent" class="ih:border" />
|
||
</div>
|
||
<p class="ih:flex ih:items-center ih:gap-2 ih:text-sm">
|
||
<PersonAvatar :person="request.user" class="ih:size-6" />
|
||
<span><span class="ih:font-medium">{{ request.user?.name }}</span><span v-if="request.user?.department" class="ih:text-muted-foreground"> · {{ request.user.department }}</span></span>
|
||
<span class="ih:text-xs ih:text-muted-foreground">{{ formatRelative(request.created_at) }}</span>
|
||
</p>
|
||
<p class="ih:flex ih:flex-wrap ih:gap-x-4 ih:gap-y-1 ih:text-sm ih:text-muted-foreground">
|
||
<span class="ih:inline-flex ih:items-center ih:gap-1"><MapPin class="ih:size-3.5" /> {{ request.location }}</span>
|
||
<span v-if="period(request)" class="ih:inline-flex ih:items-center ih:gap-1"><CalendarDays class="ih:size-3.5" /> {{ period(request) }}</span>
|
||
</p>
|
||
<p v-if="request.message" class="ih:flex ih:gap-1.5 ih:text-sm"><MessageSquareText class="ih:mt-0.5 ih:size-3.5 ih:shrink-0 ih:text-muted-foreground" /> „{{ request.message }}“</p>
|
||
<p v-if="request.item?.lent" class="ih:text-xs ih:text-muted-foreground">Gerade verliehen{{ request.item.location ? ` (${request.item.location})` : '' }} – eine Zusage trägt den neuen Ort ein.</p>
|
||
</div>
|
||
<div class="ih:flex ih:gap-2 ih:sm:flex-col">
|
||
<Button @click="open(request, true)"><Check /> Zusagen</Button>
|
||
<Button variant="outline" @click="open(request, false)"><X /> Absagen</Button>
|
||
</div>
|
||
</article>
|
||
</div>
|
||
<div v-else class="ih:rounded-lg ih:border ih:bg-card">
|
||
<EmptyState :icon="Inbox" title="Keine offenen Anfragen" text="Neue Anfragen kommen im Portal und per E-Mail." />
|
||
</div>
|
||
</section>
|
||
|
||
<section v-if="recent.length" aria-labelledby="zuletzt">
|
||
<h2 id="zuletzt" class="ih:mb-3 ih:text-sm ih:font-semibold">Zuletzt beantwortet</h2>
|
||
<ul class="ih:divide-y ih:rounded-lg ih:border ih:bg-card">
|
||
<li v-for="request in recent" :key="request.id" class="ih:flex ih:flex-wrap ih:items-center ih:gap-x-3 ih:gap-y-1 ih:px-4 ih:py-2.5 ih:text-sm">
|
||
<Link :href="request.item?.url ?? '#'" class="ih:font-medium ih:hover:underline">{{ request.item?.title }}</Link>
|
||
<span class="ih:text-muted-foreground">{{ request.user?.name }} · {{ request.location }}</span>
|
||
<span class="ih:rounded-full ih:px-2 ih:py-0.5 ih:text-xs ih:font-medium" :class="request.status === 'accepted' ? 'ih:bg-brand-soft ih:text-brand-text' : 'ih:bg-muted ih:text-muted-foreground'">{{ request.status_label }}</span>
|
||
<span class="ih:ml-auto ih:text-xs ih:text-muted-foreground">{{ request.decider ? `${request.decider.name}, ` : '' }}{{ formatDate(request.decided_at ?? request.created_at) }}</span>
|
||
</li>
|
||
</ul>
|
||
</section>
|
||
|
||
<Dialog :open="!!deciding" @update:open="(v) => !v && (deciding = null)">
|
||
<DialogContent v-if="deciding" class="ih:sm:max-w-md">
|
||
<DialogHeader>
|
||
<DialogTitle>{{ deciding.accept ? 'Zusagen' : 'Absagen' }}: {{ deciding.request.item?.title }}</DialogTitle>
|
||
<DialogDescription>
|
||
<template v-if="deciding.accept">Wird als verliehen an {{ deciding.request.user?.name }} nach „{{ deciding.request.location }}“ eingetragen.</template>
|
||
<template v-else>{{ deciding.request.user?.name }} bekommt die Absage im Portal und per E-Mail.</template>
|
||
</DialogDescription>
|
||
</DialogHeader>
|
||
<form id="verleih-entscheidung" @submit.prevent="submit">
|
||
<FormField id="vl-note" label="Hinweis (optional)" :error="form.errors.note || form.errors.status">
|
||
<Textarea id="vl-note" v-model="form.note" rows="3" maxlength="1000" :placeholder="deciding.accept ? 'z. B. Wir bringen es am Montag vorbei.' : 'z. B. Ist bis Ende März schon vergeben.'" />
|
||
</FormField>
|
||
</form>
|
||
<DialogFooter>
|
||
<Button variant="outline" @click="deciding = null">Abbrechen</Button>
|
||
<Button type="submit" form="verleih-entscheidung" :variant="deciding.accept ? 'default' : 'destructive'" :disabled="form.processing">
|
||
<LoaderCircle v-if="form.processing" class="ih:animate-spin" /> {{ deciding.accept ? 'Zusagen' : 'Absagen' }}
|
||
</Button>
|
||
</DialogFooter>
|
||
</DialogContent>
|
||
</Dialog>
|
||
</AppLayout>
|
||
</template>
|