No Description

StateTime.js 5.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. import React from "react";
  2. import firebase from "firebase";
  3. import { Component } from "react";
  4. import { TouchableWithoutFeedback, ImageBackground, Text } from "react-native";
  5. import { styles } from "../../config/styles";
  6. import { Button, View} from 'react-native'
  7. import moment from "moment";
  8. export default class Time extends Component{
  9. constructor(props){
  10. super(props);
  11. this.starttime = 0 ,
  12. this.endtime = 0,
  13. this.timesetter = 0,
  14. this.state = {
  15. Day : this.props.route.params.Day,
  16. Month: this.props.route.params.Month,
  17. int2_id : this.props.route.params.int_id,
  18. mapflag: this.props.route.params.mapflag,
  19. i_token: this.props.route.params.I_Token,
  20. u_token: this.props.route.params.U_Token,
  21. username: this.props.route.params.Username,
  22. I_username: this.props.route.params.I_Username,
  23. pin: this.props.route.params.Pin
  24. }
  25. console.log(" Time params: ",this.props.route.params)
  26. this.time_assignment = this.time_assignment.bind(this);
  27. }
  28. time_set(desired_time){
  29. if(!this.startTime){
  30. if(desired_time == 1){
  31. this.startTime = "8:00am"
  32. }
  33. if(desired_time == 2){
  34. this.startTime = "9:00am"
  35. }
  36. if(desired_time == 3){
  37. this.startTime = "10:00am"
  38. }
  39. if(desired_time == 4){
  40. this.startTime = "11:00am"
  41. }
  42. if(desired_time == 5){
  43. this.startTime = "12:00pm"
  44. }
  45. if(desired_time == 6){
  46. this.startTime = "1:00pm"
  47. }
  48. if(desired_time == 7){
  49. this.startTime = "2:00pm"
  50. }
  51. this.timesetter = desired_time
  52. }
  53. else{
  54. if(this.timesetter > desired_time){
  55. this.endtime = this.startTime
  56. if(desired_time == 1){
  57. this.startTime = "8:00am"
  58. }
  59. if(desired_time == 2){
  60. this.startTime = "9:00am"
  61. }
  62. if(desired_time == 3){
  63. this.startTime = "10:00am"
  64. }
  65. if(desired_time == 4){
  66. this.startTime = "11:00am"
  67. }
  68. if(desired_time == 5){
  69. this.startTime = "12:00pm"
  70. }
  71. if(desired_time == 6){
  72. this.startTime = "1:00pm"
  73. }
  74. if(desired_time == 7){
  75. this.startTime = "2:00pm"
  76. }
  77. }
  78. else{
  79. if(desired_time == 1){
  80. this.endtime = "8:00am"
  81. }
  82. if(desired_time == 2){
  83. this.endtime = "9:00am"
  84. }
  85. if(desired_time == 3){
  86. this.endtime = "10:00am"
  87. }
  88. if(desired_time == 4){
  89. this.endtime = "11:00am"
  90. }
  91. if(desired_time == 5){
  92. this.endtime = "12:00pm"
  93. }
  94. if(desired_time == 6){
  95. this.endtime = "1:00pm"
  96. }
  97. if(desired_time == 7){
  98. this.endtime = "2:00pm"
  99. }
  100. }
  101. }
  102. }
  103. time_assignment(selectedTime){
  104. selectedTime = this.startTime +'-'+ this.endtime
  105. if(this.state.mapflag == true){
  106. console.log("UToken is: ")
  107. console.log(this.state.u_token)
  108. const user = firebase.auth().currentUser;
  109. const uid = user.uid
  110. const username = this.state.username;
  111. const I_username = this.state.I_username;
  112. const u_token = this.state.u_token;
  113. const i_token = this.state.i_token;
  114. const month = this.state.Month;
  115. const day = this.state.Day;
  116. const _time_ = selectedTime;
  117. const i_id = this.state.int2_id;
  118. const lat = this.state.pin.latitude;
  119. const lon = this.state.pin.longitude;
  120. firebase.firestore()
  121. .collection('APPOINTMENTS')
  122. .add({
  123. User: username,
  124. Interpreter: I_username,
  125. participantes: [
  126. i_id,
  127. uid,
  128. ],
  129. new: 'true',
  130. Month : month,
  131. Day: day,
  132. Time: _time_,
  133. u_token : u_token,
  134. i_token : i_token,
  135. Pin: [
  136. lat,
  137. lon,
  138. ],
  139. })
  140. }
  141. else{
  142. const user = firebase.auth().currentUser
  143. const uid = user.uid
  144. const username = this.state.username;
  145. const I_username = this.state.I_username;
  146. const u_token = this.state.u_token;
  147. const i_token = this.state.i_token;
  148. const month = this.state.Month;
  149. const day = this.state.Day;
  150. const _time_ = selectedTime;
  151. const i_id = this.state.int2_id;
  152. console.log('Params: ')
  153. console.log(this.props.route.params)
  154. firebase.firestore()
  155. .collection('APPOINTMENTS')
  156. .add({
  157. User: username,
  158. Interpreter: I_username,
  159. participantes: [
  160. i_id,
  161. uid,
  162. ],
  163. new: 'true',
  164. Month : month,
  165. Day: day,
  166. Time: _time_,
  167. u_token : u_token,
  168. i_token : i_token,
  169. })
  170. }
  171. this.props.navigation.navigate('Home');
  172. }
  173. render(){
  174. return(
  175. <TouchableWithoutFeedback style={styles.stdcontainer}>
  176. <ImageBackground style={styles.regcontainer} source={require('../../assets/yellow-white.jpg')}>
  177. <Text style={styles.qsttxt}> Select the Start and End Time for the Appointment </Text>
  178. <Button style={styles.cenregbutton} title="8:00am" onPress={() => this.time_set(1,)}/>
  179. <Button style={styles.cenregbutton} title="9:00am" onPress={() => this.time_set(2,)}/>
  180. <Button style={styles.cenregbutton} title="10:00am" onPress={() => this.time_set(3,)}/>
  181. <Button style={styles.cenregbutton} title="11:00am" onPress={() => this.time_set(4,)}/>
  182. <Button style={styles.cenregbutton} title="12:00pm" onPress={() => this.time_set(5,)}/>
  183. <Button style={styles.cenregbutton} title="1:00pm" onPress={() => this.time_set(6,)}/>
  184. <Button style={styles.cenregbutton} title="2:00pm" onPress={() => this.time_set(7,)}/>
  185. <Button style={styles.regbutton} title="Request Appointment" onPress={() => this.time_assignment()}/>
  186. </ImageBackground>
  187. </TouchableWithoutFeedback>
  188. );
  189. }
  190. }