344 lines
14 KiB
TypeScript
344 lines
14 KiB
TypeScript
import React from 'react';
|
|
import { useNavigate, useParams } from 'react-router-dom';
|
|
import { useTranslation } from 'react-i18next';
|
|
import { CalendarDays, MapPin, Settings, Users, Camera, Sparkles, QrCode, Image, Shield, Layout, RefreshCcw, Pencil, Megaphone, Tv } from 'lucide-react';
|
|
import { YStack, XStack } from '@tamagui/stacks';
|
|
import { SizableText as Text } from '@tamagui/text';
|
|
import { Pressable } from '@tamagui/react-native-web-lite';
|
|
import { MobileShell, HeaderActionButton } from './components/MobileShell';
|
|
import { MobileCard, PillBadge, KpiTile, ActionTile } from './components/Primitives';
|
|
import { TenantEvent, EventStats, EventToolkit, getEvent, getEventStats, getEventToolkit, getEvents } from '../api';
|
|
import { adminPath, ADMIN_EVENT_BRANDING_PATH, ADMIN_EVENT_GUEST_NOTIFICATIONS_PATH, ADMIN_EVENT_INVITES_PATH, ADMIN_EVENT_LIVE_SHOW_PATH, ADMIN_EVENT_LIVE_SHOW_SETTINGS_PATH, ADMIN_EVENT_MEMBERS_PATH, ADMIN_EVENT_PHOTOS_PATH, ADMIN_EVENT_TASKS_PATH } from '../constants';
|
|
import { isAuthError } from '../auth/tokens';
|
|
import { getApiErrorMessage } from '../lib/apiError';
|
|
import { MobileSheet } from './components/Sheet';
|
|
import { useEventContext } from '../context/EventContext';
|
|
import { formatEventDate, isBrandingAllowed, resolveEngagementMode, resolveEventDisplayName } from '../lib/events';
|
|
import { isPastEvent } from './eventDate';
|
|
import { useBackNavigation } from './hooks/useBackNavigation';
|
|
import { ADMIN_ACTION_COLORS, ADMIN_MOTION, useAdminTheme } from './theme';
|
|
|
|
export default function MobileEventDetailPage() {
|
|
const { slug: slugParam } = useParams<{ slug?: string }>();
|
|
const slug = slugParam ?? null;
|
|
const navigate = useNavigate();
|
|
const { t } = useTranslation('management');
|
|
|
|
const [event, setEvent] = React.useState<TenantEvent | null>(null);
|
|
const [stats, setStats] = React.useState<EventStats | null>(null);
|
|
const [toolkit, setToolkit] = React.useState<EventToolkit | null>(null);
|
|
const [loading, setLoading] = React.useState(true);
|
|
const [error, setError] = React.useState<string | null>(null);
|
|
const { events, activeEvent, selectEvent } = useEventContext();
|
|
const [showEventPicker, setShowEventPicker] = React.useState(false);
|
|
const back = useBackNavigation(adminPath('/mobile/events'));
|
|
const { textStrong, text, muted, danger, accentSoft } = useAdminTheme();
|
|
|
|
React.useEffect(() => {
|
|
if (!slug) return;
|
|
selectEvent(slug);
|
|
}, [slug, selectEvent]);
|
|
|
|
React.useEffect(() => {
|
|
if (!slug) return;
|
|
(async () => {
|
|
setLoading(true);
|
|
try {
|
|
const [eventData, statsData, toolkitData] = await Promise.all([getEvent(slug), getEventStats(slug), getEventToolkit(slug)]);
|
|
setEvent(eventData);
|
|
setStats(statsData);
|
|
setToolkit(toolkitData);
|
|
setError(null);
|
|
} catch (err) {
|
|
if (!isAuthError(err)) {
|
|
try {
|
|
const list = await getEvents({ force: true });
|
|
const fallback = list.find((ev: TenantEvent) => ev.slug === slug) ?? null;
|
|
if (fallback) {
|
|
setEvent(fallback);
|
|
setError(null);
|
|
} else {
|
|
setError(getApiErrorMessage(err, t('events.errors.loadFailed', 'Event konnte nicht geladen werden.')));
|
|
}
|
|
} catch (fallbackErr) {
|
|
setError(getApiErrorMessage(fallbackErr, t('events.errors.loadFailed', 'Event konnte nicht geladen werden.')));
|
|
}
|
|
}
|
|
} finally {
|
|
setLoading(false);
|
|
}
|
|
})();
|
|
}, [slug, t]);
|
|
|
|
const tasksEnabled = resolveEngagementMode(event ?? activeEvent ?? null) !== 'photo_only';
|
|
const brandingAllowed = isBrandingAllowed(event ?? activeEvent ?? null);
|
|
|
|
const kpis = [
|
|
{
|
|
label: t('events.detail.kpi.guests', 'Guests Registered'),
|
|
value: toolkit?.invites?.summary.total ?? event?.active_invites_count ?? '—',
|
|
icon: Users,
|
|
},
|
|
{
|
|
label: t('events.detail.kpi.photos', 'Images Uploaded'),
|
|
value: stats?.uploads_total ?? event?.photo_count ?? '—',
|
|
icon: Camera,
|
|
},
|
|
];
|
|
|
|
if (tasksEnabled) {
|
|
kpis.unshift({
|
|
label: t('events.detail.kpi.tasks', 'Active Tasks'),
|
|
value: event?.tasks_count ?? toolkit?.tasks?.summary?.total ?? '—',
|
|
icon: Sparkles,
|
|
});
|
|
}
|
|
|
|
return (
|
|
<MobileShell
|
|
activeTab="home"
|
|
title={resolveEventDisplayName(event ?? activeEvent ?? undefined)}
|
|
subtitle={
|
|
event?.event_date || activeEvent?.event_date
|
|
? formatDate(event?.event_date ?? activeEvent?.event_date, t)
|
|
: undefined
|
|
}
|
|
onBack={back}
|
|
headerActions={
|
|
<XStack space="$3" alignItems="center">
|
|
<HeaderActionButton onPress={() => navigate(adminPath('/mobile/settings'))} ariaLabel={t('mobileSettings.title', 'Settings')}>
|
|
<Settings size={18} color={textStrong} />
|
|
</HeaderActionButton>
|
|
<HeaderActionButton onPress={() => navigate(0)} ariaLabel={t('common.refresh', 'Refresh')}>
|
|
<RefreshCcw size={18} color={textStrong} />
|
|
</HeaderActionButton>
|
|
</XStack>
|
|
}
|
|
>
|
|
{error ? (
|
|
<MobileCard>
|
|
<Text fontWeight="700" color={danger}>
|
|
{error}
|
|
</Text>
|
|
</MobileCard>
|
|
) : null}
|
|
|
|
<MobileCard space="$3">
|
|
<Text fontSize="$lg" fontWeight="800" color={textStrong}>
|
|
{event ? renderName(event.name, t) : t('events.placeholders.untitled', 'Unbenanntes Event')}
|
|
</Text>
|
|
<XStack alignItems="center" space="$2">
|
|
<CalendarDays size={16} color={muted} />
|
|
<Text fontSize="$sm" color={muted}>
|
|
{formatDate(event?.event_date, t)}
|
|
</Text>
|
|
<MapPin size={16} color={muted} />
|
|
<Text fontSize="$sm" color={muted}>
|
|
{resolveLocation(event, t)}
|
|
</Text>
|
|
</XStack>
|
|
<PillBadge tone={event?.status === 'published' ? 'success' : 'warning'}>
|
|
{event?.status === 'published' ? t('events.status.published', 'Live') : t('events.status.draft', 'Draft')}
|
|
</PillBadge>
|
|
<Pressable
|
|
aria-label={t('mobileEvents.edit', 'Edit event')}
|
|
onPress={() => slug && navigate(adminPath(`/mobile/events/${slug}/edit`))}
|
|
style={{
|
|
position: 'absolute',
|
|
right: 16,
|
|
top: 16,
|
|
width: 44,
|
|
height: 44,
|
|
borderRadius: 22,
|
|
backgroundColor: accentSoft,
|
|
alignItems: 'center',
|
|
justifyContent: 'center',
|
|
boxShadow: '0 6px 16px rgba(0,0,0,0.12)',
|
|
}}
|
|
>
|
|
<Pencil size={18} color={textStrong} />
|
|
</Pressable>
|
|
</MobileCard>
|
|
|
|
<YStack space="$2">
|
|
{loading ? (
|
|
<XStack space="$2" flexWrap="wrap">
|
|
{Array.from({ length: 3 }).map((_, idx) => (
|
|
<MobileCard key={`kpi-${idx}`} height={90} width="32%" />
|
|
))}
|
|
</XStack>
|
|
) : (
|
|
<XStack space="$2" flexWrap="wrap">
|
|
{kpis.map((kpi) => (
|
|
<KpiTile key={kpi.label} icon={kpi.icon} label={kpi.label} value={kpi.value} />
|
|
))}
|
|
</XStack>
|
|
)}
|
|
</YStack>
|
|
|
|
<MobileSheet
|
|
open={showEventPicker}
|
|
onClose={() => setShowEventPicker(false)}
|
|
title={t('events.detail.pickEvent', 'Event wählen')}
|
|
footer={null}
|
|
bottomOffsetPx={120}
|
|
>
|
|
<YStack space="$2">
|
|
{events.length === 0 ? (
|
|
<Text fontSize={12.5} color={muted}>
|
|
{t('events.list.empty.description', 'Starte jetzt mit deinem ersten Event.')}
|
|
</Text>
|
|
) : (
|
|
events.map((ev) => (
|
|
<Pressable
|
|
key={ev.slug}
|
|
onPress={() => {
|
|
selectEvent(ev.slug ?? null);
|
|
setShowEventPicker(false);
|
|
navigate(adminPath(`/mobile/events/${ev.slug}`));
|
|
}}
|
|
>
|
|
<XStack alignItems="center" justifyContent="space-between" paddingVertical="$2">
|
|
<YStack space="$1">
|
|
<Text fontSize={13} fontWeight="700" color={textStrong}>
|
|
{renderName(ev.name, t)}
|
|
</Text>
|
|
<XStack alignItems="center" space="$1.5">
|
|
<CalendarDays size={14} color={muted} />
|
|
<Text fontSize={12} color={muted}>
|
|
{formatDate(ev.event_date, t)}
|
|
</Text>
|
|
</XStack>
|
|
</YStack>
|
|
<PillBadge tone={ev.slug === activeEvent?.slug ? 'success' : 'muted'}>
|
|
{ev.slug === activeEvent?.slug ? t('events.detail.active', 'Aktiv') : t('events.actions.open', 'Öffnen')}
|
|
</PillBadge>
|
|
</XStack>
|
|
</Pressable>
|
|
))
|
|
)}
|
|
</YStack>
|
|
</MobileSheet>
|
|
|
|
<YStack space="$2">
|
|
<Text fontSize="$md" fontWeight="800" color={textStrong}>
|
|
{t('events.detail.managementTitle', 'Event Management')}
|
|
</Text>
|
|
<XStack flexWrap="wrap" space="$2">
|
|
<ActionTile
|
|
icon={Sparkles}
|
|
label={
|
|
tasksEnabled
|
|
? t('events.quick.tasks', 'Tasks & Checklists')
|
|
: `${t('events.quick.tasks', 'Tasks & Checklists')} (${t('common:states.disabled', 'Disabled')})`
|
|
}
|
|
color={ADMIN_ACTION_COLORS.tasks}
|
|
onPress={() => navigate(adminPath(`/mobile/events/${slug ?? ''}/tasks`))}
|
|
delayMs={0}
|
|
/>
|
|
<ActionTile
|
|
icon={QrCode}
|
|
label={t('events.quick.qr', 'QR Code Layouts')}
|
|
color={ADMIN_ACTION_COLORS.qr}
|
|
onPress={() => navigate(adminPath(`/mobile/events/${slug ?? ''}/qr`))}
|
|
delayMs={ADMIN_MOTION.tileStaggerMs}
|
|
/>
|
|
<ActionTile
|
|
icon={Image}
|
|
label={t('events.quick.images', 'Image Management')}
|
|
color={ADMIN_ACTION_COLORS.images}
|
|
onPress={() => navigate(adminPath(`/mobile/events/${slug ?? ''}/photos`))}
|
|
delayMs={ADMIN_MOTION.tileStaggerMs * 2}
|
|
/>
|
|
<ActionTile
|
|
icon={Tv}
|
|
label={t('events.quick.liveShow', 'Live Show queue')}
|
|
color={ADMIN_ACTION_COLORS.images}
|
|
onPress={() => slug && navigate(ADMIN_EVENT_LIVE_SHOW_PATH(slug))}
|
|
disabled={!slug}
|
|
delayMs={ADMIN_MOTION.tileStaggerMs * 3}
|
|
/>
|
|
<ActionTile
|
|
icon={Settings}
|
|
label={t('events.quick.liveShowSettings', 'Live Show settings')}
|
|
color={ADMIN_ACTION_COLORS.images}
|
|
onPress={() => slug && navigate(ADMIN_EVENT_LIVE_SHOW_SETTINGS_PATH(slug))}
|
|
disabled={!slug}
|
|
delayMs={ADMIN_MOTION.tileStaggerMs * 4}
|
|
/>
|
|
<ActionTile
|
|
icon={Users}
|
|
label={t('events.quick.guests', 'Guest Management')}
|
|
color={ADMIN_ACTION_COLORS.guests}
|
|
onPress={() => navigate(adminPath(`/mobile/events/${slug ?? ''}/members`))}
|
|
delayMs={ADMIN_MOTION.tileStaggerMs * 5}
|
|
/>
|
|
<ActionTile
|
|
icon={Megaphone}
|
|
label={t('events.quick.guestMessages', 'Guest messages')}
|
|
color={ADMIN_ACTION_COLORS.guestMessages}
|
|
onPress={() => slug && navigate(ADMIN_EVENT_GUEST_NOTIFICATIONS_PATH(slug))}
|
|
disabled={!slug}
|
|
delayMs={ADMIN_MOTION.tileStaggerMs * 6}
|
|
/>
|
|
<ActionTile
|
|
icon={Layout}
|
|
label={t('events.quick.branding', 'Branding & Theme')}
|
|
color={ADMIN_ACTION_COLORS.branding}
|
|
onPress={
|
|
brandingAllowed ? () => navigate(adminPath(`/mobile/events/${slug ?? ''}/branding`)) : undefined
|
|
}
|
|
disabled={!brandingAllowed}
|
|
delayMs={ADMIN_MOTION.tileStaggerMs * 7}
|
|
/>
|
|
<ActionTile
|
|
icon={Camera}
|
|
label={t('events.quick.photobooth', 'Photobooth')}
|
|
color={ADMIN_ACTION_COLORS.photobooth}
|
|
onPress={() => navigate(adminPath(`/mobile/events/${slug ?? ''}/photobooth`))}
|
|
delayMs={ADMIN_MOTION.tileStaggerMs * 8}
|
|
/>
|
|
{isPastEvent(event?.event_date) ? (
|
|
<ActionTile
|
|
icon={Sparkles}
|
|
label={t('events.quick.recap', 'Recap & Archive')}
|
|
color={ADMIN_ACTION_COLORS.recap}
|
|
onPress={() => navigate(adminPath(`/mobile/events/${slug ?? ''}/recap`))}
|
|
delayMs={ADMIN_MOTION.tileStaggerMs * 9}
|
|
/>
|
|
) : null}
|
|
</XStack>
|
|
</YStack>
|
|
</MobileShell>
|
|
);
|
|
}
|
|
|
|
function renderName(name: TenantEvent['name'], t: (key: string, fallback: string) => string): string {
|
|
const fallback = t('events.placeholders.untitled', 'Untitled event');
|
|
if (typeof name === 'string' && name.trim()) return name;
|
|
if (name && typeof name === 'object') {
|
|
return name.de ?? name.en ?? Object.values(name)[0] ?? fallback;
|
|
}
|
|
return fallback;
|
|
}
|
|
|
|
function formatDate(iso: string | null | undefined, t: (key: string, fallback: string) => string): string {
|
|
if (!iso) return t('events.detail.dateTbd', 'Date tbd');
|
|
const date = new Date(iso);
|
|
if (Number.isNaN(date.getTime())) return t('events.detail.dateTbd', 'Date tbd');
|
|
return date.toLocaleDateString(undefined, { month: 'short', day: 'numeric', year: 'numeric' });
|
|
}
|
|
|
|
function resolveLocation(event: TenantEvent | null, t: (key: string, fallback: string) => string): string {
|
|
if (!event) return t('events.detail.locationPlaceholder', 'Location');
|
|
const settings = (event.settings ?? {}) as Record<string, unknown>;
|
|
const candidate =
|
|
(settings.location as string | undefined) ??
|
|
(settings.address as string | undefined) ??
|
|
(settings.city as string | undefined);
|
|
if (candidate && candidate.trim()) {
|
|
return candidate;
|
|
}
|
|
return t('events.detail.locationPlaceholder', 'Location');
|
|
}
|