stateful tabs and reliable back behavior, and a full onboarding flow is wired in with conditional package selection
(skips when an active package exists).
What changed
- Added per‑tab history + back navigation fallback to make tab switching/Back feel native (resources/js/admin/mobile/
lib/tabHistory.ts, resources/js/admin/mobile/hooks/useBackNavigation.ts, resources/js/admin/mobile/hooks/
useMobileNav.ts, resources/js/admin/mobile/components/MobileShell.tsx + updates across mobile pages).
- Implemented onboarding flow pages + shared shell, and wired new routes/prefetch (resources/js/admin/mobile/welcome/
WelcomeLandingPage.tsx, resources/js/admin/mobile/welcome/WelcomePackagesPage.tsx, resources/js/admin/mobile/
welcome/WelcomeSummaryPage.tsx, resources/js/admin/mobile/welcome/WelcomeEventPage.tsx, resources/js/admin/mobile/
components/OnboardingShell.tsx, resources/js/admin/router.tsx, resources/js/admin/mobile/prefetch.ts).
- Conditional package step: packages page redirects to event setup if activePackage exists; selection stored locally
for summary (resources/js/admin/mobile/lib/onboardingSelection.ts, resources/js/admin/mobile/welcome/
WelcomePackagesPage.tsx).
- Added a “Start welcome journey” CTA in the empty dashboard state (resources/js/admin/mobile/DashboardPage.tsx).
- Added translations for onboarding shell + selected package + dashboard CTA (resources/js/admin/i18n/locales/en/
onboarding.json, resources/js/admin/i18n/locales/de/onboarding.json, resources/js/admin/i18n/locales/en/
management.json, resources/js/admin/i18n/locales/de/management.json).
- Tests for new helpers/hooks (resources/js/admin/mobile/lib/tabHistory.test.ts, resources/js/admin/mobile/lib/
onboardingSelection.test.ts, resources/js/admin/mobile/hooks/useBackNavigation.test.tsx).
225 lines
7.4 KiB
TypeScript
225 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';
|
|
import { useBackNavigation } from './hooks/useBackNavigation';
|
|
|
|
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 back = useBackNavigation();
|
|
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={back}
|
|
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' });
|
|
}
|