import React from "react"; import firebase from "firebase"; import { Component } from "react"; import { TouchableWithoutFeedback, ImageBackground, Text } from "react-native"; import { styles } from "../../config/styles"; import { Button, View} from 'react-native' import moment from "moment"; export default class Time extends Component{ constructor(props){ super(props); this.starttime = 0 , this.endtime = 0, this.timesetter = 0, this.state = { Appointment : this.props.route.params.Appointment, int2_id : this.props.route.params.int_id, mapflag: this.props.route.params.mapflag, i_token: this.props.route.params.I_Token, u_token: this.props.route.params.U_Token, pin: this.props.route.params.Pin } console.log(" Time params: ",this.props.route.params) this.time_assignment = this.time_assignment.bind(this); } time_set(desired_time){ if(!this.startTime){ if(desired_time == 1){ this.startTime = "8:00am" } if(desired_time == 2){ this.startTime = "9:00am" } if(desired_time == 3){ this.startTime = "10:00am" } if(desired_time == 4){ this.startTime = "11:00am" } if(desired_time == 5){ this.startTime = "12:00pm" } if(desired_time == 6){ this.startTime = "1:00pm" } if(desired_time == 7){ this.startTime = "2:00pm" } this.timesetter = desired_time } else{ if(this.timesetter > desired_time){ this.endtime = this.startTime if(desired_time == 1){ this.startTime = "8:00am" } if(desired_time == 2){ this.startTime = "9:00am" } if(desired_time == 3){ this.startTime = "10:00am" } if(desired_time == 4){ this.startTime = "11:00am" } if(desired_time == 5){ this.startTime = "12:00pm" } if(desired_time == 6){ this.startTime = "1:00pm" } if(desired_time == 7){ this.startTime = "2:00pm" } } else{ if(desired_time == 1){ this.endtime = "8:00am" } if(desired_time == 2){ this.endtime = "9:00am" } if(desired_time == 3){ this.endtime = "10:00am" } if(desired_time == 4){ this.endtime = "11:00am" } if(desired_time == 5){ this.endtime = "12:00pm" } if(desired_time == 6){ this.endtime = "1:00pm" } if(desired_time == 7){ this.endtime = "2:00pm" } } } } time_assignment(selectedTime){ selectedTime = this.startTime +'-'+ this.endtime if(this.state.mapflag == true){ console.log("UToken is: ") console.log(this.state.u_token) const user = firebase.auth().currentUser; const uid = user.uid const u_token = this.state.u_token; const i_token = this.state.i_token; const date = this.state.Appointment const month = date.getMonth() + 1; console.log("Month: ", month) const day = date.getDate(); const _time_ = selectedTime; const i_id = this.state.int2_id; const lat = this.state.pin.latitude; const lon = this.state.pin.longitude; firebase.firestore() .collection('APPOINTMENTS') .add({ participantes: [ i_id, uid, ], new: true, Month : month, Day: day, Time: _time_, u_token : u_token, i_token : i_token, Pin: [ lat, lon, ], }) } else{ const user = firebase.auth().currentUser const uid = user.uid const u_token = this.state.u_token; const i_token = this.state.i_token; const date = this.state.Appointment const month = date.getMonth(); const day = date.getDate(); console.log("Date: ", day) const _time_ = selectedTime; const i_id = this.state.int2_id; console.log('Params: ') console.log(this.props.route.params) firebase.firestore() .collection('APPOINTMENTS') .add({ participantes: [ i_id, uid, ], new: true, Month : month, Day: day, Time: _time_, u_token : u_token, i_token : i_token, }) } this.props.navigation.navigate('Home'); } render(){ return(