-
Notifications
You must be signed in to change notification settings - Fork 0
/
AddRestaurant.js
164 lines (154 loc) · 5.2 KB
/
AddRestaurant.js
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
import React, { Component } from 'react';
import {View, Text, StyleSheet, TextInput, Button, ScrollView, Alert} from 'react-native';
export default class AddRestaurant extends Component {
static navigationOptions = {
title: 'Add Restaurants',
headerStyle:{
backgroundColor: '#008000',
},
headerTitleStyle:{
color: 'white',
fontSize: 25,
},
headerTintColor: 'white',
};
constructor(props){
super(props)
this.state = {
name: '',
address:'',
city:'',
region:'',
country:'',
postal_code:'',
phone:'',
veg_level: '',
short_description:''
}
}
sendData(){
fetch('http://10.0.2.2:2000/api/veggierestaurants/create', {
method: 'POST',
headers: {
Accept: 'application/json',
'Content-Type': 'application/json',
},
body: JSON.stringify({
name: this.state.name,
address: this.state.address,
city: this.state.city,
region: this.state.region,
country: this.state.country,
postal_code: this.state.postal_code,
phone: this.state.phone,
veg_level_description: this.state.veg_level,
short_description: this.state.short_description
}),
});
Alert.alert(
'Restaurant Added',
(this.state.name+' was successfully added to the database!'),
[
{text: 'OK'},
],
{cancelable: false},
);
}
render() {
return (
<ScrollView style = {{backgroundColor: '#ffffff'}}>
<Text style={styles.heading}>Name</Text>
<TextInput
style={styles.box}
onChangeText={(name) => this.setState({name})}
value={this.state.name}
/>
<Text style={styles.heading}>Address</Text>
<TextInput
style={styles.box}
onChangeText={(address) => this.setState({address})}
value={this.state.address}
/>
<Text style={styles.heading}>City</Text>
<TextInput
style={styles.box}
onChangeText={(city) => this.setState({city})}
value={this.state.city}
/>
<Text style={styles.heading}>Region</Text>
<TextInput
style={styles.box}
onChangeText={(region) => this.setState({region})}
value={this.state.region}
/>
<Text style={styles.heading}>Country</Text>
<TextInput
style={styles.box}
onChangeText={(country) => this.setState({country})}
value={this.state.country}
/>
<Text style={styles.heading}>Postcode</Text>
<TextInput
style={styles.box}
onChangeText={(postal_code) => this.setState({postal_code})}
value={this.state.postal_code}
/>
<Text style={styles.heading}>Phone Number</Text>
<TextInput
style={styles.box}
onChangeText={(phone) => this.setState({phone})}
value={this.state.phone}
/>
<Text style={styles.heading}>Veg Level</Text>
<TextInput
style={styles.box}
placeholder="Vegetarian/Vegan/Vegetarian-Friendly/Vegan-Friendly"
onChangeText={(veg_level) => this.setState({veg_level})}
value={this.state.veg_level}
/>
<Text style={styles.heading}>Short Description</Text>
<TextInput
style={styles.box}
onChangeText={(short_description) => this.setState({short_description})}
value={this.state.short_description}
/>
<View style = {styles.button}>
<Button color="#228b22" variant="raised" title="Submit" onPress={() => this.sendData()}
/>
</View>
</ScrollView>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: "center",
alignItems: "center",
backgroundColor: "#9FA8DA"
},
heading: {
fontSize: 23,
color:'#006400',
paddingLeft: 25,
paddingTop: 10
},
box: {
height: 40,
width: '85%',
backgroundColor: '#ffffff',
alignSelf: 'center',
borderTopColor: '#ffffff',
borderBottomColor: '#39fe66',
borderLeftColor: '#ffffff',
borderRightColor: '#ffffff',
borderWidth: 2,
paddingBottom: 15
},
button:{
paddingTop:40,
paddingBottom:20,
width: '85%',
alignSelf: 'center'
}
});