|
5 | 5 | */ |
6 | 6 |
|
7 | 7 | import React from 'react' |
8 | | -import {StyleSheet} from 'react-native' |
| 8 | +import { |
| 9 | + StyleSheet, |
| 10 | + Text, |
| 11 | + View, |
| 12 | + Navigator, |
| 13 | +} from 'react-native' |
9 | 14 |
|
10 | 15 | import TabbedView from '../components/tabbed-view' |
| 16 | +import Button from 'react-native-button' |
11 | 17 | import tabs from './tabs' |
12 | | - |
| 18 | +import LoadingView from '../components/loading' |
| 19 | +import {isLoggedIn} from '../../lib/login' |
| 20 | +import * as c from '../components/colors' |
13 | 21 | const styles = StyleSheet.create({ |
14 | 22 | container: { |
15 | 23 | flex: 1, |
16 | 24 | }, |
| 25 | + error: { |
| 26 | + marginTop: 50, |
| 27 | + marginLeft: 20, |
| 28 | + marginRight: 20, |
| 29 | + }, |
| 30 | + errorButton: { |
| 31 | + backgroundColor: c.denim, |
| 32 | + width: 200, |
| 33 | + color: c.white, |
| 34 | + alignSelf: 'center', |
| 35 | + height: 30, |
| 36 | + paddingTop: 3, |
| 37 | + marginBottom: 10, |
| 38 | + marginTop: 10, |
| 39 | + borderRadius: 6, |
| 40 | + overflow: 'hidden', |
| 41 | + }, |
17 | 42 | }) |
18 | 43 |
|
19 | | -export default function SISView() { |
20 | | - return <TabbedView style={styles.container} tabs={tabs} /> |
21 | | -} |
| 44 | +export default class SISView extends React.Component { |
| 45 | + static propTypes = { |
| 46 | + navigator: React.PropTypes.instanceOf(Navigator).isRequired, |
| 47 | + route: React.PropTypes.object.isRequired, |
| 48 | + } |
| 49 | + |
| 50 | + state = { |
| 51 | + loggedIn: false, |
| 52 | + loaded: false, |
| 53 | + }; |
| 54 | + |
| 55 | + componentWillMount() { |
| 56 | + this.load() |
| 57 | + } |
| 58 | + |
| 59 | + load = async () => { |
| 60 | + let loggedIn = await isLoggedIn() |
| 61 | + this.setState({loggedIn, loaded: true}) |
| 62 | + } |
| 63 | + |
| 64 | + render() { |
| 65 | + let {navigator, route} = this.props |
| 66 | + |
| 67 | + if (!this.state.loaded) { |
| 68 | + return <LoadingView /> |
| 69 | + } |
| 70 | + |
| 71 | + // Check if the user has a valid username and password |
| 72 | + if (this.state.loggedIn) { |
| 73 | + return <TabbedView style={styles.container} tabs={tabs} /> |
| 74 | + } |
22 | 75 |
|
23 | | -SISView.propTypes = { |
| 76 | + return ( |
| 77 | + <View style={styles.error}> |
| 78 | + <Text>Sorry, we couldn't find your login credentials. Did you set them up in the settings?</Text> |
| 79 | + <Button |
| 80 | + onPress={() => |
| 81 | + navigator.push({ |
| 82 | + id: 'SettingsView', |
| 83 | + index: route.index + 1, |
| 84 | + title: 'Settings', |
| 85 | + }) |
| 86 | + } |
| 87 | + style={styles.errorButton} |
| 88 | + >Open Settings</Button> |
| 89 | + </View> |
| 90 | + ) |
| 91 | + } |
24 | 92 | } |
0 commit comments