import React, { Component } from 'react'; import { StyleSheet, TextInput, View, Alert, TouchableOpacity, Text, ScrollView, Platform,Picker,SafeAreaView} from 'react-native'; import DatePicker from 'react-native-datepicker'; import RNPickerSelect, { defaultStyles } from 'react-native-picker-select'; import Constants from 'expo-constants'; export default class Product extends Component { constructor(props) { super(props) this.state = { uid:this.props.navigation.getParam('uid'), lid:this.props.navigation.getParam('lid'), name_p: '', bought_date:'', expiration_date:'', iso_date:'', i:'', typ:'', quantity:'', notes:'', renew:'', picked:'no' } } insertList_Function = () => { this.setState({ picked: "yes" }) fetch('https://ada.uprrp.edu/~laura.gonzalez19/4030/insert_p.php', { method: 'POST', headers: { 'Accept': 'application/json', 'Content-Type': 'application/json', }, body: JSON.stringify({ name_p: this.state.name_p, lid: this.state.lid, bought_date:this.state.bought_date, expiration_date:this.state.expiration_date, type:this.state.typ, quantity:this.state.quantity, renew:this.state.renew, notes:this.state.notes, }) }).then((response) => response.json()) .then((responseJson) => { // Showing response message coming from server after inserting records. Alert.alert("Status",responseJson, [ { text: 'Cancel', style: 'cancel' }, { text: 'OK', onPress:() => this.props.navigation.navigate('Products') } ], { cancelable: false } ); //navigation.navigate('Landing'); }); } setBought=(data)=>{ this.setState({bought_date:data}); this.setExpiration; } setType=(itemValue)=>{ this.setExpiration; } setExpiration=()=>{ if(this.state.typ!=='' && this.state.bought_date!=='' ){ const e_date=new Date(this.state.bought_date); //this.setState({e_date: new Date(this.state.bought_date)}); if(this.state.typ==='fruits'){ e_date.setDate(e_date.getDate() + 5); } else if(this.state.typ==='eggs'){ e_date.setDate(e_date.getDate() + 28); } else if(this.state.typ==='meats'){ e_date.setDate(e_date.getDate() + 14); } else if(this.state.typ==='salads'){ e_date.setDate(e_date.getDate() + 3); } else if(this.state.typ==='poultry'){ e_date.setDate(e_date.getDate() + 2); } else if(this.state.typ==='soups'){ e_date.setDate(e_date.getDate() + 3); } else if(this.state.typ==='scr'){ e_date.setDate(e_date.getDate() + 4); } else if(this.state.typ==='bacon'){ e_date.setDate(e_date.getDate() + 7); } else if(this.state.typ==='sausage'){ e_date.setDate(e_date.getDate() + 2); } else if(this.state.typ==='gmeat'){ e_date.setDate(e_date.getDate() + 2); } else if(this.state.typ==='pizza'){ e_date.setDate(e_date.getDate() + 4); } this.setState({expiration_date: e_date.toISOString().slice(0,10)}); this.setState({ iso_date: e_date.toISOString().slice(0,10)}); } } render() { return ( Products Form this.setState({ name_p: data })} underlineColorAndroid='transparent' style={styles.TextInputStyleClass} /> {this.setState({typ:itemValue},()=>{ this.setExpiration();});}} style={pickerSelectStyles} useNativeAndroidPickerStyle={false} /> this.setBought(data)} onDateChange={data => {this.setState({bought_date:data},()=>{ this.setExpiration();});}} /> Expected expiration date {this.state.iso_date} Add date here if you prefer to add your own expiration date this.setState({expiration_date:data})} /> this.setState({quantity: text})} value = {this.state.quantity} /> this.setState({ notes: data })} underlineColorAndroid='transparent' style={styles.TextInputStyleClass} /> this.setState({renew: itemValue})} style={pickerSelectStyles} useNativeAndroidPickerStyle={false} /> + Start adding your products ); } } const styles = StyleSheet.create({ MainContainer: { marginTop: Constants.statusBarHeight, justifyContent: 'center', alignItems: 'center', flex: 1, margin: 10 }, TextInputStyleClass: { color: 'gray', textAlign: 'center', marginBottom: 7, height: 40, width: '80%', borderWidth: 1, borderColor: '#3414B3' }, datestyling: { textAlign: 'center', color: 'gray', marginBottom: 7, height: 40, width: '80%', borderWidth: 1, borderColor: '#3414B3' }, button: { height:50, width: 50, paddingTop: 2, paddingBottom: 2, backgroundColor: '#3414B3', borderRadius: 100, marginTop: 20, alignItems: 'center' }, text: { color: '#fff', fontSize: 30, textAlign: 'center', padding: 0 }, } ); const pickerSelectStyles = StyleSheet.create({ inputIOS: { textAlign: 'center', marginLeft:35, borderWidth: 1, fontSize: 16, borderColor: '#3414B3', marginBottom: 7, height: 40, width: '80%', color: 'gray' }, inputAndroid: { textAlign: "center", borderWidth: 1, fontSize: 16, borderColor: '#3414B3', marginBottom: 7, height: 40, width: 270, color: 'gray' }, inputWeb: { color: 'gray', alignItems: 'center', fontSize: 16, textAlign: 'center', marginBottom: 7, height: 40, width: '80%', borderWidth: 1, borderColor: '#3414B3', } });