import React, { Component } from "react"; import { TextInput, TouchableWithoutFeedback, Keyboard, ImageBackground, Image, View, Text, Button } from "react-native"; import firebase from "firebase"; import { Calendar } from "react-native-calendars"; import { ScrollView } from "react-native-gesture-handler"; import SectionedMultiSelect from 'react-native-sectioned-multi-select'; import Icon from 'react-native-vector-icons/MaterialIcons'; import { connect } from 'react-redux'; import { bindActionCreators } from 'redux'; import { Picker } from "@react-native-picker/picker"; import { fetchUser } from "../../redux/actions"; import { styles } from "../../config/styles"; import { availability } from "../../config/availability"; export class AvailabilityScreen extends Component { constructor(props) { super(props); this.state = { //x : this.route.params.availabilityData.selectedItems, //y : this.route.params.availabilityData.markedDates, english: false, spanish: false, virtual: false, face_to_face: false, personal: false, group: false, city: 'San Juan', //cities: [], selectedItems: [], markedDates: {} }; this.onSelectedItemsChange = this.onSelectedItemsChange.bind(this); this.onDaySelect = this.onDaySelect.bind(this); this.onSave = this.onSave.bind(this); this.handleUpdate = this.handleUpdate.bind(this); }; componentDidMount(){ /*if (x != undefined){ this.setState({selectedItems : x}); }; if (y != undefined){ this.setState({markedDates : y}); }*/ this.props.fetchUser(); this.forceUpdate(() => {this.handleUpdate()}) }; handleUpdate(){ const { currentUser } = this.props; if (currentUser != undefined){ if (currentUser.hasOwnProperty('selectedItems') && currentUser.hasOwnProperty('markedDates') && currentUser.hasOwnProperty('city')) this.setState( {selectedItems: currentUser.selectedItems}); this.setState( {markedDates: currentUser.markedDates}); this.setState({city: currentUser.city}) } }; onSave(){ const { selectedItems } = this.state; selectedItems.forEach((value) => { if(value === 'English'){ this.setState({english : true}, () => firebase.firestore().collection('Interpreters').doc(firebase.auth().currentUser.uid).set({english : true}, {merge : true})); } else if(value === 'Spanish'){ this.setState({spanish : true}, () => firebase.firestore().collection('Interpreters').doc(firebase.auth().currentUser.uid).set({spanish : true}, {merge : true})); } else if(value === 'Virtual'){ this.setState({virtual : true}, () => firebase.firestore().collection('Interpreters').doc(firebase.auth().currentUser.uid).set({virtual : true}, {merge : true})); } else if(value === 'Face-to-Face'){ this.setState({face_to_face : true}, () => firebase.firestore().collection('Interpreters').doc(firebase.auth().currentUser.uid).set({face_to_face : true}, {merge : true})); } else if(value === 'Personal Session'){ this.setState({personal : true}, () => firebase.firestore().collection('Interpreters').doc(firebase.auth().currentUser.uid).set({personal : true}, {merge : true})); } else if(value === 'Group Session'){ this.setState({group : true}, () => firebase.firestore().collection('Interpreters').doc(firebase.auth().currentUser.uid).set({group : true}, {merge : true})); } else if(!isNaN(value.charAt(0))){ for (let key in this.state.markedDates) { if(this.state.markedDates[key].hasOwnProperty('timeSlot')){ this.state.markedDates[key].timeSlot.push(value); } else{ this.state.markedDates[key].timeSlot = []; this.state.markedDates[key].timeSlot.push(value); } } } /*else{ this.state.cities.push(value); }*/ }) firebase.firestore().collection('Interpreters') .doc(firebase.auth().currentUser.uid) .set(this.state, {merge : true}) .then(() => {this.props.navigation.goBack()}); }; onSelectedItemsChange = (selectedItems) => { this.setState({selectedItems}); }; onDaySelect = (day) => { const selectedDay = day.dateString; let selected = true; if (this.state.markedDates[selectedDay]) { selected = !this.state.markedDates[selectedDay].selected; } const updatedMarkedDates = {...this.state.markedDates, ...{ [selectedDay]: { selected } } } this.setState({ markedDates : updatedMarkedDates }); }; render() { return ( this.setState({city : itemValue})}>