No Description

StateTime.js 5.3KB

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