import React from 'react'; import { useNavigate } from 'react-router-dom'; import { useTranslation } from 'react-i18next'; import { useQuery } from '@tanstack/react-query'; import { CheckCircle2, Package as PackageIcon } from 'lucide-react'; import { YStack, XStack } from '@tamagui/stacks'; import { SizableText as Text } from '@tamagui/text'; import { OnboardingShell } from '../components/OnboardingShell'; import { MobileCard, CTAButton, PillBadge } from '../components/Primitives'; import { getPackages, getTenantPackagesOverview } from '../../api'; import { ADMIN_WELCOME_BASE_PATH, ADMIN_WELCOME_EVENT_PATH, ADMIN_WELCOME_PACKAGES_PATH, adminPath } from '../../constants'; import { getSelectedPackageId } from '../lib/onboardingSelection'; import { ADMIN_COLORS } from '../theme'; type SummaryPackage = { id: number; name: string; max_photos: number | null; max_guests: number | null; gallery_days: number | null; active: boolean; remaining_events?: number | null; }; export default function WelcomeSummaryPage() { const navigate = useNavigate(); const { t } = useTranslation('onboarding'); const selectedId = getSelectedPackageId(); const { data: catalog, isLoading: catalogLoading } = useQuery({ queryKey: ['mobile', 'onboarding', 'packages-list'], queryFn: () => getPackages('endcustomer'), staleTime: 60_000, }); const { data: overview, isLoading: overviewLoading } = useQuery({ queryKey: ['mobile', 'onboarding', 'packages-overview'], queryFn: () => getTenantPackagesOverview({ force: true }), staleTime: 60_000, }); const selectedPackage = catalog?.find((pkg) => pkg.id === selectedId) ?? null; const activePackage = overview?.activePackage ?? null; const hasActivePackage = Boolean(activePackage) || Boolean(overview?.packages?.some((pkg) => pkg.active)); const resolvedPackage: SummaryPackage | null = selectedPackage ? { id: selectedPackage.id, name: selectedPackage.name, max_photos: selectedPackage.max_photos ?? null, max_guests: selectedPackage.max_guests ?? null, gallery_days: selectedPackage.gallery_days ?? null, active: false, } : activePackage ? { id: activePackage.id, name: activePackage.package_name ?? 'Package', max_photos: (activePackage.package_limits as any)?.max_photos ?? null, max_guests: (activePackage.package_limits as any)?.max_guests ?? null, gallery_days: (activePackage.package_limits as any)?.gallery_days ?? null, active: true, remaining_events: activePackage.remaining_events ?? null, } : null; const loading = catalogLoading || overviewLoading; const backTarget = selectedPackage ? ADMIN_WELCOME_PACKAGES_PATH : ADMIN_WELCOME_BASE_PATH; return ( navigate(backTarget)} onSkip={() => navigate(adminPath('/mobile/billing#packages'))} skipLabel={t('summary.cta.billing.button', 'Go to billing')} > {loading ? ( {t('summary.state.loading', 'Checking available packages …')} ) : !resolvedPackage ? ( {t('summary.state.missingTitle', 'No package selected')} {t('summary.state.missingDescription', 'Select a package first or refresh if data changed.')} navigate(ADMIN_WELCOME_PACKAGES_PATH)} /> ) : ( {resolvedPackage.name} {resolvedPackage.active ? t('summary.details.section.statusActive', 'Already purchased') : t('summary.details.section.statusInactive', 'Not purchased yet')} {resolvedPackage.active ? t('summary.details.section.statusActive', 'Already purchased') : t('packages.card.select', 'Select package')} {resolvedPackage.remaining_events !== undefined && resolvedPackage.remaining_events !== null ? ( ) : null} {resolvedPackage.active ? ( {t('summary.details.section.statusActive', 'Already purchased')} ) : null} )} {t('summary.nextStepsTitle', 'Next steps')} {(t('summary.nextSteps', { returnObjects: true, defaultValue: [ 'Optional: finish billing via Paddle inside the billing area.', 'Complete the event setup and configure tasks, team, and gallery.', 'Check your event slots before go-live and share your guest link.', ], }) as string[]).map((item) => ( {item} ))} navigate(adminPath('/mobile/billing#packages'))} fullWidth={false} /> navigate(ADMIN_WELCOME_EVENT_PATH)} disabled={!resolvedPackage && !hasActivePackage} fullWidth={false} /> ); } function SummaryRow({ label, value }: { label: string; value: string }) { return ( {label} {value} ); }