import React, { useState, useEffect, componentDidMount } from "react"; import { StyleSheet, SafeAreaView, Text, TextInput, View, NavigatorIOS } from "react-native"; import { Button} from 'native-base'; import { useTheme } from '@react-navigation/native'; function PersonalInformation({route, navigation}) { const { colors } = useTheme(); const [age, setAge] = useState(''); const [height, setHeight] = useState(''); const [weight, setWeight] = useState(''); const [gender, setGender] = useState(''); const postUserInfo=() => { fetch(localhost+'/signup', { method: "POST", headers: { 'Accept': 'application/json', 'Content-Type': 'application/json' }, body: JSON.stringify({ uid: route.params.uid, username: route.params.username, first_name: route.params.firstName, last_name: route.params.lastName, age: age, gender: gender, height: height, weight: weight }) }) .then( function(response) { if (response.status === 200 || response.status === 201) { // Successful POST console.log('good postUserInfo'); alert("Successfully created!") navigation.navigate("DefinedAvgStats", { username: route.params.username }); } else { // Examine the text in the response console.log('issue in postUserInfo. 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 information:</Text> <Text style={ [styles.subtitle, {color: colors.text}] }>Age in years:</Text> <TextInput placeholder = "20" style={ [styles.input, {color: colors.text}] } onChangeText={(age) => setAge(age)} /> <Text style={ [styles.subtitle, {color: colors.text}] }>Height in inches:</Text> <TextInput placeholder = "71" style={ [styles.input, {color: colors.text}] } onChangeText={(height) => setHeight(height)} /> <Text style={ [styles.subtitle, {color: colors.text}] }>Weight in pounds:</Text> <TextInput placeholder = "150" style={ [styles.input, {color: colors.text}] } onChangeText={(weight) => setWeight(weight)} /> <Text style={ [styles.subtitle, {color: colors.text}] }>Gender as male, female, or other:</Text> <TextInput placeholder = "male" style={ [styles.input, {color: colors.text}] } onChangeText={(gender) => setGender(gender)} /> <View style={{flexDirection: "row"}}> <Button style={ styles.nextButton } onPress={postUserInfo}> <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 PersonalInformation;