import React, { useState, useCallback, useEffect } from 'react'; import { View, Text, StyleSheet, KeyboardAvoidingView, Platform, ScrollView, TouchableOpacity, } from 'react-native'; import { router, useLocalSearchParams } from 'expo-router'; import { Ionicons } from '@expo/vector-icons'; import { Button } from '@/components/ui/Button'; import { Input } from '@/components/ui/Input'; import { ErrorMessage } from '@/components/ui/ErrorMessage'; import { AppColors, BorderRadius, FontSizes, Spacing } from '@/constants/theme'; import { api } from '@/services/api'; export default function EnterNameScreen() { const params = useLocalSearchParams<{ email: string; inviteCode: string }>(); const email = params.email || ''; const inviteCode = params.inviteCode || ''; const [firstName, setFirstName] = useState(''); const [lastName, setLastName] = useState(''); const [isLoading, setIsLoading] = useState(false); const [error, setError] = useState(null); const handleContinue = useCallback(async () => { setError(null); const trimmedFirstName = firstName.trim(); const trimmedLastName = lastName.trim(); if (!trimmedFirstName) { setError('Please enter your first name'); return; } setIsLoading(true); try { // Update profile with name via API const response = await api.updateProfile({ firstName: trimmedFirstName, lastName: trimmedLastName || undefined, }); if (!response.ok) { throw new Error(response.error?.message || 'Failed to update profile'); } // Navigate to add loved one screen (onboarding step 1) router.replace({ pathname: '/(auth)/add-loved-one', params: { email, inviteCode, }, }); } catch (err) { setError(err instanceof Error ? err.message : 'Failed to save name'); } finally { setIsLoading(false); } }, [firstName, lastName, email, inviteCode]); const handleSkip = () => { // Skip entering name and go to add loved one router.replace({ pathname: '/(auth)/add-loved-one', params: { email, inviteCode, }, }); }; return ( {/* Skip Button */} Skip {/* Icon */} {/* Header */} What's your name? This helps us personalize your experience {/* Error Message */} {error && ( setError(null)} /> )} {/* Form */} { setFirstName(text); setError(null); }} autoCapitalize="words" autoCorrect={false} editable={!isLoading} returnKeyType="next" /> {/* Continue Button */}