import { useState } from 'react'; import { Alert, Text } from 'react-native'; import { Stack } from 'expo-router'; import { useAction, useMutation, useQuery } from 'convex/react'; import { api } from '@spoon/backend/convex/_generated/api.js'; import { AppScreen } from '~/components/ui/app-screen'; import { Button } from '~/components/ui/button'; import { Card } from '~/components/ui/card'; import { Field } from '~/components/ui/field'; import { titleize } from '~/utils/format'; const ProfileRoute = () => { const user = useQuery(api.auth.getUser, {}); const provider = useQuery(api.auth.getUserProvider, {}); const updateUser = useMutation(api.auth.updateUser); const updatePassword = useAction(api.auth.updateUserPassword); const [name, setName] = useState(user?.name ?? ''); const [email, setEmail] = useState(user?.email ?? ''); const [currentPassword, setCurrentPassword] = useState(''); const [newPassword, setNewPassword] = useState(''); const [savingProfile, setSavingProfile] = useState(false); const [savingPassword, setSavingPassword] = useState(false); const saveProfile = async () => { setSavingProfile(true); try { await updateUser({ name, email }); Alert.alert('Saved', 'Profile updated.'); } catch (error) { console.error(error); Alert.alert('Could not save profile.'); } finally { setSavingProfile(false); } }; const savePassword = async () => { setSavingPassword(true); try { await updatePassword({ currentPassword, newPassword }); setCurrentPassword(''); setNewPassword(''); Alert.alert('Saved', 'Password updated.'); } catch (error) { console.error(error); Alert.alert('Could not update password.'); } finally { setSavingPassword(false); } }; return ( Profile Email is currently managed by {titleize(provider ?? 'your provider')}. {provider === 'password' ? ( Password ) : ( Password changes are hidden because this account is currently using{' '} {titleize(provider ?? 'an OAuth provider')}. )} ); }; export default ProfileRoute;