todosLists/Screen/SignUpScreen.js

54 lines
1.6 KiB
JavaScript
Raw Normal View History

2022-02-24 12:55:27 +01:00
import React, { useContext, useState } from 'react'
import { Text, View, TextInput, Button, StyleSheet } from 'react-native'
import signUp from '../components/SignUp'
import { UsernameContext, TokenContext } from '../Context/Context'
export default function SignUpScreen({ navigation }) {
const [ username, setUsername] = useContext(UsernameContext)
const [ token, setToken] = useContext(TokenContext)
const [ password, setPassword] = useState("")
const [error, setError] = useState("")
const signup = () => {
signUp(username, password)
.then(token => {
setToken(token)
setUsername(username)
}).catch(err => setError(err))
}
2022-02-11 08:58:55 +01:00
return (
2022-02-24 12:55:27 +01:00
<View style={styles.container}>
<Text>{error}</Text>
<Text>Token is {token === undefined ? "undefined" : (token === null ? "null" : token)}</Text>
<Text>username is {username}</Text>
<Text>Nom d'utilisateur:</Text>
<TextInput value={username} onChangeText={setUsername} onSubmitEditing={signup} style={styles.input}></TextInput>
<Text>Mot de passe:</Text>
<TextInput value={password} onChangeText={setPassword} onSubmitEditing={signup} style={styles.input} secureTextEntry={true}></TextInput>
<View style={styles.button}>
<Button onPress={signup} title="S'inscrire" />
</View>
</View>
2022-02-11 08:58:55 +01:00
);
}
2022-02-24 12:55:27 +01:00
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
marginHorizontal: 16,
},
input: {
height: 40,
margin: 12,
borderWidth: 1,
padding: 10,
},
button: {
padding: 10,
marginHorizontal: 30
}
});