import React, { useState, useEffect } from 'react'; import { useParams, useNavigate } from 'react-router-dom'; import { useEventData } from '../hooks/useEventData'; import { useGuestIdentity } from '../context/GuestIdentityContext'; import { Input } from '@/components/ui/input'; import { Button } from '@/components/ui/button'; import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card'; import { Label } from '@/components/ui/label'; import { useTranslation } from '../i18n/useTranslation'; import { motion } from 'framer-motion'; import { FADE_SCALE, FADE_UP, STAGGER_FAST, getMotionContainerProps, getMotionItemProps, prefersReducedMotion } from '../lib/motion'; export default function ProfileSetupPage() { const { token } = useParams<{ token: string }>(); const nav = useNavigate(); const { event, loading, error } = useEventData(); const { name: storedName, setName: persistName, hydrated } = useGuestIdentity(); const [name, setName] = useState(storedName); const [submitting, setSubmitting] = useState(false); const { t } = useTranslation(); const motionEnabled = !prefersReducedMotion(); const containerMotion = getMotionContainerProps(motionEnabled, STAGGER_FAST); const fadeUpMotion = getMotionItemProps(motionEnabled, FADE_UP); const fadeScaleMotion = getMotionItemProps(motionEnabled, FADE_SCALE); useEffect(() => { if (!token) { nav('/'); return; } }, [token, nav]); useEffect(() => { if (hydrated) { setName(storedName); } }, [hydrated, storedName]); function handleChange(value: string) { setName(value); } function submitName() { if (!token) return; const trimmedName = name.trim(); if (!trimmedName) return; setSubmitting(true); try { persistName(trimmedName); nav(`/e/${token}`); } catch (e) { console.error('Fehler beim Speichern des Namens:', e); setSubmitting(false); } } if (loading) { return (
{error || t('profileSetup.error.default')}