import { useRef, useState } from 'react'; import { Alert, Text, TextInput, View } from 'react-native'; import { useTranslation } from 'react-i18next'; import { useColors } from '../../../lib/theme'; import { apiFetch } from '../../../lib/api'; import { invalidateMe, useMe } from '../../../hooks/useMe'; import { OnboardingShell } from '../OnboardingShell'; import { LyraBubble } from '../LyraBubble'; import { CTABar } from '../CTABar'; export function NicknameSlide({ onNext, current, total, }: { onNext: () => void; current: number; total: number; }) { const { t } = useTranslation(); const colors = useColors(); const { me } = useMe(); const [nickname, setNickname] = useState(me?.nickname ?? ''); const [saving, setSaving] = useState(false); const inputRef = useRef(null); const trimmed = nickname.trim(); const valid = trimmed.length >= 2; async function save() { if (!valid || saving) return; setSaving(true); try { await apiFetch('/api/auth/me', { method: 'PATCH', body: { nickname: trimmed }, }); await apiFetch('/api/profile/me/onboarding-step', { method: 'PATCH', body: { step: 'account' }, }).catch(() => {}); invalidateMe(); onNext(); } catch (e: unknown) { Alert.alert( t('common.error'), e instanceof Error ? e.message : t('common.unknown_error'), ); } finally { setSaving(false); } } return ( } > {t('onboarding.nickname.label')} {t('onboarding.nickname.hint')} ); }