Selaa lähdekoodia

Upload files to ''

Add Product.js which is for product input
laura.gonzalez19 4 vuotta sitten
vanhempi
commit
58799ac4aa
1 muutettua tiedostoa jossa 252 lisäystä ja 0 poistoa
  1. 252
    0
      Product.js

+ 252
- 0
Product.js Näytä tiedosto

@@ -0,0 +1,252 @@
1
+import React, { Component } from 'react';
2
+import { StyleSheet, TextInput, View, Alert, TouchableOpacity, Text, ScrollView, Platform,Picker} from 'react-native';
3
+import DatePicker from 'react-native-datepicker';
4
+import RNPickerSelect, { defaultStyles } from 'react-native-picker-select';
5
+
6
+const food=[{label:'food',value:'food'},{label:'not food',value:'notfood'}];
7
+
8
+export default class Product extends Component {
9
+  
10
+  constructor(props) {
11
+
12
+    super(props)
13
+
14
+    this.state = {
15
+      uid:'1234',
16
+      lid:'5678',
17
+      name_p: '',
18
+	    bought_date:'',
19
+      expiration_date:'',
20
+      type:'fresh',
21
+      quantity:'',
22
+      notes:'',
23
+      renew:'1',
24
+      picked:'no'
25
+
26
+    }
27
+  }
28
+  
29
+  insertList_Function = () => {
30
+    this.setState({ picked: "yes" })
31
+    fetch('https://ada.uprrp.edu/~laura.gonzalez19/4030/insert_productsss.php', {
32
+      method: 'POST',
33
+      headers: {
34
+        'Accept': 'application/json',
35
+        'Content-Type': 'application/json',
36
+      },
37
+      body: JSON.stringify({
38
+
39
+    name_p: this.state.name_p,
40
+
41
+    lid: this.state.lid,
42
+		
43
+		uid: this.state.uid,
44
+		
45
+		bought_date:this.state.bought_date,
46
+		
47
+		expiration_date:this.state.expiration_date,
48
+		
49
+		type:this.state.type,
50
+		
51
+		quantity:this.state.quantity,
52
+		
53
+		renew:this.state.renew,
54
+		
55
+		notes:this.state.notes,
56
+
57
+      })
58
+
59
+    }).then((response) => response.json())
60
+      .then((responseJson) => {
61
+        // Showing response message coming from server after inserting records.
62
+        Alert.alert(responseJson);
63
+      });
64
+
65
+
66
+  }
67
+
68
+  render() {
69
+    return (
70
+
71
+
72
+      <View style={styles.MainContainer}>
73
+      
74
+        <Text style={{ fontSize: 25, color: "#3414B3", textAlign: 'center', marginBottom: 15 }}>Add Products!</Text>
75
+
76
+		<TextInput
77
+          placeholder="Product Name"
78
+          onChangeText={data => this.setState({ name_p: data })}
79
+          underlineColorAndroid='transparent'
80
+          style={styles.TextInputStyleClass}
81
+        />
82
+       
83
+		<DatePicker
84
+          style={styles.TextInputStyleClass}
85
+          mode="date" // The enum of date, datetime and time
86
+          placeholder="Bought"
87
+          format="YYYY-MM-DD"
88
+          date={this.state.bought_date}
89
+          confirmBtnText="Confirm"
90
+          cancelBtnText="Cancel"
91
+          customStyles={{
92
+            dateIcon: {
93
+              position: 'absolute',
94
+              left: 0,
95
+              top: 4,
96
+              marginLeft: 0,
97
+            },
98
+            dateInput: {
99
+              marginLeft: 36,
100
+            },
101
+          }}
102
+          onDateChange={data => this.setState({bought_date:data}) }
103
+          
104
+        />
105
+  		<DatePicker
106
+          style={styles.TextInputStyleClass}
107
+          mode="date" // The enum of date, datetime and time
108
+          date={this.state.expiration_date}
109
+          placeholder="Expiration"
110
+          format="YYYY-MM-DD"
111
+          confirmBtnText="Confirm"
112
+          cancelBtnText="Cancel"
113
+          customStyles={{
114
+            dateIcon: {
115
+              position: 'absolute',
116
+              left: 0,
117
+              top: 4,
118
+              marginLeft: 0,
119
+            },
120
+            dateInput: {
121
+              marginLeft: 36,
122
+            },
123
+          }}
124
+          onDateChange={data => this.setState({expiration_date:data}) }
125
+          
126
+        />
127
+
128
+<TextInput 
129
+  placeholder="Quantity"
130
+  style={styles.TextInputStyleClass}
131
+  keyboardType = 'number-pad'
132
+  onChangeText = {(text)=> this.setState({quantity: text})}
133
+  value = {this.state.quantity}
134
+/>
135
+
136
+		<TextInput
137
+          placeholder="Notes"
138
+          onChangeText={data => this.setState({ notes: data })}
139
+          underlineColorAndroid='transparent'
140
+          style={styles.TextInputStyleClass}
141
+        />
142
+
143
+ 
144
+
145
+          <RNPickerSelect
146
+          placeholder={{label: 'Select type of food...',color: '#9EA0A4',}}
147
+            items={ [{label: 'Fruit',value: 'fruit'}, {label: 'Meat',value: 'meat'}]}
148
+            selectedValue={this.state.type}
149
+            onValueChange={(itemValue, itemIndex) =>this.setState({type: itemValue})}
150
+            style={pickerSelectStyles}
151
+            useNativeAndroidPickerStyle={false}
152
+          />
153
+
154
+
155
+        <RNPickerSelect
156
+            placeholder={{label: 'Select to renew or not...',color: '#9EA0A4',}}
157
+            items={ [{label: 'Renew',value: '1'}, {label: 'Do not Renew',value: '0'}]}
158
+              selectedValue={this.state.renew}
159
+              onValueChange={(itemValue, itemIndex) => this.setState({renew: itemValue})} 
160
+              style={pickerSelectStyles}
161
+            useNativeAndroidPickerStyle={false}
162
+          />
163
+
164
+
165
+      <TouchableOpacity style={styles.button} onPress={this.insertList_Function} >
166
+
167
+          <Text style={styles.text}>+</Text>
168
+
169
+        </TouchableOpacity>
170
+
171
+
172
+		<Text style={{ fontSize: 15, color: "#3414B3", textAlign: 'center', marginTop: 20, marginBottom: 15 }}>Start adding your products </Text>
173
+
174
+
175
+      </View>
176
+
177
+    );
178
+  }
179
+}
180
+
181
+const styles = StyleSheet.create({
182
+
183
+  MainContainer: {
184
+
185
+    justifyContent: 'center',
186
+    alignItems: 'center',
187
+    flex: 1,
188
+    margin: 10
189
+  },
190
+
191
+  TextInputStyleClass: {
192
+    color: 'gray',
193
+    textAlign: 'center',
194
+    marginBottom: 7,
195
+    height: 40,
196
+    width: '80%',
197
+    borderWidth: 1,
198
+    borderColor: '#3414B3'
199
+  },
200
+
201
+  button: {
202
+	  height:50,
203
+    width: 50,
204
+    paddingTop: 2,
205
+    paddingBottom: 2,
206
+    backgroundColor: '#3414B3',
207
+    borderRadius: 100,
208
+    marginTop: 20
209
+  },
210
+
211
+  text: {
212
+    color: '#fff',
213
+    fontSize: 32,
214
+    textAlign: 'center',
215
+    padding: 0
216
+  },
217
+
218
+}
219
+
220
+);
221
+
222
+const pickerSelectStyles = StyleSheet.create({
223
+  inputIOS: {
224
+    fontSize: 16,
225
+    borderWidth: 1,
226
+    paddingVertical: 12,
227
+    paddingHorizontal: 10,
228
+    borderColor: '#3414B3',
229
+    color: 'gray',
230
+    marginTop: 20,
231
+    paddingRight: 30, // to ensure the text is never behind the icon
232
+  },
233
+  inputAndroid: {
234
+    justifyContent: 'center',
235
+    borderWidth: 1,
236
+    alignItems: 'center',
237
+    fontSize: 16,
238
+    paddingHorizontal: 10,
239
+    paddingVertical: 8,
240
+    
241
+    paddingTop: 2,
242
+    paddingBottom: 2,
243
+    borderColor: '#3414B3',
244
+    marginBottom: 7,
245
+    height: 40,
246
+    width: 270,
247
+    color: 'gray',
248
+    paddingRight: 30, // to ensure the text is never behind the icon
249
+  },
250
+});
251
+
252
+