-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.ios.js
131 lines (114 loc) · 3.17 KB
/
index.ios.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
/**
* Sample React Native App
* https://github.com/facebook/react-native
* @flow
*/
import React, { Component } from 'react';
import {
AppRegistry,
Text,
View,
ActivityIndicator,
} from 'react-native';
import LoginView from './Views/LoginView';
import CustomerView from './Views/CustomerView';
import VendorView from './Views/VendorView';
import CleanerView from './Views/CleanerView';
import AuthService from './Services/AuthService';
import DBService from './Services/DBService';
import baseStyles from './Styles/Styles';
import { AppConstants } from './Constants/Constants';
const styles = Object.assign(baseStyles, {
welcome: {
fontSize: 20,
textAlign: 'center',
margin: 10,
},
instructions: {
textAlign: 'center',
color: '#333333',
marginBottom: 5,
},
});
class iFCApp extends Component {
constructor(props) {
super(props);
this.state = {
isLoggedIn: false,
checkingAuth: true,
userInfo: null,
};
this.onLogin = this.onLogin.bind(this);
this.onLogout = this.onLogout.bind(this);
}
componentDidMount() {
DBService.initialize();
AuthService.getUserInfo((err, userInfo) => {
this.setState({
checkingAuth: false,
isLoggedIn: userInfo != null,
});
if (this.state.isLoggedIn) {
this.setLoginState(userInfo);
}
});
}
onLogin(userInfo) {
this.setLoginState(userInfo);
}
setLoginState(userInfo) {
this.setState({
isLoggedIn: true,
userInfo,
});
}
onLogout() {
this.setState({ isLoggedIn: false });
}
render() {
if (this.state.checkingAuth) {
return (
<View style={styles.container}>
<ActivityIndicator
animating = {true}
size="large"
style={styles.loader}
/>
</View>
);
}
if (this.state.isLoggedIn && this.state.userInfo != null) {
switch (this.state.userInfo.userType) {
case AppConstants.customer:
return (
<CustomerView onLogout={this.onLogout}
userInfo={this.state.userInfo}
/>
);
case AppConstants.vendor:
return (
<VendorView onLogout={this.onLogout}
userInfo={this.state.userInfo}
/>
);
case AppConstants.cleaner:
return (
<CleanerView onLogout={this.onLogout}
userInfo={this.state.userInfo}
/>
);
default :
return (
<View style={styles.container}>
<Text style={styles.welcome}>Logged in!</Text>
</View>
);
}
} else {
return (
<LoginView onLogin={this.onLogin} />
);
}
}
}
AppRegistry.registerComponent('iFCApp', () => iFCApp);