ADD: ajout du contenu du screen signIn

stub-api
Alban GUILHOT 3 years ago
parent a8a26682ae
commit 142eec96b4

@ -1,24 +1,49 @@
import { StatusBar } from 'expo-status-bar' import { StatusBar } from 'expo-status-bar'
import { StyleSheet, View, ImageSourcePropType, Pressable, Text} from 'react-native' import { StyleSheet, View, ImageSourcePropType, Pressable, Text} from 'react-native'
import React from 'react'; import React, { useState } from 'react';
import stylesScreen from './style/screens.style' import stylesScreen from './style/screens.style'
import { TextInput } from 'react-native-gesture-handler'; import { TextInput } from 'react-native-gesture-handler';
import { CustomTextInput } from '../components/CustomTextInput'; import { CustomTextInput } from '../components/CustomTextInput';
import { ButtonGameTypeChoice } from '../components/ButtonGameTypeChoice'; import { ButtonGameTypeChoice } from '../components/ButtonGameTypeChoice';
import { User } from "../core/user";
import tabUS from "../constUser";
import styles from "./style/SignIn.style" import styles from "./style/SignIn.style"
import { useDispatch, useSelector } from 'react-redux';
import { RootState } from '../redux/store';
import { loginUser } from '../redux/features/currentUserSlice';
function SignIn(props: { navigation: any; }) { function SignIn(props: { navigation: any; }) {
const { navigation } = props const { navigation } = props
const [pseudo, setPseudo] = useState('');
const [password, setPassword] = useState('');
const dispatch=useDispatch();
function userVerif(login: string, password: string, nav: any){
if((tabUS.map((User) => User.getUsername()).indexOf(login)) !== -1){
let id = (tabUS.map((User) => User.getUsername()).indexOf(login))
if ((tabUS.map((User) => User.getUsername()).indexOf(login) === id) && ( tabUS[id].getPassword() === password) ){
dispatch(loginUser(tabUS[id]));
nav.navigate('HomeTab');
}
}
}
return ( return (
<View style={stylesScreen.container}> <View style={stylesScreen.container}>
<View style={stylesScreen.bodyCenter}> <View style={stylesScreen.bodyCenter}>
<CustomTextInput placeholder={""} text="ID"/> <TextInput style={styles.textInput} placeholder='Login' onChangeText={(val) => setPseudo(val)} autoCapitalize='none' />
<CustomTextInput placeholder={""} text="Password"/> <TextInput style={styles.textInput} placeholder='Password' onChangeText={(val) => setPassword(val)} autoCapitalize='none' />
<Pressable style={styles.button} onPress={navigation.navigate('Home')}> <Pressable style={styles.button} onPress={() => userVerif(pseudo, password, navigation)}>
<Text style={styles.text}>Se connecter</Text> <Text style={styles.text}>Se connecter</Text>
</Pressable> </Pressable>
<Pressable> <Pressable onPress={() => navigation.navigate('SignUp')}>
<Text style={styles.signup}>Pas de compte? Inscrivez vous !</Text> <Text style={styles.signup}>Pas de compte? Inscrivez vous !</Text>
</Pressable> </Pressable>
</View> </View>

@ -24,4 +24,9 @@ export default StyleSheet.create({
color:'white', color:'white',
textDecorationLine:"underline", textDecorationLine:"underline",
}, },
textInput: {
width: '50%',
height: '5%',
backgroundColor: 'white',
}
}); });
Loading…
Cancel
Save