import React, { useState } from 'react'; import { View, StyleSheet, KeyboardAvoidingView, Platform, ScrollView, } from 'react-native'; import { Button, Text, Surface, TextInput, Divider, HelperText, } from 'react-native-paper'; import { SafeAreaView } from 'react-native-safe-area-context'; import { useDispatch } from 'react-redux'; import { authApi } from '../../lib/api/auth'; import { setUser, setError, clearError } from '../../store/slices/authSlice'; export function LoginScreen() { const dispatch = useDispatch(); const [loading, setLoading] = useState(false); const [email, setEmail] = useState(''); const [password, setPassword] = useState(''); const [showPassword, setShowPassword] = useState(false); const [localError, setLocalError] = useState(''); const handleGoogleLogin = async () => { setLoading(true); setLocalError(''); dispatch(clearError()); try { const user = await authApi.login(); dispatch(setUser(user)); } catch (err) { const message = err instanceof Error ? err.message : 'Login failed. Please try again.'; setLocalError(message); dispatch(setError(message)); } finally { setLoading(false); } }; const handleCredentialLogin = async () => { if (!email.trim() || !password) { setLocalError('Email and password are required.'); return; } setLoading(true); setLocalError(''); dispatch(clearError()); try { const user = await authApi.loginWithCredentials( email.trim().toLowerCase(), password, ); dispatch(setUser(user)); } catch (err) { const message = err instanceof Error ? err.message : 'Login failed. Please try again.'; setLocalError(message); dispatch(setError(message)); } finally { setLoading(false); } }; return ( Sea Haven Industries Proposal System Submit and manage proposals from anywhere setShowPassword(!showPassword)} /> } /> {localError ? ( {localError} ) : null} OR Use your Sea Haven email to sign in ); } const styles = StyleSheet.create({ container: { flex: 1, backgroundColor: '#FAFAFA', }, flex: { flex: 1, }, content: { flexGrow: 1, justifyContent: 'center', alignItems: 'center', paddingHorizontal: 32, paddingVertical: 24, }, logoContainer: { alignItems: 'center', marginBottom: 32, backgroundColor: 'transparent', }, brand: { fontWeight: '800', color: '#1565C0', }, brandSub: { color: '#757575', marginTop: -4, }, title: { fontWeight: '700', color: '#212121', marginBottom: 8, }, subtitle: { color: '#757575', textAlign: 'center', marginBottom: 32, }, form: { width: '100%', }, input: { marginBottom: 12, }, buttonContent: { paddingVertical: 8, }, button: { borderRadius: 8, width: '100%', }, dividerRow: { flexDirection: 'row', alignItems: 'center', width: '100%', marginVertical: 20, }, dividerLine: { flex: 1, }, dividerText: { color: '#9E9E9E', marginHorizontal: 16, }, footer: { color: '#9E9E9E', marginTop: 24, }, });