Skip to content

Commit 1881549

Browse files
elijahverdoornhawkrives
authored andcommitted
Add SIS credential error handling (#174)
* Add error handling for a user not having credentials entered for SIS view Add a button that redirects them to settings, with an error message. * add function to check if login is good * rebuild SISView around login checks * also actually set `loaded` so the loading screen goes away
1 parent 17f5351 commit 1881549

File tree

3 files changed

+78
-7
lines changed

3 files changed

+78
-7
lines changed

lib/financials.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,4 +94,3 @@ export default async function getWeeklyMealsRemaining() {
9494
let loginResult = await api.post('/apps/olecard/checkbalance/authenticate.cfm', {body: form})
9595
return loginResult
9696
}
97-

lib/login.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ export function clearLoginCredentials(): Promise<any> {
2727
.catch(() => {})
2828
}
2929

30+
export async function isLoggedIn(): Promise<boolean> {
31+
let result = await AsyncStorage.getItem('credentials:valid')
32+
return JSON.parse(result)
33+
}
3034

3135
export function checkLogin(username: string, password: string): Promise<boolean> {
3236
return sisLogin(username, password).then(res => res.result)

views/sis/index.js

Lines changed: 74 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,88 @@
55
*/
66

77
import React from 'react'
8-
import {StyleSheet} from 'react-native'
8+
import {
9+
StyleSheet,
10+
Text,
11+
View,
12+
Navigator,
13+
} from 'react-native'
914

1015
import TabbedView from '../components/tabbed-view'
16+
import Button from 'react-native-button'
1117
import tabs from './tabs'
12-
18+
import LoadingView from '../components/loading'
19+
import {isLoggedIn} from '../../lib/login'
20+
import * as c from '../components/colors'
1321
const styles = StyleSheet.create({
1422
container: {
1523
flex: 1,
1624
},
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+
},
1742
})
1843

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+
}
2275

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+
}
2492
}

0 commit comments

Comments
 (0)