import React, { useState } from "react"; import { View, Text, TextInput, TouchableOpacity, ActivityIndicator, ScrollView, useColorScheme, } from "react-native"; import { SafeAreaView } from "react-native-safe-area-context"; import { Ionicons } from "@expo/vector-icons"; import { useAuth } from "@/context/AuthContext"; export default function EditProfile({ onClose }: { onClose: () => void }) { const dark = useColorScheme() === "dark"; const accent = dark ? "#E07B45" : "#C4622D"; const { user, updateUser } = useAuth(); const [newEmail, setNewEmail] = useState(""); const [newPassword, setNewPassword] = useState(""); const [confirmPass, setConfirmPass] = useState(""); const [showPass, setShowPass] = useState(false); const [loading, setLoading] = useState(false); const [error, setError] = useState(""); const [success, setSuccess] = useState(""); const inputClass = `rounded-xl px-4 py-3.5 text-sm font-sans border ${ dark ? "bg-obsidian-100 border-border-dark text-ink-dark" : "bg-parchment-100 border-border-light text-ink-light" }`; const save = async () => { setError(""); setSuccess(""); if (newPassword && newPassword !== confirmPass) { setError("Passwords don't match."); return; } if (!newEmail && !newPassword) { setError("Enter a new email or password to update."); return; } setLoading(true); try { await updateUser( newEmail || undefined, newPassword || undefined, ); setSuccess("Profile updated successfully."); setNewEmail(""); setNewPassword(""); setConfirmPass(""); } catch (e: any) { setError(e.message ?? "Update failed. Please try again."); } finally { setLoading(false); } }; return ( {/* Header */} Edit Profile {/* Current email (read-only) */} CURRENT EMAIL {user?.email} {/* Change email TODO fix this show if email is taken and there is also a bug when trying to change email many times ill fix it later if i feel like it or someone else can */} NEW EMAIL {/* Divider */} {/* New password */} NEW PASSWORD setShowPass((v) => !v)} className="absolute right-3 top-3.5" > {/* Confirm password */} CONFIRM NEW PASSWORD {/* Error */} {error !== "" && ( {error} )} {/* Success */} {success !== "" && ( {success} )} {/* Save button */} {loading ? : Save changes } ); }