149 lines
9.6 KiB
Vue
149 lines
9.6 KiB
Vue
<script setup>
|
||
import { computed, onBeforeUnmount, ref, watch } from 'vue';
|
||
import { Link, router, useForm, usePage } from '@inertiajs/vue3';
|
||
import { CalendarDays, ChevronLeft, Clock, ImageOff, LoaderCircle, MapPin, PencilLine, Send, Trash2, Undo2, UserRound, X } from '@lucide/vue';
|
||
import { AppLayout, Button, Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle, FormField, Input, PersonAvatar, formatDate, toast } from '@inhaus/ui';
|
||
import RequestDialog from '../components/RequestDialog.vue';
|
||
import StatusBadge from '../components/StatusBadge.vue';
|
||
|
||
const props = defineProps({
|
||
item: { type: Object, required: true },
|
||
labels: { type: Object, required: true },
|
||
canManage: { type: Boolean, default: false },
|
||
myRequest: { type: Object, default: null },
|
||
defaultLocation: { type: String, default: null },
|
||
requests: { type: Array, default: () => [] },
|
||
});
|
||
|
||
const page = usePage();
|
||
watch(() => page.props.flash?.status, (status) => status && toast.success(status), { immediate: true });
|
||
|
||
const item = computed(() => props.item);
|
||
const requesting = ref(false);
|
||
const zoom = ref(false);
|
||
const onKey = (event) => event.key === 'Escape' && (zoom.value = false);
|
||
watch(zoom, (open) => (open ? window.addEventListener('keydown', onKey) : window.removeEventListener('keydown', onKey)));
|
||
onBeforeUnmount(() => window.removeEventListener('keydown', onKey));
|
||
|
||
// Team: zurücknehmen mit neuem Standort
|
||
const returning = ref(false);
|
||
const giveBack = useForm({ location: '' });
|
||
const submitReturn = () => giveBack.post(`/verleih/${item.value.id}/zurueck`, { preserveScroll: true, onSuccess: () => (returning.value = false) });
|
||
|
||
const cancel = () => window.confirm('Anfrage zurückziehen?') && router.delete(`/verleih/anfragen/${props.myRequest.id}`, { preserveScroll: true });
|
||
const remove = () => window.confirm(`„${item.value.title}“ endgültig löschen?`) && router.delete(`/verleih/${item.value.id}`);
|
||
|
||
const period = (from, until) =>
|
||
[from ? `ab ${formatDate(from)}` : null, until ? `bis ${formatDate(until)}` : null].filter(Boolean).join(' ');
|
||
</script>
|
||
|
||
<template>
|
||
<AppLayout :title="item.title">
|
||
<div class="ih:mb-4 ih:flex ih:flex-wrap ih:items-center ih:justify-between ih:gap-3">
|
||
<Link href="/verleih" class="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>
|
||
<div v-if="canManage" class="ih:flex ih:gap-2">
|
||
<Button variant="outline" size="sm" as-child><Link :href="`/verleih/${item.id}/bearbeiten`"><PencilLine /> Bearbeiten</Link></Button>
|
||
<Button variant="ghost" size="sm" class="ih:text-destructive ih:hover:text-destructive" @click="remove"><Trash2 /> Löschen</Button>
|
||
</div>
|
||
</div>
|
||
|
||
<div class="ih:grid ih:gap-6 ih:lg:grid-cols-[minmax(0,1fr)_22rem]">
|
||
<!-- Bild: ganz, ohne Zuschnitt -->
|
||
<div class="ih:grid ih:min-w-0 ih:content-start ih:gap-6">
|
||
<button
|
||
v-if="item.image_url"
|
||
type="button"
|
||
class="ih:grid ih:place-items-center ih:rounded-lg ih:border ih:bg-muted ih:p-4 ih:sm:p-8"
|
||
:aria-label="`${item.title} vergrößern`"
|
||
@click="zoom = true"
|
||
>
|
||
<img :src="item.image_url" :alt="item.title" class="ih:max-h-[70vh] ih:w-auto ih:max-w-full ih:object-contain ih:shadow-md" />
|
||
</button>
|
||
<div v-else class="ih:grid ih:aspect-[4/3] ih:place-items-center ih:rounded-lg ih:border ih:bg-muted ih:text-muted-foreground">
|
||
<ImageOff class="ih:size-10" :stroke-width="1.5" />
|
||
</div>
|
||
|
||
<section v-if="item.description" class="ih:rounded-lg ih:border ih:bg-card ih:p-5">
|
||
<!-- serverseitig bereinigtes HTML -->
|
||
<div class="verleih-text ih:text-[15px] ih:leading-relaxed" v-html="item.description" />
|
||
</section>
|
||
</div>
|
||
|
||
<aside class="ih:grid ih:content-start ih:gap-4 ih:lg:sticky ih:lg:top-24">
|
||
<section class="ih:grid ih:gap-4 ih:rounded-lg ih:border ih:bg-card ih:p-5">
|
||
<div class="ih:grid ih:gap-2">
|
||
<StatusBadge :lent="item.lent" class="ih:w-fit ih:border" />
|
||
<h1 class="ih:text-xl ih:leading-snug ih:font-semibold">{{ item.title }}</h1>
|
||
</div>
|
||
<dl class="ih:grid ih:gap-2 ih:text-sm">
|
||
<div class="ih:flex ih:gap-2">
|
||
<dt class="ih:sr-only">Aktueller Standort</dt>
|
||
<MapPin class="ih:mt-0.5 ih:size-4 ih:shrink-0 ih:text-muted-foreground" aria-hidden="true" />
|
||
<dd>{{ item.location || 'Standort nicht angegeben' }}</dd>
|
||
</div>
|
||
<div v-if="item.lent && (item.lent_since || item.lent_until)" class="ih:flex ih:gap-2">
|
||
<dt class="ih:sr-only">Zeitraum</dt>
|
||
<CalendarDays class="ih:mt-0.5 ih:size-4 ih:shrink-0 ih:text-muted-foreground" aria-hidden="true" />
|
||
<dd>Verliehen {{ period(item.lent_since, item.lent_until) }}</dd>
|
||
</div>
|
||
<div v-if="item.lent_to" class="ih:flex ih:gap-2">
|
||
<dt class="ih:sr-only">Ausgeliehen von</dt>
|
||
<UserRound class="ih:mt-0.5 ih:size-4 ih:shrink-0 ih:text-muted-foreground" aria-hidden="true" />
|
||
<dd><Link :href="`/personen/${item.lent_to.id}`" class="ih:hover:underline">{{ item.lent_to.name }}</Link></dd>
|
||
</div>
|
||
</dl>
|
||
|
||
<div v-if="myRequest" class="ih:grid ih:gap-2 ih:rounded-md ih:bg-brand-soft ih:p-3 ih:text-sm ih:text-brand-text">
|
||
<p class="ih:flex ih:items-center ih:gap-1.5 ih:font-medium"><Clock class="ih:size-4" /> Angefragt am {{ formatDate(myRequest.created_at) }}</p>
|
||
<p>Nach „{{ myRequest.location }}“ {{ period(myRequest.from, myRequest.until) }} – das Team meldet sich.</p>
|
||
<button type="button" class="ih:w-fit ih:text-xs ih:font-medium ih:underline" @click="cancel">Anfrage zurückziehen</button>
|
||
</div>
|
||
<Button v-else size="lg" class="ih:w-full" @click="requesting = true"><Send /> {{ labels.singular }} anfragen</Button>
|
||
|
||
<Button v-if="canManage && item.lent" variant="outline" class="ih:w-full" @click="returning = true"><Undo2 /> Zurückgenommen</Button>
|
||
</section>
|
||
|
||
<!-- Team: Anfragen zu diesem Objekt -->
|
||
<section v-if="canManage && requests.length" class="ih:rounded-lg ih:border ih:bg-card ih:p-5">
|
||
<h2 class="ih:mb-3 ih:text-sm ih:font-semibold">Anfragen</h2>
|
||
<ul class="ih:grid ih:gap-3">
|
||
<li v-for="request in requests" :key="request.id" class="ih:flex ih:gap-3 ih:text-sm">
|
||
<PersonAvatar :person="request.user" class="ih:size-8" />
|
||
<div class="ih:min-w-0">
|
||
<p><span class="ih:font-medium">{{ request.user?.name }}</span> · {{ request.location }}</p>
|
||
<p class="ih:text-xs ih:text-muted-foreground">{{ request.status_label }} · {{ formatDate(request.created_at) }}</p>
|
||
</div>
|
||
</li>
|
||
</ul>
|
||
<Link href="/verleih/anfragen" class="ih:mt-3 ih:inline-block ih:text-sm ih:font-medium ih:text-brand-text ih:hover:underline">Alle Anfragen</Link>
|
||
</section>
|
||
</aside>
|
||
</div>
|
||
|
||
<RequestDialog v-model:open="requesting" :item="item" :labels="labels" :default-location="defaultLocation" />
|
||
|
||
<Dialog v-model:open="returning">
|
||
<DialogContent class="ih:sm:max-w-md">
|
||
<DialogHeader>
|
||
<DialogTitle>„{{ item.title }}“ zurückgenommen</DialogTitle>
|
||
<DialogDescription>Danach ist es wieder verfügbar. Wo ist es jetzt?</DialogDescription>
|
||
</DialogHeader>
|
||
<form id="verleih-zurueck" @submit.prevent="submitReturn">
|
||
<FormField id="vl-return" label="Neuer Standort" :error="giveBack.errors.location">
|
||
<Input id="vl-return" v-model="giveBack.location" maxlength="200" placeholder="z. B. Lager Künstlerteam" />
|
||
</FormField>
|
||
</form>
|
||
<DialogFooter>
|
||
<Button variant="outline" @click="returning = false">Abbrechen</Button>
|
||
<Button type="submit" form="verleih-zurueck" :disabled="giveBack.processing"><LoaderCircle v-if="giveBack.processing" class="ih:animate-spin" /> Speichern</Button>
|
||
</DialogFooter>
|
||
</DialogContent>
|
||
</Dialog>
|
||
|
||
<!-- Vergrößerung -->
|
||
<div v-if="zoom" class="ih:fixed ih:inset-0 ih:z-50 ih:grid ih:place-items-center ih:bg-black/85 ih:p-4" role="dialog" aria-modal="true" :aria-label="item.title" @click="zoom = false">
|
||
<img :src="item.image_url" :alt="item.title" class="ih:size-full ih:object-contain" />
|
||
<button type="button" class="ih:absolute ih:top-4 ih:right-4 ih:grid ih:size-10 ih:place-items-center ih:rounded-full ih:bg-white/15 ih:text-white" aria-label="Schließen" @click.stop="zoom = false"><X /></button>
|
||
</div>
|
||
</AppLayout>
|
||
</template>
|