説明なし

Drna.js 4.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. import React from "react";
  2. import {
  3. View,
  4. Text,
  5. StyleSheet,
  6. TouchableOpacity,
  7. TextInput,
  8. } from "react-native";
  9. import { SelectList } from "react-native-dropdown-select-list";
  10. const postData = (URL, data) => {
  11. fetch(URL, {
  12. method: "POST",
  13. headers: {
  14. Accept: "application/json",
  15. "Content-Type": "application/json",
  16. },
  17. body: JSON.stringify(data),
  18. })
  19. .then((response) => response.json())
  20. .then((responseJson) => {
  21. console.log(responseJson);
  22. })
  23. .catch((error) => {
  24. console.error(error);
  25. });
  26. };
  27. const Drna = () => {
  28. const URL = "http://192.168.50.171:5000/complaints/add";
  29. const [name, onChangeName] = React.useState(null);
  30. const [email, onChangeEmail] = React.useState(null);
  31. const [place, onChangePlace] = React.useState(null);
  32. const [selected, setSelected] = React.useState("");
  33. const [description, onChangeDescription] = React.useState(null);
  34. const leyesViolaciones = [
  35. { key: "1", value: "Descarga de águas contaminadas" },
  36. { key: "2", value: "Olores objetables-fuertes" },
  37. { key: "3", value: "Tala y/o poda de árboles" },
  38. { key: "4", value: "Rellenando un bosque" },
  39. { key: "5", value: "Rellenando una quebrada" },
  40. { key: "6", value: "Realizando perforaciones en el suelo" },
  41. { key: "7", value: "Moviendo con maquinaria tierra de un lugar a otro" },
  42. { key: "8", value: "Peces y/o otros organismos muertos" },
  43. { key: "9", value: "Tapando la vegetación" },
  44. { key: "10", value: "Destrucción de humedal" },
  45. { key: "11", value: "Construcción sospechosa" },
  46. { key: "12", value: "Otros (vertederos clandestinos, entre otros)" },
  47. ];
  48. return (
  49. <View>
  50. <Text
  51. style={{
  52. fontSize: 30,
  53. textAlign: "center",
  54. marginTop: "20%",
  55. }}
  56. >
  57. Formulario DRNA
  58. </Text>
  59. <TextInput
  60. style={styles.input}
  61. value={name}
  62. onChangeText={onChangeName}
  63. placeholder="Nombre"
  64. placeholderTextColor={"grey"}
  65. />
  66. <TextInput
  67. style={styles.input}
  68. value={email}
  69. onChangeText={onChangeEmail}
  70. placeholder="Email"
  71. placeholderTextColor={"grey"}
  72. />
  73. {/* <TextInput
  74. style={styles.input}
  75. value={text}
  76. placeholder="Fecha"
  77. placeholderTextColor={"grey"}
  78. /> */}
  79. <SelectList
  80. boxStyles={styles.input}
  81. dropdownStyles={styles.input2}
  82. data={leyesViolaciones}
  83. setSelected={setSelected}
  84. placeholder="Leyes en violacion"
  85. />
  86. <TextInput
  87. style={styles.input}
  88. value={place}
  89. onChangeText={onChangePlace}
  90. placeholder="Lugar de los hechos"
  91. placeholderTextColor={"grey"}
  92. />
  93. <TextInput
  94. style={styles.input2}
  95. value={description}
  96. placeholder="Descripcion de los hechos"
  97. onChangeText={onChangeDescription}
  98. placeholderTextColor={"grey"}
  99. />
  100. <TouchableOpacity
  101. style={styles.button}
  102. onPress={() =>
  103. postData(URL, {
  104. name: name,
  105. email: email,
  106. place: place,
  107. complaint_type: selected.valueOf(),
  108. complaint_description: description,
  109. })
  110. }
  111. >
  112. <Text style={styles.text}>Someter</Text>
  113. </TouchableOpacity>
  114. </View>
  115. );
  116. };
  117. export default Drna;
  118. const styles = StyleSheet.create({
  119. input: {
  120. height: 40,
  121. margin: 12,
  122. borderWidth: 0.5,
  123. padding: 10,
  124. borderRadius: 10,
  125. },
  126. input2: {
  127. height: 100,
  128. margin: 12,
  129. borderWidth: 0.5,
  130. padding: 15,
  131. borderRadius: 10,
  132. },
  133. button: {
  134. width: 250,
  135. alignSelf: "center",
  136. alignItems: "center",
  137. justifyContent: "center",
  138. paddingVertical: 12,
  139. paddingHorizontal: 32,
  140. borderRadius: 4,
  141. elevation: 3,
  142. backgroundColor: "#009688",
  143. marginTop: "5%",
  144. },
  145. text: {
  146. fontSize: 16,
  147. lineHeight: 21,
  148. fontWeight: "bold",
  149. letterSpacing: 0.25,
  150. color: "white",
  151. },
  152. });