No Description

StateTime.js 5.8KB

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