|
@@ -0,0 +1,352 @@
|
|
1
|
+import React, { Component } from 'react';
|
|
2
|
+import { StyleSheet, TextInput, View, Alert, TouchableOpacity, Text, ScrollView, Platform,Picker,SafeAreaView} from 'react-native';
|
|
3
|
+import DatePicker from 'react-native-datepicker';
|
|
4
|
+import RNPickerSelect, { defaultStyles } from 'react-native-picker-select';
|
|
5
|
+import Constants from 'expo-constants';
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+export default class Product extends Component {
|
|
9
|
+
|
|
10
|
+ constructor(props) {
|
|
11
|
+
|
|
12
|
+ super(props)
|
|
13
|
+
|
|
14
|
+ this.state = {
|
|
15
|
+ uid:this.props.navigation.getParam('uid'),
|
|
16
|
+ lid:this.props.navigation.getParam('lid'),
|
|
17
|
+ name_p: '',
|
|
18
|
+ bought_date:'',
|
|
19
|
+ expiration_date:'',
|
|
20
|
+ iso_date:'',
|
|
21
|
+ i:'',
|
|
22
|
+ typ:'',
|
|
23
|
+ quantity:'',
|
|
24
|
+ notes:'',
|
|
25
|
+ renew:'',
|
|
26
|
+ picked:'no'
|
|
27
|
+
|
|
28
|
+ }
|
|
29
|
+ }
|
|
30
|
+
|
|
31
|
+ insertList_Function = () => {
|
|
32
|
+ this.setState({ picked: "yes" })
|
|
33
|
+ fetch('https://ada.uprrp.edu/~laura.gonzalez19/4030/insert_p.php', {
|
|
34
|
+ method: 'POST',
|
|
35
|
+ headers: {
|
|
36
|
+ 'Accept': 'application/json',
|
|
37
|
+ 'Content-Type': 'application/json',
|
|
38
|
+ },
|
|
39
|
+ body: JSON.stringify({
|
|
40
|
+
|
|
41
|
+ name_p: this.state.name_p,
|
|
42
|
+
|
|
43
|
+ lid: this.state.lid,
|
|
44
|
+
|
|
45
|
+ bought_date:this.state.bought_date,
|
|
46
|
+
|
|
47
|
+ expiration_date:this.state.expiration_date,
|
|
48
|
+
|
|
49
|
+ type:this.state.typ,
|
|
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("Status",responseJson, [
|
|
63
|
+ {
|
|
64
|
+ text: 'Cancel',
|
|
65
|
+ style: 'cancel'
|
|
66
|
+ },
|
|
67
|
+ { text: 'OK', onPress:() => this.props.navigation.navigate('Products') }
|
|
68
|
+ ],
|
|
69
|
+ { cancelable: false }
|
|
70
|
+ );
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+ //navigation.navigate('Landing');
|
|
75
|
+ });
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+ }
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+setBought=(data)=>{
|
|
83
|
+ this.setState({bought_date:data});
|
|
84
|
+ this.setExpiration;
|
|
85
|
+ }
|
|
86
|
+
|
|
87
|
+setType=(itemValue)=>{
|
|
88
|
+ this.setExpiration;
|
|
89
|
+ }
|
|
90
|
+
|
|
91
|
+setExpiration=()=>{
|
|
92
|
+
|
|
93
|
+if(this.state.typ!=='' && this.state.bought_date!=='' ){
|
|
94
|
+ const e_date=new Date(this.state.bought_date);
|
|
95
|
+ //this.setState({e_date: new Date(this.state.bought_date)});
|
|
96
|
+ if(this.state.typ==='fruits'){
|
|
97
|
+ e_date.setDate(e_date.getDate() + 5);
|
|
98
|
+ }
|
|
99
|
+ else if(this.state.typ==='eggs'){
|
|
100
|
+ e_date.setDate(e_date.getDate() + 28);
|
|
101
|
+ }
|
|
102
|
+ else if(this.state.typ==='meats'){
|
|
103
|
+ e_date.setDate(e_date.getDate() + 14);
|
|
104
|
+ }
|
|
105
|
+ else if(this.state.typ==='salads'){
|
|
106
|
+ e_date.setDate(e_date.getDate() + 3);
|
|
107
|
+ }
|
|
108
|
+
|
|
109
|
+ else if(this.state.typ==='poultry'){
|
|
110
|
+ e_date.setDate(e_date.getDate() + 2);
|
|
111
|
+ }
|
|
112
|
+
|
|
113
|
+ else if(this.state.typ==='soups'){
|
|
114
|
+ e_date.setDate(e_date.getDate() + 3);
|
|
115
|
+ }
|
|
116
|
+ else if(this.state.typ==='scr'){
|
|
117
|
+ e_date.setDate(e_date.getDate() + 4);
|
|
118
|
+ }
|
|
119
|
+ else if(this.state.typ==='bacon'){
|
|
120
|
+ e_date.setDate(e_date.getDate() + 7);
|
|
121
|
+ }
|
|
122
|
+ else if(this.state.typ==='sausage'){
|
|
123
|
+ e_date.setDate(e_date.getDate() + 2);
|
|
124
|
+ }
|
|
125
|
+
|
|
126
|
+ else if(this.state.typ==='gmeat'){
|
|
127
|
+ e_date.setDate(e_date.getDate() + 2);
|
|
128
|
+ }
|
|
129
|
+
|
|
130
|
+ else if(this.state.typ==='pizza'){
|
|
131
|
+ e_date.setDate(e_date.getDate() + 4);
|
|
132
|
+ }
|
|
133
|
+ this.setState({expiration_date: e_date.toISOString().slice(0,10)});
|
|
134
|
+ this.setState({ iso_date: e_date.toISOString().slice(0,10)});
|
|
135
|
+}
|
|
136
|
+}
|
|
137
|
+
|
|
138
|
+
|
|
139
|
+
|
|
140
|
+ render() {
|
|
141
|
+ return (
|
|
142
|
+
|
|
143
|
+
|
|
144
|
+ <ScrollView contentContainerStyle={{ flexGrow: 1, justifyContent: 'center' }}>
|
|
145
|
+ <View style={styles.MainContainer}>
|
|
146
|
+ <Text style={{ fontSize: 25, color: "#3414B3", textAlign: 'center', marginBottom: 15 }}>Products Form</Text>
|
|
147
|
+
|
|
148
|
+ <TextInput
|
|
149
|
+ placeholder="Product Name"
|
|
150
|
+ onChangeText={data => this.setState({ name_p: data })}
|
|
151
|
+ underlineColorAndroid='transparent'
|
|
152
|
+ style={styles.TextInputStyleClass}
|
|
153
|
+ />
|
|
154
|
+
|
|
155
|
+
|
|
156
|
+
|
|
157
|
+ <RNPickerSelect
|
|
158
|
+ placeholder={{label: 'Select type of food to refrigerate',color: 'gray',}}
|
|
159
|
+ items={ [{label: 'Fruits',value: 'fruits'}, {label: 'Unopened Luncheon Meat',value: 'meats'},{label: 'Eggs',value: 'eggs'},{label: 'Salad',value: 'salads'},{label: 'Fresh Poultry',value: 'poultry'},{label: 'Soups',value: 'soups'},{label: 'Steaks, Chops or Roasts',value: 'scr'},{label: 'Bacon',value: 'bacon'},{label: 'Sausage',value: 'sausage'},{label: 'Ground Meat(Hamburguers)',value: 'gmeat'},{label: 'Pizza',value: 'pizza'}]}
|
|
160
|
+
|
|
161
|
+ onValueChange={(itemValue, itemIndex) => {this.setState({typ:itemValue},()=>{ this.setExpiration();});}}
|
|
162
|
+ style={pickerSelectStyles}
|
|
163
|
+ useNativeAndroidPickerStyle={false}
|
|
164
|
+ />
|
|
165
|
+
|
|
166
|
+ <DatePicker
|
|
167
|
+ style={styles.TextInputStyleClass}
|
|
168
|
+ mode="date" // The enum of date, datetime and time
|
|
169
|
+ placeholder="Bought"
|
|
170
|
+ format="YYYY-MM-DD"
|
|
171
|
+ date={this.state.bought_date}
|
|
172
|
+ confirmBtnText="Confirm"
|
|
173
|
+ cancelBtnText="Cancel"
|
|
174
|
+ customStyles={{
|
|
175
|
+ dateIcon: {
|
|
176
|
+ position: 'absolute',
|
|
177
|
+ left: 2,
|
|
178
|
+ top: 3,
|
|
179
|
+ marginLeft: 0,
|
|
180
|
+ },
|
|
181
|
+ dateInput: {
|
|
182
|
+ marginLeft: 0,
|
|
183
|
+ },
|
|
184
|
+ }}
|
|
185
|
+ //onDateChange={data => this.setBought(data)}
|
|
186
|
+ onDateChange={data => {this.setState({bought_date:data},()=>{ this.setExpiration();});}}
|
|
187
|
+ />
|
|
188
|
+
|
|
189
|
+<Text style={{ fontSize: 15, color: "#3414B3", textAlign: 'center', marginBottom: 10 }}> Expected expiration date {this.state.iso_date} </Text>
|
|
190
|
+
|
|
191
|
+<Text style={{ fontSize: 10, color: "#3414B3", textAlign: 'center', marginBottom: 10 }}>Add date here if you prefer to add your own expiration date</Text>
|
|
192
|
+
|
|
193
|
+ <DatePicker
|
|
194
|
+ style={styles.datestyling}
|
|
195
|
+ mode="date" // The enum of date, datetime and time
|
|
196
|
+ date={this.state.expiration_date}
|
|
197
|
+ placeholder="Expiration"
|
|
198
|
+ format="YYYY-MM-DD"
|
|
199
|
+ confirmBtnText="Confirm"
|
|
200
|
+ cancelBtnText="Cancel"
|
|
201
|
+ customStyles={{
|
|
202
|
+ dateIcon: {
|
|
203
|
+ position: 'absolute',
|
|
204
|
+ left: 2,
|
|
205
|
+ top: 3,
|
|
206
|
+ marginLeft: 0,
|
|
207
|
+ },
|
|
208
|
+ dateInput: {
|
|
209
|
+ marginLeft: 0,
|
|
210
|
+ },
|
|
211
|
+ }}
|
|
212
|
+ onDateChange={data => this.setState({expiration_date:data})}
|
|
213
|
+
|
|
214
|
+ />
|
|
215
|
+
|
|
216
|
+
|
|
217
|
+
|
|
218
|
+<TextInput
|
|
219
|
+ placeholder="Quantity"
|
|
220
|
+ style={styles.TextInputStyleClass}
|
|
221
|
+ keyboardType = 'number-pad'
|
|
222
|
+ onChangeText = {(text)=> this.setState({quantity: text})}
|
|
223
|
+ value = {this.state.quantity}
|
|
224
|
+/>
|
|
225
|
+
|
|
226
|
+ <TextInput
|
|
227
|
+ placeholder="Notes"
|
|
228
|
+ onChangeText={data => this.setState({ notes: data })}
|
|
229
|
+ underlineColorAndroid='transparent'
|
|
230
|
+ style={styles.TextInputStyleClass}
|
|
231
|
+ />
|
|
232
|
+
|
|
233
|
+
|
|
234
|
+
|
|
235
|
+
|
|
236
|
+
|
|
237
|
+
|
|
238
|
+ <RNPickerSelect
|
|
239
|
+ placeholder={{label: 'Select to renew or not',color: '#9EA0A4',}}
|
|
240
|
+ items={ [{label: 'Renew',value: '1'}, {label: 'Do not Renew',value: '2'}]}
|
|
241
|
+ selectedValue={this.state.renew}
|
|
242
|
+ onValueChange={(itemValue, itemIndex) =>this.setState({renew: itemValue})}
|
|
243
|
+ style={pickerSelectStyles}
|
|
244
|
+ useNativeAndroidPickerStyle={false}
|
|
245
|
+ />
|
|
246
|
+
|
|
247
|
+
|
|
248
|
+ <TouchableOpacity style={styles.button} onPress={this.insertList_Function} >
|
|
249
|
+
|
|
250
|
+ <Text style={styles.text}>+</Text>
|
|
251
|
+
|
|
252
|
+ </TouchableOpacity>
|
|
253
|
+
|
|
254
|
+
|
|
255
|
+ <Text style={{ fontSize: 15, color: "#3414B3", textAlign: 'center', marginTop: 20, marginBottom: 15 }}>Start adding your products </Text>
|
|
256
|
+
|
|
257
|
+</View>
|
|
258
|
+ </ScrollView>
|
|
259
|
+
|
|
260
|
+
|
|
261
|
+ );
|
|
262
|
+ }
|
|
263
|
+}
|
|
264
|
+
|
|
265
|
+const styles = StyleSheet.create({
|
|
266
|
+
|
|
267
|
+ MainContainer: {
|
|
268
|
+ marginTop: Constants.statusBarHeight,
|
|
269
|
+ justifyContent: 'center',
|
|
270
|
+ alignItems: 'center',
|
|
271
|
+ flex: 1,
|
|
272
|
+ margin: 10
|
|
273
|
+ },
|
|
274
|
+
|
|
275
|
+ TextInputStyleClass: {
|
|
276
|
+ color: 'gray',
|
|
277
|
+ textAlign: 'center',
|
|
278
|
+ marginBottom: 7,
|
|
279
|
+ height: 40,
|
|
280
|
+ width: '80%',
|
|
281
|
+ borderWidth: 1,
|
|
282
|
+ borderColor: '#3414B3'
|
|
283
|
+ },
|
|
284
|
+
|
|
285
|
+ datestyling: {
|
|
286
|
+ textAlign: 'center',
|
|
287
|
+ color: 'gray',
|
|
288
|
+ marginBottom: 7,
|
|
289
|
+ height: 40,
|
|
290
|
+ width: '80%',
|
|
291
|
+ borderWidth: 1,
|
|
292
|
+ borderColor: '#3414B3'
|
|
293
|
+ },
|
|
294
|
+
|
|
295
|
+ button: {
|
|
296
|
+ height:50,
|
|
297
|
+ width: 50,
|
|
298
|
+ paddingTop: 2,
|
|
299
|
+ paddingBottom: 2,
|
|
300
|
+ backgroundColor: '#3414B3',
|
|
301
|
+ borderRadius: 100,
|
|
302
|
+ marginTop: 20,
|
|
303
|
+ alignItems: 'center'
|
|
304
|
+ },
|
|
305
|
+
|
|
306
|
+ text: {
|
|
307
|
+ color: '#fff',
|
|
308
|
+ fontSize: 30,
|
|
309
|
+ textAlign: 'center',
|
|
310
|
+ padding: 0
|
|
311
|
+ },
|
|
312
|
+
|
|
313
|
+
|
|
314
|
+}
|
|
315
|
+
|
|
316
|
+);
|
|
317
|
+
|
|
318
|
+const pickerSelectStyles = StyleSheet.create({
|
|
319
|
+ inputIOS: {
|
|
320
|
+ textAlign: 'center',
|
|
321
|
+ marginLeft:35,
|
|
322
|
+ borderWidth: 1,
|
|
323
|
+ fontSize: 16,
|
|
324
|
+ borderColor: '#3414B3',
|
|
325
|
+ marginBottom: 7,
|
|
326
|
+ height: 40,
|
|
327
|
+ width: '80%',
|
|
328
|
+ color: 'gray'
|
|
329
|
+ },
|
|
330
|
+ inputAndroid: {
|
|
331
|
+ textAlign: "center",
|
|
332
|
+ borderWidth: 1,
|
|
333
|
+ fontSize: 16,
|
|
334
|
+ borderColor: '#3414B3',
|
|
335
|
+ marginBottom: 7,
|
|
336
|
+ height: 40,
|
|
337
|
+ width: 270,
|
|
338
|
+ color: 'gray'
|
|
339
|
+ },
|
|
340
|
+
|
|
341
|
+ inputWeb: {
|
|
342
|
+ color: 'gray',
|
|
343
|
+ alignItems: 'center',
|
|
344
|
+ fontSize: 16,
|
|
345
|
+ textAlign: 'center',
|
|
346
|
+ marginBottom: 7,
|
|
347
|
+ height: 40,
|
|
348
|
+ width: '80%',
|
|
349
|
+ borderWidth: 1,
|
|
350
|
+ borderColor: '#3414B3',
|
|
351
|
+ }
|
|
352
|
+});
|