|
@@ -0,0 +1,134 @@
|
|
1
|
+import React, { Component } from "react";
|
|
2
|
+import { TextInput, TouchableWithoutFeedback, Keyboard, ImageBackground, Image, View, Text, Button } from "react-native";
|
|
3
|
+import firebase from "firebase";
|
|
4
|
+import { Calendar } from "react-native-calendars";
|
|
5
|
+import { ScrollView } from "react-native-gesture-handler";
|
|
6
|
+import SectionedMultiSelect from 'react-native-sectioned-multi-select';
|
|
7
|
+import Icon from 'react-native-vector-icons/MaterialIcons';
|
|
8
|
+import { connect } from 'react-redux';
|
|
9
|
+import { bindActionCreators } from 'redux';
|
|
10
|
+
|
|
11
|
+import { fetchUser } from "../../redux/actions";
|
|
12
|
+import { styles } from "../../config/styles";
|
|
13
|
+import { availability } from "../../config/availability";
|
|
14
|
+
|
|
15
|
+export class AvailabilityScreen extends Component {
|
|
16
|
+ constructor(props) {
|
|
17
|
+ super(props);
|
|
18
|
+ this.state = {
|
|
19
|
+ english: false,
|
|
20
|
+ spanish: false,
|
|
21
|
+ virtual: false,
|
|
22
|
+ face_to_face: false,
|
|
23
|
+ personal: false,
|
|
24
|
+ group: false,
|
|
25
|
+ cities: [],
|
|
26
|
+ selectedItems: [],
|
|
27
|
+ markedDates: {}
|
|
28
|
+ };
|
|
29
|
+ this.onSelectedItemsChange = this.onSelectedItemsChange.bind(this);
|
|
30
|
+ this.onDaySelect = this.onDaySelect.bind(this);
|
|
31
|
+ this.onSave = this.onSave.bind(this);
|
|
32
|
+ this.handleUpdate = this.handleUpdate.bind(this);
|
|
33
|
+ };
|
|
34
|
+
|
|
35
|
+ componentDidMount(){
|
|
36
|
+ this.props.fetchUser();
|
|
37
|
+ this.forceUpdate(() => {this.handleUpdate()})
|
|
38
|
+ };
|
|
39
|
+
|
|
40
|
+ handleUpdate(){
|
|
41
|
+ const { currentUser } = this.props;
|
|
42
|
+ if (currentUser != undefined){
|
|
43
|
+ if (currentUser.hasOwnProperty('selectedItems') && currentUser.hasOwnProperty('markedDates'))
|
|
44
|
+ this.setState( {selectedItems: currentUser.selectedItems});
|
|
45
|
+ this.setState( {markedDates: currentUser.markedDates});
|
|
46
|
+ }
|
|
47
|
+ };
|
|
48
|
+
|
|
49
|
+ onSave(){
|
|
50
|
+ const { selectedItems } = this.state;
|
|
51
|
+
|
|
52
|
+ selectedItems.forEach((value) => {
|
|
53
|
+ if(value === 'English'){
|
|
54
|
+ this.setState({english : true}, () => firebase.firestore().collection('Interpreters').doc(firebase.auth().currentUser.uid).set({english : true}, {merge : true}));
|
|
55
|
+ }
|
|
56
|
+ else if(value === 'Spanish'){
|
|
57
|
+ this.setState({spanish : true}, () => firebase.firestore().collection('Interpreters').doc(firebase.auth().currentUser.uid).set({spanish : true}, {merge : true}));
|
|
58
|
+ }
|
|
59
|
+ else if(value === 'Virtual'){
|
|
60
|
+ this.setState({virtual : true}, () => firebase.firestore().collection('Interpreters').doc(firebase.auth().currentUser.uid).set({virtual : true}, {merge : true}));
|
|
61
|
+ }
|
|
62
|
+ else if(value === 'Face-to-Face'){
|
|
63
|
+ this.setState({face_to_face : true}, () => firebase.firestore().collection('Interpreters').doc(firebase.auth().currentUser.uid).set({face_to_face : true}, {merge : true}));
|
|
64
|
+ }
|
|
65
|
+ else if(value === 'Personal Session'){
|
|
66
|
+ this.setState({personal : true}, () => firebase.firestore().collection('Interpreters').doc(firebase.auth().currentUser.uid).set({personal : true}, {merge : true}));
|
|
67
|
+ }
|
|
68
|
+ else if(value === 'Group Session'){
|
|
69
|
+ this.setState({group : true}, () => firebase.firestore().collection('Interpreters').doc(firebase.auth().currentUser.uid).set({group : true}, {merge : true}));
|
|
70
|
+ }
|
|
71
|
+ else if(!isNaN(value.charAt(0))){
|
|
72
|
+ for (let key in this.state.markedDates) {
|
|
73
|
+ if(this.state.markedDates[key].hasOwnProperty('timeSlot')){
|
|
74
|
+ this.state.markedDates[key].timeSlot.push(value);
|
|
75
|
+ }
|
|
76
|
+ else{
|
|
77
|
+ this.state.markedDates[key].timeSlot = [];
|
|
78
|
+ this.state.markedDates[key].timeSlot.push(value);
|
|
79
|
+ }
|
|
80
|
+ }
|
|
81
|
+ }
|
|
82
|
+ else{
|
|
83
|
+ this.state.cities.push(value);
|
|
84
|
+ }
|
|
85
|
+ })
|
|
86
|
+ firebase.firestore().collection('Interpreters')
|
|
87
|
+ .doc(firebase.auth().currentUser.uid)
|
|
88
|
+ .set(this.state, {merge : true})
|
|
89
|
+ .then(() => {this.props.navigation.goBack()});
|
|
90
|
+ };
|
|
91
|
+
|
|
92
|
+ onSelectedItemsChange = (selectedItems) => {
|
|
93
|
+ this.setState({selectedItems});
|
|
94
|
+ };
|
|
95
|
+
|
|
96
|
+ onDaySelect = (day) => {
|
|
97
|
+ const selectedDay = day.dateString;
|
|
98
|
+ let selected = true;
|
|
99
|
+
|
|
100
|
+ if (this.state.markedDates[selectedDay]) {
|
|
101
|
+ selected = !this.state.markedDates[selectedDay].selected;
|
|
102
|
+ }
|
|
103
|
+ const updatedMarkedDates = {...this.state.markedDates, ...{ [selectedDay]: { selected } } }
|
|
104
|
+ this.setState({ markedDates : updatedMarkedDates });
|
|
105
|
+ };
|
|
106
|
+
|
|
107
|
+ render() {
|
|
108
|
+ return (
|
|
109
|
+ <ScrollView contentContainerstyle={styles.stdcontainer}>
|
|
110
|
+ <Calendar
|
|
111
|
+ onDayPress={this.onDaySelect}
|
|
112
|
+ style={styles.calendar}
|
|
113
|
+ markedDates={this.state.markedDates}
|
|
114
|
+ theme={{selectedDayBackgroundColor: 'green'}}
|
|
115
|
+ />
|
|
116
|
+ <SectionedMultiSelect
|
|
117
|
+ items={availability}
|
|
118
|
+ IconRenderer={Icon}
|
|
119
|
+ readOnlyHeadings={true}
|
|
120
|
+ uniqueKey='name'
|
|
121
|
+ subKey='children'
|
|
122
|
+ selectText='Choose your availability...'
|
|
123
|
+ onSelectedItemsChange={this.onSelectedItemsChange}
|
|
124
|
+ selectedItems={this.state.selectedItems}
|
|
125
|
+ />
|
|
126
|
+ <Button title='Save' onPress={() => {this.onSave()}}/>
|
|
127
|
+ </ScrollView>
|
|
128
|
+ );
|
|
129
|
+ }
|
|
130
|
+}
|
|
131
|
+
|
|
132
|
+const mapStateProps = (store) => ({currentUser : store.userState.currentUser})
|
|
133
|
+const mapDispatchProps = (dispatch) => bindActionCreators({fetchUser}, dispatch)
|
|
134
|
+export default connect(mapStateProps, mapDispatchProps)(AvailabilityScreen)
|