patterns, skeleton loading, photo selection/bulk actions with shared‑element transitions, notification detail sheet,
offline banner, maskable manifest icons, and route prefetching.
Key changes
- Navigation/shell: press feedback on all header actions, glassy sticky header and tab bar, safer bottom spacing
(resources/js/admin/mobile/components/MobileShell.tsx, resources/js/admin/mobile/components/BottomNav.tsx).
- Forms + lists: shared mobile form controls, list‑style rows in settings/profile, consistent inputs across core
flows (resources/js/admin/mobile/components/FormControls.tsx, resources/js/admin/mobile/SettingsPage.tsx,
resources/js/admin/mobile/ProfilePage.tsx, resources/js/admin/mobile/EventFormPage.tsx, resources/js/admin/mobile/
EventMembersPage.tsx, resources/js/admin/mobile/EventTasksPage.tsx, resources/js/admin/mobile/
EventGuestNotificationsPage.tsx, resources/js/admin/mobile/NotificationsPage.tsx, resources/js/admin/mobile/
EventPhotosPage.tsx, resources/js/admin/mobile/EventsPage.tsx).
- Media workflows: shared‑element photo transitions, selection mode + bulk actions bar (resources/js/admin/mobile/
EventPhotosPage.tsx).
- Loading UX: shimmering skeletons (resources/css/app.css, resources/js/admin/mobile/components/Primitives.tsx).
- PWA polish + perf: maskable icons, offline banner hook, and route prefetch (public/manifest.json, resources/js/
admin/mobile/hooks/useOnlineStatus.tsx, resources/js/admin/mobile/prefetch.ts, resources/js/admin/main.tsx).
223 lines
7.4 KiB
TypeScript
223 lines
7.4 KiB
TypeScript
import React from 'react';
|
|
import { useNavigate } from 'react-router-dom';
|
|
import { CalendarDays, MapPin, Plus, Search } 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 { useTranslation } from 'react-i18next';
|
|
import { MobileShell, HeaderActionButton } from './components/MobileShell';
|
|
import { MobileCard, PillBadge, CTAButton, FloatingActionButton, SkeletonCard } from './components/Primitives';
|
|
import { MobileInput } from './components/FormControls';
|
|
import { getEvents, TenantEvent } from '../api';
|
|
import { adminPath } from '../constants';
|
|
import { isAuthError } from '../auth/tokens';
|
|
import { getApiErrorMessage } from '../lib/apiError';
|
|
import { useTheme } from '@tamagui/core';
|
|
|
|
export default function MobileEventsPage() {
|
|
const { t } = useTranslation('management');
|
|
const navigate = useNavigate();
|
|
const [events, setEvents] = React.useState<TenantEvent[]>([]);
|
|
const [loading, setLoading] = React.useState(true);
|
|
const [error, setError] = React.useState<string | null>(null);
|
|
const [query, setQuery] = React.useState('');
|
|
const searchRef = React.useRef<HTMLInputElement>(null);
|
|
const theme = useTheme();
|
|
const text = String(theme.color?.val ?? '#111827');
|
|
const muted = String(theme.gray?.val ?? '#4b5563');
|
|
const subtle = String(theme.gray8?.val ?? '#6b7280');
|
|
const border = String(theme.borderColor?.val ?? '#e5e7eb');
|
|
const primary = String(theme.primary?.val ?? '#007AFF');
|
|
const danger = String(theme.red10?.val ?? '#b91c1c');
|
|
const surface = String(theme.surface?.val ?? '#ffffff');
|
|
React.useEffect(() => {
|
|
(async () => {
|
|
try {
|
|
setEvents(await getEvents());
|
|
} catch (err) {
|
|
if (!isAuthError(err)) {
|
|
setError(getApiErrorMessage(err, t('events.errors.loadFailed', 'Event konnte nicht geladen werden.')));
|
|
}
|
|
} finally {
|
|
setLoading(false);
|
|
}
|
|
})();
|
|
}, [t]);
|
|
|
|
return (
|
|
<MobileShell
|
|
activeTab="home"
|
|
title={t('events.list.dashboardTitle', 'All Events Dashboard')}
|
|
onBack={() => navigate(-1)}
|
|
headerActions={
|
|
<HeaderActionButton onPress={() => searchRef.current?.focus()} ariaLabel={t('events.list.search', 'Search events')}>
|
|
<Search size={18} color={text} />
|
|
</HeaderActionButton>
|
|
}
|
|
>
|
|
{error ? (
|
|
<MobileCard>
|
|
<Text fontWeight="700" color={danger}>
|
|
{error}
|
|
</Text>
|
|
</MobileCard>
|
|
) : null}
|
|
|
|
<MobileInput
|
|
ref={searchRef}
|
|
type="search"
|
|
value={query}
|
|
onChange={(e) => setQuery(e.target.value)}
|
|
placeholder={t('events.list.search', 'Search events')}
|
|
compact
|
|
style={{ marginBottom: 12 }}
|
|
/>
|
|
|
|
{loading ? (
|
|
<YStack space="$2">
|
|
{Array.from({ length: 3 }).map((_, idx) => (
|
|
<SkeletonCard key={`sk-${idx}`} height={90} />
|
|
))}
|
|
</YStack>
|
|
) : events.length === 0 ? (
|
|
<MobileCard alignItems="center" justifyContent="center" space="$3">
|
|
<Text fontSize="$md" fontWeight="700">
|
|
{t('events.list.empty.title', 'Noch kein Event angelegt')}
|
|
</Text>
|
|
<Text fontSize="$sm" color={muted} textAlign="center">
|
|
{t('events.list.empty.description', 'Starte jetzt mit deinem ersten Event.')}
|
|
</Text>
|
|
<CTAButton label={t('events.actions.create', 'Create New Event')} onPress={() => navigate(adminPath('/events/new'))} />
|
|
</MobileCard>
|
|
) : (
|
|
<YStack space="$3">
|
|
{events
|
|
.filter((event) => {
|
|
if (!query.trim()) return true;
|
|
const hay = `${event.name ?? ''} ${event.location ?? ''}`.toLowerCase();
|
|
return hay.includes(query.toLowerCase());
|
|
})
|
|
.map((event) => (
|
|
<EventRow
|
|
key={event.id}
|
|
event={event}
|
|
text={text}
|
|
muted={muted}
|
|
subtle={subtle}
|
|
border={border}
|
|
primary={primary}
|
|
onOpen={(slug) => navigate(adminPath(`/mobile/events/${slug}`))}
|
|
onEdit={(slug) => navigate(adminPath(`/mobile/events/${slug}/edit`))}
|
|
/>
|
|
))}
|
|
</YStack>
|
|
)}
|
|
|
|
<FloatingActionButton
|
|
label={t('events.actions.create', 'Create New Event')}
|
|
icon={Plus}
|
|
onPress={() => navigate(adminPath('/mobile/events/new'))}
|
|
/>
|
|
</MobileShell>
|
|
);
|
|
}
|
|
|
|
function EventRow({
|
|
event,
|
|
text,
|
|
muted,
|
|
subtle,
|
|
border,
|
|
primary,
|
|
onOpen,
|
|
onEdit,
|
|
}: {
|
|
event: TenantEvent;
|
|
text: string;
|
|
muted: string;
|
|
subtle: string;
|
|
border: string;
|
|
primary: string;
|
|
onOpen: (slug: string) => void;
|
|
onEdit: (slug: string) => void;
|
|
}) {
|
|
const status = resolveStatus(event);
|
|
return (
|
|
<MobileCard borderColor={border}>
|
|
<XStack justifyContent="space-between" alignItems="flex-start" space="$2">
|
|
<YStack space="$1">
|
|
<Text fontSize="$md" fontWeight="800" color={text}>
|
|
{renderName(event.name)}
|
|
</Text>
|
|
<XStack alignItems="center" space="$2">
|
|
<CalendarDays size={14} color={subtle} />
|
|
<Text fontSize="$sm" color={muted}>
|
|
{formatDate(event.event_date)}
|
|
</Text>
|
|
</XStack>
|
|
<XStack alignItems="center" space="$2">
|
|
<MapPin size={14} color={subtle} />
|
|
<Text fontSize="$sm" color={muted}>
|
|
{resolveLocation(event)}
|
|
</Text>
|
|
</XStack>
|
|
<PillBadge tone={status.tone}>{status.label}</PillBadge>
|
|
</YStack>
|
|
<Pressable onPress={() => onEdit(event.slug)}>
|
|
<Text fontSize="$xl" color={muted}>
|
|
˅
|
|
</Text>
|
|
</Pressable>
|
|
</XStack>
|
|
|
|
<Pressable onPress={() => onOpen(event.slug)} style={{ marginTop: 8 }}>
|
|
<XStack alignItems="center" justifyContent="flex-start" space="$2">
|
|
<Plus size={16} color={primary} />
|
|
<Text fontSize="$sm" color={primary} fontWeight="700">
|
|
Open event
|
|
</Text>
|
|
</XStack>
|
|
</Pressable>
|
|
</MobileCard>
|
|
);
|
|
}
|
|
|
|
function resolveStatus(event: TenantEvent): { label: string; tone: 'success' | 'warning' | 'muted' } {
|
|
if (event.status === 'published') {
|
|
return { label: 'Upcoming', tone: 'success' };
|
|
}
|
|
if (event.status === 'draft') {
|
|
return { label: 'Draft', tone: 'warning' };
|
|
}
|
|
return { label: 'Past', tone: 'muted' };
|
|
}
|
|
|
|
function renderName(name: TenantEvent['name']): string {
|
|
if (typeof name === 'string') return name;
|
|
if (name && typeof name === 'object') {
|
|
return name.de ?? name.en ?? Object.values(name)[0] ?? 'Unbenanntes Event';
|
|
}
|
|
return 'Unbenanntes Event';
|
|
}
|
|
|
|
function resolveLocation(event: TenantEvent): string {
|
|
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 'Location';
|
|
}
|
|
|
|
function formatDate(iso: string | null): string {
|
|
if (!iso) return 'Date tbd';
|
|
const date = new Date(iso);
|
|
if (Number.isNaN(date.getTime())) {
|
|
return 'Date tbd';
|
|
}
|
|
return date.toLocaleDateString(undefined, { month: 'short', day: 'numeric', year: 'numeric' });
|
|
}
|