aboutsummaryrefslogtreecommitdiff
path: root/mobile/screens/Form1.js
blob: 16ced64ed3e78bf2bf98da9aff355e187e06303a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
import React, { Component } from 'react';
import {Text, Alert, AppRegistry, StyleSheet, View } from 'react-native';
import { Button, Input, CheckBox } from 'react-native-elements';

export default class Form1 extends Component {
  _onPressButton1() {
    const { navigation } = this.props;
    const coordinates = navigation.getParam('coordinates');
    //var coordinates = this.coordinates ? coordinates : [];
    fetch('https://helpthehome-qa.herokuapp.com/mobilerequest', {
      method: 'POST',
      headers: {
        Accept: 'application/json',
        'Content-Type': 'application/json',
      },
      body: JSON.stringify({
        'coordinates': coordinates,
        'type': "Point",
        'isInjured': this.state.injured,
        'reasonForHelp': this.state.why,
        'ageRange': this.state.age,
        'clothingDescription': this.state.appearance
    }),
  });
  // TODO: handle the response from the serve and decide what to display
  // based on that
  // for now just to back to the home page
  Alert.alert("You will now be redirected to the main page");
  this.props.navigation.navigate('GreetingPage');
}
  _onPressButton2() {
    Alert.alert('Continue:')
  }
  constructor(props) {
    super(props);
      this.state = {
        age: '',
        appearance: '',
        injured: false,
        why: ''
      };
  }

  render() {
    return (
      <View style={{padding: 40}}>
        <Text>Age:</Text>
          <Input
            style={{height: 40}}
            placeholder="Estimate is fine"
            onChangeText={(age) => this.setState({age})}
          />
        <Text>Appearance:</Text>
          <Input
            style={{height: 40}}
            placeholder="What are they wearing?"
            onChangeText={(appearance) => this.setState({appearance})}
          />
        <CheckBox
            center
            title="Are they injured?"
            checked={this.state.injured}
            onPress={() => this.setState({ injured: !this.state.injured })}
          />
        <Text>Reason for help?</Text>
            <Input
              style={{height: 40}}
              placeholder="Please keep it short"
              onChangeText={(why) => this.setState({why})}
            />
        <View style={{padding: 40}}>
          <Button
              buttonStyle={{backgroundColor:"green"}}
              onPress={() => this._onPressButton1()}
              title="Submit!"
          />
          <Button
              containerStyle={{paddingTop: 10}}
              onPress={() =>  this.props.navigation.navigate('GreetingPage')}
              title="Go Back"
          />
        </View>
      </View>
    );
  }
}