Нет описания

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304
  1. import React, {useState, useEffect, useRef} from 'react'
  2. import { Button, Text, View, StyleSheet, Dimensions, Linking, Alert} 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("Interpreters")
  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. const create_meet = () => {
  83. Alert.alert(
  84. "IMPORTANTE!",
  85. "Al continuar, se mandara a la aplicacion de Google Meet, recuerda crear y compartir el enlace de la reunion con su cliente. Continuar?",
  86. [
  87. {
  88. text: "Cancelar",
  89. // onPress: () => console.log("Cancel Pressed"),
  90. style: "cancel"
  91. },
  92. { text: "OK", onPress: () => Linking.openURL(`https://meet.google.com/new`) }
  93. ]
  94. );
  95. //after pressing the button, redirect to the meet app
  96. }
  97. return (
  98. <ImageBackground style={styles.stdcontainer} source={require('../../assets/yellow-white.jpg')}>
  99. <FlatList style={{
  100. flex: 1,
  101. width: screenWidth,
  102. }}
  103. data={threads}
  104. keyExtractor = {item => item._id}
  105. ItemSeparatorComponent={() => <Divider />}
  106. renderItem = {({item}) => (
  107. <TouchableOpacity
  108. onPress={() => navigation.navigate('Room', {thread: item})}
  109. >
  110. <List.Item
  111. title={item.name}
  112. titleNumberOfLines={1}
  113. titleStyle={styles.listTitle}
  114. descriptionStyle={styles.listDescription}
  115. descriptionNumberOfLines={1}
  116. />
  117. </TouchableOpacity>
  118. )}
  119. />
  120. <FlatList style={{
  121. flex: 1,
  122. width: screenWidth,
  123. }}
  124. data={appointments}
  125. keyExtractor = {item => item._id}
  126. ItemSeparatorComponent={() => <Divider />}
  127. renderItem = {({item}) => (
  128. <TouchableOpacity
  129. onPress={async () => {
  130. console.log("cita")
  131. }}
  132. >
  133. <List.Item
  134. title='Usuario:'
  135. description={item.User}
  136. titleNumberOfLines={1}
  137. titleStyle={styles.listTitle}
  138. descriptionStyle={styles.listDescription}
  139. descriptionNumberOfLines={1}
  140. />
  141. <List.Item
  142. title='Mes:'
  143. description={item.Month}
  144. titleNumberOfLines={1}
  145. titleStyle={styles.listTitle}
  146. descriptionStyle={styles.listDescription}
  147. descriptionNumberOfLines={1}
  148. />
  149. <List.Item
  150. title='Día'
  151. description={item.Day}
  152. titleNumberOfLines={1}
  153. titleStyle={styles.listTitle}
  154. descriptionStyle={styles.listDescription}
  155. descriptionNumberOfLines={1}
  156. />
  157. <List.Item
  158. title='Hora:'
  159. description={item.Time}
  160. titleNumberOfLines={1}
  161. titleStyle={styles.listTitle}
  162. descriptionStyle={styles.listDescription}
  163. descriptionNumberOfLines={1}
  164. />
  165. </TouchableOpacity>
  166. )}
  167. />
  168. <Button
  169. title ='Crear cita virtual'
  170. onPress= {() => {create_meet()}}
  171. />
  172. <Button
  173. title ='Ver mapa'
  174. onPress= {() => navigation.navigate('Map', {View_Only: true, Pin: Pin})}
  175. />
  176. <Button
  177. title ='Logout'
  178. onPress= {() => firebase.auth().signOut()}
  179. />
  180. </ImageBackground>
  181. );
  182. }
  183. else{
  184. return (
  185. <ImageBackground style={styles.stdcontainer} source={require('../../assets/yellow-white.jpg')}>
  186. <FlatList style={{
  187. flex: 1,
  188. width: screenWidth,
  189. }}
  190. data={threads}
  191. keyExtractor = {item => item._id}
  192. ItemSeparatorComponent={() => <Divider />}
  193. renderItem = {({item}) => (
  194. <TouchableOpacity
  195. onPress={() => navigation.navigate('Room', {thread: item})}
  196. >
  197. <List.Item
  198. title={item.name}
  199. titleNumberOfLines={1}
  200. titleStyle={styles.listTitle}
  201. descriptionStyle={styles.listDescription}
  202. descriptionNumberOfLines={1}
  203. />
  204. </TouchableOpacity>
  205. )}
  206. />
  207. <FlatList style={{
  208. flex: 1,
  209. width: screenWidth,
  210. }}
  211. data={appointments}
  212. keyExtractor = {item => item._id}
  213. ItemSeparatorComponent={() => <Divider />}
  214. renderItem = {({item}) => (
  215. <TouchableOpacity
  216. onPress={async () => {
  217. console.log("cita")
  218. }}
  219. >
  220. <List.Item
  221. title='Interprete:'
  222. description={item.Interpreter}
  223. titleNumberOfLines={1}
  224. titleStyle={styles.listTitle}
  225. descriptionStyle={styles.listDescription}
  226. descriptionNumberOfLines={1}
  227. />
  228. <List.Item
  229. title='Mes:'
  230. description={item.Month}
  231. titleNumberOfLines={1}
  232. titleStyle={styles.listTitle}
  233. descriptionStyle={styles.listDescription}
  234. descriptionNumberOfLines={1}
  235. />
  236. <List.Item
  237. title='Día:'
  238. description={item.Day}
  239. titleNumberOfLines={1}
  240. titleStyle={styles.listTitle}
  241. descriptionStyle={styles.listDescription}
  242. descriptionNumberOfLines={1}
  243. />
  244. <List.Item
  245. title='Hora:'
  246. description={item.Time}
  247. titleNumberOfLines={1}
  248. titleStyle={styles.listTitle}
  249. descriptionStyle={styles.listDescription}
  250. descriptionNumberOfLines={1}
  251. />
  252. </TouchableOpacity>
  253. )}
  254. />
  255. <Button
  256. title ='Ver mapa'
  257. onPress= {() => navigation.navigate('Map', {View_Only: true, Pin: Pin})}
  258. />
  259. <Button
  260. title ='Logout'
  261. onPress= {() => firebase.auth().signOut()}
  262. />
  263. </ImageBackground>
  264. );
  265. }
  266. }
  267. const mapStateToProps = (store) => ({
  268. currentUser: store.userState.currentUser
  269. })
  270. const mapDispatchProps = (dispatch) => bindActionCreators({fetchUser}, dispatch);
  271. export default connect(mapStateToProps, mapDispatchProps)(Cita);