import React, { useState } from "react"; import { View, ScrollView, Pressable, TextInput, ActivityIndicator, } from "react-native"; import { useSirouRouter } from "@sirou/react-native"; import { AppRoutes } from "@/lib/routes"; import { Text } from "@/components/ui/text"; import { Button } from "@/components/ui/button"; import { ScreenWrapper } from "@/components/ScreenWrapper"; import { ArrowLeft, User, Check, X } from "@/lib/icons"; import { useAuthStore } from "@/lib/auth-store"; import { api } from "@/lib/api"; import { useToast } from "@/lib/toast-store"; import { useColorScheme } from "nativewind"; export default function EditProfileScreen() { const nav = useSirouRouter(); const { user, updateUser } = useAuthStore(); const { showToast } = useToast(); const { colorScheme } = useColorScheme(); const isDark = colorScheme === "dark"; const [loading, setLoading] = useState(false); const [firstName, setFirstName] = useState(user?.firstName || ""); const [lastName, setLastName] = useState(user?.lastName || ""); const handleSave = async () => { if (!firstName.trim() || !lastName.trim()) { showToast("First and last name are required", "error"); return; } setLoading(true); try { const response = await api.users.updateProfile({ body: { firstName: firstName.trim(), lastName: lastName.trim(), }, }); // Update local store with the returned user data updateUser(response); showToast("Profile updated successfully", "success"); nav.back(); } catch (e: any) { console.error("[EditProfile] Update failed:", e); showToast(e.message || "Failed to update profile", "error"); } finally { setLoading(false); } }; return ( {/* Header */} nav.back()} className="h-10 w-10 rounded-[10px] bg-card items-center justify-center border border-border" > Edit Profile {/* Spacer */} {/* First Name */} First Name {firstName.trim().length > 0 && ( )} {/* Last Name */} Last Name {lastName.trim().length > 0 && ( )} nav.back()} className="h-10 border border-border items-center justify-center" disabled={loading} > Cancel ); }