// app/onboarding.tsx import { View, Text, KeyboardAvoidingView, Platform, ScrollView } from 'react-native'; import { useState } from 'react'; import { router } from 'expo-router'; import { Input } from '@/components/ui/Input'; import { Button } from '@/components/ui/Button'; import { useUserStore } from '@/store/useUserStore'; import { getDatabase } from '@/lib/database'; import * as Crypto from 'expo-crypto'; export default function OnboardingScreen() { const [name, setName] = useState(''); const [loading, setLoading] = useState(false); const [error, setError] = useState(''); const setUser = useUserStore((s) => s.setUser); async function handleContinue() { if (!name.trim()) { setError('Please enter your name'); return; } setLoading(true); try { const id = Crypto.randomUUID(); const shareId = Crypto.randomUUID().replace(/-/g, '').substring(0, 12).toUpperCase(); const now = Math.floor(Date.now() / 1000); const db = await getDatabase(); await db.runAsync( 'INSERT INTO users (id, display_name, share_id, is_self, created_at) VALUES (?, ?, ?, 1, ?)', [id, name.trim(), shareId, now] ); setUser({ id, displayName: name.trim(), shareId }); router.replace('/(tabs)'); } catch (e) { setError('Something went wrong. Please try again.'); } finally { setLoading(false); } } return ( TerritoryLog Your ministry field records, private and organized. What should we call you? { setName(t); setError(''); }} error={error} autoFocus returnKeyType="done" onSubmitEditing={handleContinue} />