No Description

Cita.js 7.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278
  1. import React, {useState, useEffect, useRef} from 'react'
  2. import { Button, Text, View, StyleSheet, Dimensions} from 'react-native'
  3. import {FlatList, ListViewBase } from 'react-native'
  4. import {TouchableOpacity} from 'react-native-gesture-handler'
  5. import {List, Divider} from 'react-native-paper'
  6. import Loading from './Loading'
  7. import firebase from 'firebase';
  8. import { styles } from "../../config/styles";
  9. import { TextInput, TouchableWithoutFeedback, Keyboard, ImageBackground} from "react-native";
  10. import { connect } from 'react-redux'
  11. import { bindActionCreators } from 'redux'
  12. import { fetchUser } from '../../redux/actions/index'
  13. export function Cita({route, navigation}) {
  14. const [threads, setThreads] = useState([]);
  15. const [loading, setLoading] = useState(true);
  16. console.log("ID", route.params);
  17. const [appointments, setAppointments] = useState([]);
  18. const[interpreter, setState] = useState();
  19. useEffect(() => {
  20. const fire = firebase.firestore()
  21. .collection('THREADS')
  22. .where("cita", "==", route.params.tag._id)
  23. .onSnapshot(querySnapshot => {
  24. const threads = querySnapshot.docs.map(documentSnapshot => {
  25. return{
  26. _id:documentSnapshot.id,
  27. name:'',
  28. ...documentSnapshot.data()
  29. };
  30. });
  31. setThreads(threads);
  32. console.log(threads);
  33. if(loading){
  34. setLoading(false);
  35. }
  36. });
  37. const cita = firebase.firestore().collection('APPOINTMENTS').where("citaID", "==", route.params.tag._id).onSnapshot(snapShot => {
  38. const appointments = snapShot.docs.map(docSnap => {
  39. return{
  40. _id:docSnap.id,
  41. new:'',
  42. Day:'',
  43. Month:'',
  44. Time:'',
  45. i_token:'',
  46. u_token:'',
  47. Pin: {},
  48. ...docSnap.data()
  49. };
  50. });
  51. setAppointments(appointments);
  52. console.log("appointment", appointments);
  53. });
  54. return () => {
  55. fire();
  56. cita();
  57. }
  58. }, []);
  59. function check_user_type_INT(){
  60. firebase.firestore()
  61. .collection("Interprete")
  62. .doc(firebase.auth().currentUser.uid)
  63. .get()
  64. .then((snapshot) => {
  65. if(snapshot.exists){
  66. setState(true);
  67. }
  68. else{
  69. setState(false);
  70. }
  71. })
  72. if(loading){
  73. setLoading(false);
  74. }
  75. }
  76. check_user_type_INT();
  77. const dimensions = Dimensions.get('window');
  78. const screenWidth = dimensions.width;
  79. console.log("Inter: ", interpreter)
  80. const Pin = route.params.Pin;
  81. if(interpreter == true){
  82. return (
  83. <ImageBackground style={styles.stdcontainer} source={require('../../assets/yellow-white.jpg')}>
  84. <FlatList style={{
  85. flex: 1,
  86. width: screenWidth,
  87. }}
  88. data={threads}
  89. keyExtractor = {item => item._id}
  90. ItemSeparatorComponent={() => <Divider />}
  91. renderItem = {({item}) => (
  92. <TouchableOpacity
  93. onPress={() => navigation.navigate('Room', {thread: item})}
  94. >
  95. <List.Item
  96. title={item.name}
  97. titleNumberOfLines={1}
  98. titleStyle={styles.listTitle}
  99. descriptionStyle={styles.listDescription}
  100. descriptionNumberOfLines={1}
  101. />
  102. </TouchableOpacity>
  103. )}
  104. />
  105. <FlatList style={{
  106. flex: 1,
  107. width: screenWidth,
  108. }}
  109. data={appointments}
  110. keyExtractor = {item => item._id}
  111. ItemSeparatorComponent={() => <Divider />}
  112. renderItem = {({item}) => (
  113. <TouchableOpacity
  114. onPress={async () => {
  115. console.log("cita")
  116. }}
  117. >
  118. <List.Item
  119. title='Usuario:'
  120. description={item.User}
  121. titleNumberOfLines={1}
  122. titleStyle={styles.listTitle}
  123. descriptionStyle={styles.listDescription}
  124. descriptionNumberOfLines={1}
  125. />
  126. <List.Item
  127. title='Mes:'
  128. description={item.Month}
  129. titleNumberOfLines={1}
  130. titleStyle={styles.listTitle}
  131. descriptionStyle={styles.listDescription}
  132. descriptionNumberOfLines={1}
  133. />
  134. <List.Item
  135. title='Día'
  136. description={item.Day}
  137. titleNumberOfLines={1}
  138. titleStyle={styles.listTitle}
  139. descriptionStyle={styles.listDescription}
  140. descriptionNumberOfLines={1}
  141. />
  142. <List.Item
  143. title='Hora:'
  144. description={item.Time}
  145. titleNumberOfLines={1}
  146. titleStyle={styles.listTitle}
  147. descriptionStyle={styles.listDescription}
  148. descriptionNumberOfLines={1}
  149. />
  150. </TouchableOpacity>
  151. )}
  152. />
  153. <Button
  154. title ='Ver mapa'
  155. onPress= {() => navigation.navigate('Map', {View_Only: true, Pin: Pin})}
  156. />
  157. <Button
  158. title ='Logout'
  159. onPress= {() => firebase.auth().signOut()}
  160. />
  161. </ImageBackground>
  162. );
  163. }
  164. else{
  165. return (
  166. <ImageBackground style={styles.stdcontainer} source={require('../../assets/yellow-white.jpg')}>
  167. <FlatList style={{
  168. flex: 1,
  169. width: screenWidth,
  170. }}
  171. data={threads}
  172. keyExtractor = {item => item._id}
  173. ItemSeparatorComponent={() => <Divider />}
  174. renderItem = {({item}) => (
  175. <TouchableOpacity
  176. onPress={() => navigation.navigate('Room', {thread: item})}
  177. >
  178. <List.Item
  179. title={item.name}
  180. titleNumberOfLines={1}
  181. titleStyle={styles.listTitle}
  182. descriptionStyle={styles.listDescription}
  183. descriptionNumberOfLines={1}
  184. />
  185. </TouchableOpacity>
  186. )}
  187. />
  188. <FlatList style={{
  189. flex: 1,
  190. width: screenWidth,
  191. }}
  192. data={appointments}
  193. keyExtractor = {item => item._id}
  194. ItemSeparatorComponent={() => <Divider />}
  195. renderItem = {({item}) => (
  196. <TouchableOpacity
  197. onPress={async () => {
  198. console.log("cita")
  199. }}
  200. >
  201. <List.Item
  202. title='Interprete:'
  203. description={item.Interpreter}
  204. titleNumberOfLines={1}
  205. titleStyle={styles.listTitle}
  206. descriptionStyle={styles.listDescription}
  207. descriptionNumberOfLines={1}
  208. />
  209. <List.Item
  210. title='Mes:'
  211. description={item.Month}
  212. titleNumberOfLines={1}
  213. titleStyle={styles.listTitle}
  214. descriptionStyle={styles.listDescription}
  215. descriptionNumberOfLines={1}
  216. />
  217. <List.Item
  218. title='Día'
  219. description={item.Day}
  220. titleNumberOfLines={1}
  221. titleStyle={styles.listTitle}
  222. descriptionStyle={styles.listDescription}
  223. descriptionNumberOfLines={1}
  224. />
  225. <List.Item
  226. title='Hora:'
  227. description={item.Time}
  228. titleNumberOfLines={1}
  229. titleStyle={styles.listTitle}
  230. descriptionStyle={styles.listDescription}
  231. descriptionNumberOfLines={1}
  232. />
  233. </TouchableOpacity>
  234. )}
  235. />
  236. <Button
  237. title ='Ver mapa'
  238. onPress= {() => navigation.navigate('Map', {View_Only: true, Pin: Pin})}
  239. />
  240. <Button
  241. title ='Logout'
  242. onPress= {() => firebase.auth().signOut()}
  243. />
  244. </ImageBackground>
  245. );
  246. }
  247. }
  248. const mapStateToProps = (store) => ({
  249. currentUser: store.userState.currentUser
  250. })
  251. const mapDispatchProps = (dispatch) => bindActionCreators({fetchUser}, dispatch);
  252. export default connect(mapStateToProps, mapDispatchProps)(Cita);