설명 없음

Product.js 6.2KB

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