import { useAlert } from '@/components/AlertComponent'; import api from '@/utils/api'; import { ArrowLeft, Mail, Send } from 'lucide-react-native'; import { useState } from 'react'; import { Image, Platform, Text, TextInput, TouchableOpacity, View } from 'react-native'; import { KeyboardAwareScrollView } from 'react-native-keyboard-controller'; import { useRouter } from 'expo-router'; export default function ForgotPasswordScreen() { const alert = useAlert(); const router = useRouter(); const [identifier, setIdentifier] = useState(''); const [isLoading, setIsLoading] = useState(false); const handleSubmit = async () => { if (!identifier.trim()) { alert.showAlert('error', 'Attenzione', 'Inserisci email o username'); return; } setIsLoading(true); try { await api.post('/user/forgot-password', { identifier: identifier.trim() }); alert.showAlert( 'success', 'Richiesta Inviata', 'Se l\'account esiste, riceverai un\'email con il link per reimpostare la password.' ); router.back(); } catch (error: any) { let message = 'Si è verificato un errore. Riprova più tardi.'; if (error.request && !error.response) { message = 'Impossibile contattare il server. Controlla la connessione.'; } else if (error.response) { message = `Errore Server: ${error.response.data?.message || error.response.status}`; } alert.showAlert('error', 'Errore', message); } finally { setIsLoading(false); } }; return ( {/* Header with Logo */} {/* Form Container */} {/* Title */} Recupero Password Inserisci la tua email o username. Ti invieremo un link per reimpostare la password. {/* Input Email / Username */} Email o Username {/* Submit Button */} {isLoading ? 'Invio in corso...' : 'Invia Link'} {!isLoading && } {/* Back to Login */} router.back()} className="flex-row justify-center items-center mt-2" activeOpacity={0.7} > Torna al Login ); }