暫無描述

Drna.js 4.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. import React from "react";
  2. import {
  3. View,
  4. Text,
  5. StyleSheet,
  6. TouchableOpacity,
  7. TextInput,
  8. KeyboardAvoidingView
  9. } from "react-native";
  10. import { SelectList } from "react-native-dropdown-select-list";
  11. import {KeyboardAwareScrollView} from 'react-native-keyboard-aware-scroll-view';
  12. import leyesViolaciones from "./data/leyesViolaciones.json"
  13. import Municipalities from "./data/municipalities.json";
  14. const postData = (URL, data) => {
  15. fetch(URL, {
  16. method: "POST",
  17. headers: {
  18. Accept: "application/json",
  19. "Content-Type": "application/json",
  20. },
  21. body: JSON.stringify(data),
  22. })
  23. .then((response) => response.json())
  24. .then((responseJson) => {
  25. console.log(responseJson);
  26. })
  27. .catch((error) => {
  28. console.error(error);
  29. });
  30. };
  31. const Drna = () => {
  32. const URL = "http://172.20.10.2:5001/complaints/add";
  33. const [name, onChangeName] = React.useState(null);
  34. const [email, onChangeEmail] = React.useState(null);
  35. const [place, onChangePlace] = React.useState(null);
  36. const [selected, setSelected] = React.useState("");
  37. const [description, onChangeDescription] = React.useState(null);
  38. const [location, onChangeLocation] = React.useState(null);
  39. const [municipality, setMunicipality] = React.useState(null);
  40. return (
  41. <KeyboardAwareScrollView>
  42. <View>
  43. <Text
  44. style={{
  45. fontSize: 30,
  46. textAlign: "center",
  47. marginTop: "20%",
  48. }}
  49. >
  50. Formulario DRNA
  51. </Text>
  52. <TextInput
  53. style={styles.input}
  54. value={name}
  55. onChangeText={onChangeName}
  56. placeholder="Nombre"
  57. placeholderTextColor={"grey"}
  58. />
  59. <TextInput
  60. style={styles.input}
  61. value={email}
  62. onChangeText={onChangeEmail}
  63. placeholder="Email"
  64. placeholderTextColor={"grey"}
  65. />
  66. {/* <TextInput
  67. style={styles.input}
  68. value={text}
  69. placeholder="Fecha"
  70. placeholderTextColor={"grey"}
  71. /> */}
  72. <SelectList
  73. boxStyles={styles.input}
  74. dropdownStyles={styles.input2}
  75. data={
  76. leyesViolaciones.map((der) => {
  77. return(
  78. der.value
  79. )
  80. })
  81. }
  82. setSelected={setSelected}
  83. placeholder="Leyes en violacion"
  84. />
  85. <SelectList
  86. boxStyles={styles.input}
  87. dropdownStyles={styles.input2}
  88. data={
  89. Municipalities.map((der) => {
  90. return(
  91. der
  92. )
  93. })
  94. }
  95. setSelected={setMunicipality}
  96. placeholder="Municipio donde ocurrio"
  97. />
  98. <TextInput
  99. style={styles.input}
  100. value={location}
  101. onChangeText={onChangeLocation}
  102. placeholder="Coordenadas de lo ocurrido"
  103. placeholderTextColor={"grey"}
  104. />
  105. <TextInput
  106. style={styles.input}
  107. value={place}
  108. onChangeText={onChangePlace}
  109. placeholder="Lugar de los hechos"
  110. placeholderTextColor={"grey"}
  111. />
  112. <TextInput
  113. style={styles.input2}
  114. value={description}
  115. placeholder="Descripcion de los hechos"
  116. onChangeText={onChangeDescription}
  117. placeholderTextColor={"grey"}
  118. />
  119. <TouchableOpacity
  120. style={styles.button}
  121. onPress={() =>
  122. postData(URL, {
  123. name: name,
  124. email: email,
  125. place: place,
  126. complaint_status: "pending",
  127. complaint_type: selected.valueOf(),
  128. complaint_description: description,
  129. })
  130. }
  131. >
  132. <Text style={styles.text}>Someter</Text>
  133. </TouchableOpacity>
  134. </View>
  135. </KeyboardAwareScrollView>
  136. );
  137. };
  138. export default Drna;
  139. const styles = StyleSheet.create({
  140. input: {
  141. height: 40,
  142. margin: 12,
  143. borderWidth: 0.5,
  144. padding: 10,
  145. borderRadius: 10,
  146. },
  147. input2: {
  148. height: 100,
  149. margin: 12,
  150. borderWidth: 0.5,
  151. padding: 15,
  152. borderRadius: 10,
  153. },
  154. button: {
  155. width: 250,
  156. alignSelf: "center",
  157. alignItems: "center",
  158. justifyContent: "center",
  159. paddingVertical: 12,
  160. paddingHorizontal: 32,
  161. borderRadius: 4,
  162. elevation: 3,
  163. backgroundColor: "#009688",
  164. marginTop: "5%",
  165. },
  166. text: {
  167. fontSize: 16,
  168. lineHeight: 21,
  169. fontWeight: "bold",
  170. letterSpacing: 0.25,
  171. color: "white",
  172. },
  173. });