import React, { useState } from "react"; import { StyleSheet, SafeAreaView, Text, TextInput, View } from "react-native"; import { Button} from 'native-base'; import { useTheme } from '@react-navigation/native'; function Username({route, navigation}) { const { colors } = useTheme(); const [username, setUsername] = useState(''); function checkHandleUsername() { fetch(localhost+'/signup/'+username, { method: "GET", headers: { 'Accept': 'application/json', 'Content-Type': 'application/json', } }) .then( function(response) { if (response.status === 200 || response.status === 201) { console.log('good checkUsername'); response.json().then(function(data) { if (data.length == 0) { navigation.navigate("Password", { firstName: route.params.firstName, lastName: route.params.lastName, email: route.params.email, username: username }); } else { alert("Username already exists: Please enter a different username.") setUsername(''); } }) } else { // Examine the text in the response console.log('issue in handleLogin. Status code: '+ response.status); alert("Unsuccessful") } } ) .catch(function(err) { console.log('Fetch Error :-S', err); }); } return ( <SafeAreaView style={ [styles.screen, {flexDirection:"column"}] }> <Text style={ [styles.title, {color: colors.text}] }>Enter your username:</Text> <Text style={ [styles.subtitle, {color: colors.text}] }>This is how others will find your profile.</Text> <TextInput placeholder = "purduepete" style={ [styles.input, {color: colors.text}] } value={username} onChangeText={(username) => setUsername(username)} /> <View style={{flexDirection: "row"}}> <Button style={ styles.nextButton } onPress={checkHandleUsername}> <Text style={ styles.nextText } >Next</Text> </Button> </View> </SafeAreaView> ); } const styles = StyleSheet.create({ screen:{ marginTop: "20%", paddingLeft: "5%", paddingRight: "5%", paddingBottom: "30%", marginLeft: "10%", marginRight: "10%" }, title: { fontSize: 25, fontWeight: "bold", marginTop: "10%", paddingBottom: "20%", textAlign:"left" }, subtitle: { fontSize: 16, textAlign:"left", fontWeight: "bold", color: '#5c5a55' }, input: { width: "100%", height: 40, borderBottomWidth: 1 }, nextButton: { width: '100%', justifyContent: 'center', backgroundColor: "#d4911c", borderRadius: 10, alignItems: "center", marginBottom: 10, marginTop: 50 }, nextText: { fontSize: 16, fontWeight: "bold", color: "white" }, }); export default Username;