import React, { useState } from 'react';
import {
View,
Text,
KeyboardAvoidingView,
Platform,
ScrollView,
TouchableOpacity,
Alert,
} from 'react-native';
import Svg, { Circle, Rect, Path, G } from 'react-native-svg';
import { getStyles } from './LoginScreen.styles';
import { CustomInput, PrimaryButton } from '@components';
import { useAppTheme } from '@theme';
import { useNavigation } from '@react-navigation/native';
import { NativeStackNavigationProp } from '@react-navigation/native-stack';
import { AuthStackParamList } from '@navigation/navigationTypes';
import { RouteNames } from '@utils/constants';
import {
loginWithPhone,
RootState,
useAppDispatch,
useAppSelector,
} from '@store';
// Premium SVG Mascot: Delivery boy on scooter
const DeliveryScooterSvg = () => {
return (
);
};
export const LoginScreen: React.FC = () => {
const { colors } = useAppTheme();
const styles = getStyles(colors);
const navigation =
useNavigation>();
const [mobileNumber, setMobileNumber] = useState('');
// const [password, setPassword] = useState('');
// const [isLoading, setIsLoading] = useState(false);
const [errors, setErrors] = useState<{ mobile?: string }>({});
const dispatch = useAppDispatch();
const { loading } = useAppSelector((state: RootState) => state.auth);
const validate = () => {
const newErrors: { mobile?: string } = {};
if (!mobileNumber) {
newErrors.mobile = 'Mobile number is required';
} else if (mobileNumber.length < 9) {
newErrors.mobile = 'Please enter a valid mobile number';
}
// if (!password) {
// newErrors.password = 'Password is required';
// } else if (password.length < 4) {
// newErrors.password = 'Password must be at least 4 characters';
// }
setErrors(newErrors);
return Object.keys(newErrors).length === 0;
};
const handleLogin = () => {
if (!validate()) return;
dispatch(loginWithPhone(mobileNumber))
.unwrap()
.then(() => {
navigation.navigate(RouteNames.Otp, { phone: mobileNumber });
})
.catch((error: any) => {
Alert.alert('Error', error.message);
});
};
// const handleForgotPassword = () => {
// Alert.alert('Forgot Password', 'OTP verification will be sent to recover password.');
// };
const handleSignUp = () => {
Alert.alert('Sign Up', 'Redirecting to register partner profile...');
};
return (
Welcome Partner!
Login to continue
{
setMobileNumber(text);
if (errors.mobile) setErrors({ ...errors, mobile: undefined });
}}
error={errors.mobile}
/>
{/* {
setPassword(text);
if (errors.password) setErrors({ ...errors, password: undefined });
}}
error={errors.password}
/> */}
Don’t have an account?{' '}
Sign up
);
};
export default LoginScreen;