No Description

StateTime.js 5.0KB

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