before merge
This commit is contained in:
+208
-71
@@ -1,5 +1,5 @@
|
||||
import React, { useState } from 'react';
|
||||
import { View, Text, Dimensions, TextInput, TouchableOpacity, StyleSheet, StatusBar, KeyboardAvoidingView, Platform, ScrollView } from 'react-native';
|
||||
import { View, Text, Dimensions, TextInput, TouchableOpacity, StyleSheet, KeyboardAvoidingView, Platform, ScrollView, Alert } from 'react-native';
|
||||
import LinearGradient from 'react-native-linear-gradient';
|
||||
import { Formik } from 'formik';
|
||||
import * as Yup from 'yup';
|
||||
@@ -7,17 +7,18 @@ import Animated, { FadeInUp, FadeInDown } from 'react-native-reanimated';
|
||||
import { Mail, Lock, Eye, EyeOff, ArrowRight } from 'lucide-react-native';
|
||||
import colors from '../../Constant/Color';
|
||||
import ImagePath from '../../Constant/ImagePath';
|
||||
import { useLogin } from '../../Services/BBPS/Hooks';
|
||||
import { useAuctionLogin, usefetchMasterData, useGetDesignation, useLogin, useRagistrationState } from '../../Services/BBPS/Hooks';
|
||||
import { useDispatch } from 'react-redux';
|
||||
import { setToken } from '../../Redux/Slices/Token';
|
||||
import { showErrorAlert } from '../../Constant/ShowDailog';
|
||||
import { useNavigation, CommonActions } from '@react-navigation/native';
|
||||
import NavigationString from '../../Constant/NavigationString';
|
||||
import ReactNativeHapticFeedback from "react-native-haptic-feedback";
|
||||
import ReactNativeHapticFeedback from 'react-native-haptic-feedback';
|
||||
import { Loader } from '../../Component/Index';
|
||||
|
||||
const hapticOptions = {
|
||||
enableVibrateFallback: true,
|
||||
ignoreAndroidSystemSettings: false
|
||||
ignoreAndroidSystemSettings: false,
|
||||
};
|
||||
const { height, width } = Dimensions.get('window');
|
||||
|
||||
@@ -27,51 +28,145 @@ const LoginSchema = Yup.object().shape({
|
||||
});
|
||||
|
||||
const Login = () => {
|
||||
const Navigation: any = useNavigation()
|
||||
const Dispatch = useDispatch()
|
||||
const Navigation: any = useNavigation();
|
||||
const Dispatch = useDispatch();
|
||||
const [passwordVisible, setPasswordVisible] = React.useState(false);
|
||||
const [loading, setLoading] = useState(false)
|
||||
const { mutate, isPending } = useLogin()
|
||||
const [activeType, setActiveType] = useState<'tender' | 'auction'>('tender');
|
||||
const [loginLoading, setLoginLoading] = useState(false);
|
||||
const [auctionLoading, setAuctionLoading] = useState(false);
|
||||
const { mutate: loginMutate } = useLogin();
|
||||
const { mutate: auctionMutate } = useAuctionLogin();
|
||||
const {data}=useGetDesignation();
|
||||
const { mutate: registrationStateMutate } = useRagistrationState();
|
||||
|
||||
const HandleLogin = async (values: any) => {
|
||||
setLoading(true)
|
||||
mutate({ password: values.password, emailAdd: values.email }, {
|
||||
onSuccess: (res) => {
|
||||
if (res.statusCode == 200) {
|
||||
console.log("login token : ", res)
|
||||
Dispatch(setToken({ ...res.data, token: res.token }))
|
||||
Navigation.dispatch(
|
||||
CommonActions.reset({
|
||||
index: 0,
|
||||
routes: [
|
||||
{ name: NavigationString.Home },
|
||||
],
|
||||
})
|
||||
);
|
||||
const { data: MasterData}=usefetchMasterData()
|
||||
console.log("master data ",MasterData)
|
||||
|
||||
const handleGetData = async () => {
|
||||
|
||||
|
||||
registrationStateMutate(undefined, {
|
||||
onSuccess: (res: any) => {
|
||||
console.log('Registration status response try :', res);
|
||||
|
||||
if (res?.statusCode === 200) {
|
||||
const { registrationStatus, contOtherId, contOrganization } = res.data;
|
||||
const params = { otherId: contOtherId, orgType: contOrganization };
|
||||
|
||||
console.log('==========pop', registrationStatus);
|
||||
|
||||
switch (registrationStatus) {
|
||||
case null:
|
||||
case undefined:
|
||||
|
||||
Navigation.replace(NavigationString.Registration);
|
||||
break;
|
||||
case 'Pending':
|
||||
|
||||
// handleRoute(params);
|
||||
break;
|
||||
case 'Complete':
|
||||
case 'Completed':
|
||||
Navigation.dispatch(
|
||||
CommonActions.reset({
|
||||
index: 0,
|
||||
routes: [{ name: NavigationString.Home }],
|
||||
}),
|
||||
);
|
||||
break;
|
||||
default:
|
||||
{
|
||||
console.log("attempting navigation to Ragistration")
|
||||
Navigation.replace(NavigationString.Registration);}
|
||||
break;
|
||||
}
|
||||
setLoading(false)
|
||||
},
|
||||
onError: (err) => {
|
||||
showErrorAlert(err.message)
|
||||
setLoading(false)
|
||||
return;
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
if (res?.statusCode === 404) {
|
||||
console.warn('Registration API returned 404');
|
||||
Navigation.replace('Registration');
|
||||
return;
|
||||
}
|
||||
|
||||
Navigation.replace('Registration');
|
||||
},
|
||||
onError: (error: any) => {
|
||||
console.error('Registration status error catch :', error);
|
||||
|
||||
if (error?.response?.status === 500) {
|
||||
Alert.alert('Server error', 'Something went wrong. Please try again later.');
|
||||
return;
|
||||
}
|
||||
|
||||
if (error?.request) {
|
||||
Alert.alert('Network Error', 'Please check your internet connection.');
|
||||
return;
|
||||
}
|
||||
|
||||
Alert.alert('Error', error?.message || 'Something went wrong');
|
||||
Navigation.replace('Registration');
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
|
||||
const HandleLogin = async (values: any) => {
|
||||
if (activeType === 'tender') {
|
||||
setLoginLoading(true);
|
||||
loginMutate(
|
||||
{ password: values.password, emailAdd: values.email },
|
||||
{
|
||||
onSuccess: res => {
|
||||
if (res.statusCode == 200) {
|
||||
Dispatch(setToken({ ...res.data, token: res.token }));
|
||||
handleGetData();
|
||||
|
||||
|
||||
}
|
||||
setLoginLoading(false);
|
||||
},
|
||||
onError: err => {
|
||||
showErrorAlert(err.message);
|
||||
setLoginLoading(false);
|
||||
},
|
||||
},
|
||||
);
|
||||
} else {
|
||||
setAuctionLoading(true);
|
||||
auctionMutate(
|
||||
{ password: values.password, emailAdd: values.email },
|
||||
{
|
||||
onSuccess: res => {
|
||||
if (res.statusCode == 200) {
|
||||
Dispatch(setToken({ ...res.data, token: res.token }));
|
||||
Navigation.dispatch(
|
||||
CommonActions.reset({
|
||||
index: 0,
|
||||
routes: [{ name: NavigationString.Home }],
|
||||
}),
|
||||
);
|
||||
}
|
||||
setAuctionLoading(false);
|
||||
},
|
||||
onError: err => {
|
||||
showErrorAlert(err.message);
|
||||
setAuctionLoading(false);
|
||||
},
|
||||
},
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
const isLoading = activeType === 'tender' ? loginLoading : auctionLoading;
|
||||
|
||||
return (
|
||||
<View style={styles.container}>
|
||||
<KeyboardAvoidingView
|
||||
behavior={Platform.OS === 'ios' ? 'padding' : 'height'}
|
||||
style={{ flex: 1 }}
|
||||
>
|
||||
<KeyboardAvoidingView behavior={Platform.OS === 'ios' ? 'padding' : 'height'} style={{ flex: 1 }}>
|
||||
<ScrollView contentContainerStyle={{ flexGrow: 1 }} bounces={false}>
|
||||
|
||||
{/* Header */}
|
||||
<View style={styles.header}>
|
||||
<LinearGradient
|
||||
colors={[colors.primary, colors.primaryLight || '#4c669f']}
|
||||
style={styles.gradient}
|
||||
>
|
||||
<LinearGradient colors={[colors.primary, colors.primaryLight || '#4c669f']} style={styles.gradient}>
|
||||
<Animated.Image
|
||||
entering={FadeInDown.delay(200).duration(800)}
|
||||
source={ImagePath.Icon.Logo}
|
||||
@@ -81,24 +176,42 @@ const Login = () => {
|
||||
</LinearGradient>
|
||||
</View>
|
||||
|
||||
<Animated.View
|
||||
entering={FadeInUp.springify().damping(15)}
|
||||
style={styles.formContainer}
|
||||
>
|
||||
<Animated.View entering={FadeInUp.springify().damping(15)} style={styles.formContainer}>
|
||||
<View style={styles.sheetHandle} />
|
||||
|
||||
<View style={styles.toggleWrapper}>
|
||||
<View style={styles.toggleContainer}>
|
||||
<TouchableOpacity
|
||||
activeOpacity={0.8}
|
||||
style={[styles.toggleButton, activeType === 'tender' && styles.toggleButtonActive]}
|
||||
onPress={() => setActiveType('tender')}
|
||||
disabled={isLoading}
|
||||
>
|
||||
<Text style={[styles.toggleText, activeType === 'tender' && styles.toggleTextActive]}>Tender</Text>
|
||||
</TouchableOpacity>
|
||||
<TouchableOpacity
|
||||
activeOpacity={0.8}
|
||||
style={[styles.toggleButton, activeType === 'auction' && styles.toggleButtonActive]}
|
||||
onPress={() => setActiveType('auction')}
|
||||
disabled={isLoading}
|
||||
>
|
||||
<Text style={[styles.toggleText, activeType === 'auction' && styles.toggleTextActive]}>Auction</Text>
|
||||
</TouchableOpacity>
|
||||
</View>
|
||||
</View>
|
||||
|
||||
<Text style={styles.title}>Welcome Back</Text>
|
||||
<Text style={styles.subtitle}>Enter your details to access your account</Text>
|
||||
|
||||
<Formik
|
||||
initialValues={{ email: '', password: '' }}
|
||||
validationSchema={LoginSchema}
|
||||
onSubmit={(values) => {
|
||||
HandleLogin(values)
|
||||
onSubmit={values => {
|
||||
HandleLogin(values);
|
||||
}}
|
||||
>
|
||||
{({ handleChange, handleBlur, handleSubmit, values, errors, touched }) => (
|
||||
<View style={{}}>
|
||||
<View>
|
||||
<Text style={styles.label}>Email Address</Text>
|
||||
<View style={[styles.inputWrapper, touched.email && errors.email && styles.inputError]}>
|
||||
<Mail size={20} color={touched.email && !errors.email ? colors.primary : colors.grayText} />
|
||||
@@ -140,11 +253,11 @@ const Login = () => {
|
||||
<TouchableOpacity
|
||||
activeOpacity={0.8}
|
||||
onPress={() => {
|
||||
ReactNativeHapticFeedback.trigger("impactLight", hapticOptions);
|
||||
ReactNativeHapticFeedback.trigger('impactLight', hapticOptions);
|
||||
handleSubmit();
|
||||
}}
|
||||
|
||||
style={styles.buttonShadow}
|
||||
disabled={isLoading}
|
||||
>
|
||||
<LinearGradient
|
||||
colors={[colors.primary, colors.primaryLight || '#4c669f']}
|
||||
@@ -152,13 +265,25 @@ const Login = () => {
|
||||
end={{ x: 1, y: 0 }}
|
||||
style={styles.button}
|
||||
>
|
||||
{
|
||||
loading ? <Loader color={colors.white} size='small'/> : <>
|
||||
{isLoading ? (
|
||||
<Loader color={colors.white} size="small" />
|
||||
) : (
|
||||
<>
|
||||
<Text style={styles.buttonText}>Sign In</Text>
|
||||
<ArrowRight size={20} color={colors.white} style={{ marginLeft: 8, marginTop: 5 }} /></>
|
||||
}
|
||||
<ArrowRight size={20} color={colors.white} style={{ marginLeft: 8, marginTop: 5 }} />
|
||||
</>
|
||||
)}
|
||||
</LinearGradient>
|
||||
</TouchableOpacity>
|
||||
|
||||
<View style={{ alignItems: 'center', marginTop: 16 }}>
|
||||
<View style={{ flexDirection: 'row' }}>
|
||||
<Text>Don't have an account? </Text>
|
||||
<TouchableOpacity onPress={() => Navigation.navigate('Signup')}>
|
||||
<Text style={{ color: colors.primary, fontWeight: '700' }}>Sign up</Text>
|
||||
</TouchableOpacity>
|
||||
</View>
|
||||
</View>
|
||||
</View>
|
||||
)}
|
||||
</Formik>
|
||||
@@ -195,12 +320,10 @@ const styles = StyleSheet.create({
|
||||
borderTopRightRadius: 35,
|
||||
paddingHorizontal: 28,
|
||||
paddingTop: 10,
|
||||
// Shadow for iOS
|
||||
shadowColor: '#000',
|
||||
shadowOffset: { width: 0, height: -10 },
|
||||
shadowOpacity: 0.1,
|
||||
shadowRadius: 10,
|
||||
// Elevation for Android
|
||||
elevation: 20,
|
||||
},
|
||||
sheetHandle: {
|
||||
@@ -209,8 +332,37 @@ const styles = StyleSheet.create({
|
||||
backgroundColor: '#E0E0E0',
|
||||
borderRadius: 10,
|
||||
alignSelf: 'center',
|
||||
marginBottom: 16,
|
||||
},
|
||||
toggleWrapper: {
|
||||
alignItems: 'center',
|
||||
marginBottom: 20,
|
||||
},
|
||||
toggleContainer: {
|
||||
flexDirection: 'row',
|
||||
backgroundColor: '#F1F3F5',
|
||||
borderRadius: 20,
|
||||
padding: 4,
|
||||
width: width * 0.5,
|
||||
},
|
||||
toggleButton: {
|
||||
flex: 1,
|
||||
paddingVertical: 8,
|
||||
borderRadius: 16,
|
||||
alignItems: 'center',
|
||||
justifyContent: 'center',
|
||||
},
|
||||
toggleButtonActive: {
|
||||
backgroundColor: colors.primary,
|
||||
},
|
||||
toggleText: {
|
||||
fontSize: 14,
|
||||
fontWeight: '600',
|
||||
color: '#7C7C7C',
|
||||
},
|
||||
toggleTextActive: {
|
||||
color: colors.white,
|
||||
},
|
||||
title: {
|
||||
fontSize: 28,
|
||||
fontWeight: '800',
|
||||
@@ -287,21 +439,6 @@ const styles = StyleSheet.create({
|
||||
fontSize: 18,
|
||||
fontWeight: '700',
|
||||
},
|
||||
footer: {
|
||||
flexDirection: 'row',
|
||||
justifyContent: 'center',
|
||||
marginTop: 30,
|
||||
paddingBottom: 20,
|
||||
},
|
||||
footerText: {
|
||||
color: '#7C7C7C',
|
||||
fontSize: 15,
|
||||
},
|
||||
signUpText: {
|
||||
color: colors.primary,
|
||||
fontWeight: '700',
|
||||
fontSize: 15,
|
||||
},
|
||||
});
|
||||
|
||||
export default Login;
|
||||
export default Login;
|
||||
|
||||
Reference in New Issue
Block a user