Skip to content

Commit 92c62a2

Browse files
authored
Merge pull request #1613 from StoDevX/sis-messages
Add error messages to St. Olaf login panel
2 parents 85109bc + 63bbca0 commit 92c62a2

File tree

6 files changed

+112
-259
lines changed

6 files changed

+112
-259
lines changed

source/flux/parts/settings.js

Lines changed: 74 additions & 112 deletions
Original file line numberDiff line numberDiff line change
@@ -9,22 +9,21 @@ import {
99
clearLoginCredentials,
1010
} from '../../lib/login'
1111

12-
import {
13-
setTokenValid,
14-
clearTokenValid,
15-
setAnalyticsOptOut,
16-
getAnalyticsOptOut,
17-
} from '../../lib/storage'
12+
import {setAnalyticsOptOut, getAnalyticsOptOut} from '../../lib/storage'
1813

19-
import {updateBalances, updateCourses} from './sis'
14+
import {updateBalances} from './sis'
2015

2116
export const SET_LOGIN_CREDENTIALS = 'settings/SET_LOGIN_CREDENTIALS'
22-
export const CREDENTIALS_LOGIN = 'settings/CREDENTIALS_LOGIN'
17+
export const CREDENTIALS_LOGIN_START = 'settings/CREDENTIALS_LOGIN_START'
18+
export const CREDENTIALS_LOGIN_SUCCESS = 'settings/CREDENTIALS_LOGIN_SUCCESS'
19+
export const CREDENTIALS_LOGIN_FAILURE = 'settings/CREDENTIALS_LOGIN_FAILURE'
2320
export const CREDENTIALS_LOGOUT = 'settings/CREDENTIALS_LOGOUT'
24-
export const CREDENTIALS_VALIDATE = 'settings/CREDENTIALS_VALIDATE'
21+
export const CREDENTIALS_VALIDATE_START = 'settings/CREDENTIALS_VALIDATE_START'
22+
export const CREDENTIALS_VALIDATE_SUCCESS =
23+
'settings/CREDENTIALS_VALIDATE_SUCCESS'
24+
export const CREDENTIALS_VALIDATE_FAILURE =
25+
'settings/CREDENTIALS_VALIDATE_FAILURE'
2526
export const SET_FEEDBACK = 'settings/SET_FEEDBACK'
26-
export const TOKEN_LOGIN = 'settings/TOKEN_LOGIN'
27-
export const TOKEN_LOGOUT = 'settings/TOKEN_LOGOUT'
2827
export const CHANGE_THEME = 'settings/CHANGE_THEME'
2928

3029
export async function setFeedbackStatus(feedbackEnabled: boolean) {
@@ -43,24 +42,15 @@ export async function setLoginCredentials(username: string, password: string) {
4342

4443
export function logInViaCredentials(username: string, password: string) {
4544
return async (dispatch: any => any) => {
45+
dispatch({type: CREDENTIALS_LOGIN_START})
4646
const result = await performLogin(username, password)
47-
dispatch({type: CREDENTIALS_LOGIN, payload: {username, password, result}})
4847

49-
// if we logged in successfully, go ahead and fetch the meals remaining number
5048
if (result) {
49+
dispatch({type: CREDENTIALS_LOGIN_SUCCESS, payload: {username, password}})
50+
// since we logged in successfully, go ahead and fetch the meals info
5151
dispatch(updateBalances())
52-
}
53-
}
54-
}
55-
56-
export function logInViaToken(tokenStatus: boolean) {
57-
return async (dispatch: any => any) => {
58-
await setTokenValid(tokenStatus)
59-
dispatch({type: TOKEN_LOGIN, payload: tokenStatus})
60-
61-
// if we logged in successfully, go ahead and fetch the data that requires a valid token
62-
if (tokenStatus) {
63-
dispatch(updateCourses())
52+
} else {
53+
dispatch({type: CREDENTIALS_LOGIN_FAILURE})
6454
}
6555
}
6656
}
@@ -69,118 +59,81 @@ export function logOutViaCredentials() {
6959
return {type: CREDENTIALS_LOGOUT, payload: clearLoginCredentials()}
7060
}
7161

72-
export async function validateLoginCredentials(
73-
username?: string,
74-
password?: string,
75-
) {
76-
const result = await performLogin(username, password)
77-
return {type: CREDENTIALS_VALIDATE, payload: {result}}
62+
export function validateLoginCredentials(username?: string, password?: string) {
63+
return async (dispatch: any => any) => {
64+
if (!username || !password) {
65+
return
66+
}
67+
68+
dispatch({type: CREDENTIALS_VALIDATE_START})
69+
70+
const result = await performLogin(username, password)
71+
if (result) {
72+
dispatch({type: CREDENTIALS_VALIDATE_SUCCESS})
73+
} else {
74+
dispatch({type: CREDENTIALS_VALIDATE_FAILURE})
75+
}
76+
}
7877
}
7978

80-
export async function logOutViaToken() {
81-
await clearTokenValid()
82-
return {type: TOKEN_LOGOUT}
79+
export type LoginStateType = 'logged-out' | 'logged-in' | 'checking' | 'invalid'
80+
export type CredentialsState = {
81+
username: string,
82+
password: string,
83+
state: LoginStateType,
8384
}
8485

85-
const initialCredentialsState = {
86+
const initialCredentialsState: CredentialsState = {
8687
username: '',
8788
password: '',
88-
error: null,
89-
valid: false,
89+
state: 'logged-out',
9090
}
91-
function credentialsReducer(state = initialCredentialsState, action) {
92-
const {type, payload, error} = action
91+
92+
function credentialsReducer(
93+
state: CredentialsState = initialCredentialsState,
94+
action,
95+
) {
96+
const {type, payload} = action
9397

9498
switch (type) {
95-
case CREDENTIALS_VALIDATE: {
96-
if (error === true || payload.result === false) {
97-
return {
98-
...state,
99-
valid: false,
100-
error: payload.message,
101-
}
102-
}
99+
case CREDENTIALS_VALIDATE_START:
100+
return {...state, state: 'checking'}
103101

104-
return {
105-
...state,
106-
valid: true,
107-
error: null,
108-
}
109-
}
102+
case CREDENTIALS_VALIDATE_SUCCESS:
103+
return {...state, state: 'logged-in'}
110104

111-
case SET_LOGIN_CREDENTIALS: {
112-
return {
113-
...state,
114-
username: payload.username,
115-
password: payload.password,
116-
}
117-
}
105+
case CREDENTIALS_VALIDATE_FAILURE:
106+
return {...state, state: 'invalid'}
118107

119-
case CREDENTIALS_LOGIN: {
120-
if (error === true || payload.result === false) {
121-
return {
122-
...state,
123-
valid: false,
124-
error: payload.message,
125-
}
126-
}
108+
case CREDENTIALS_LOGIN_START:
109+
return {...state, state: 'checking'}
127110

111+
case CREDENTIALS_LOGIN_SUCCESS: {
128112
return {
129113
...state,
130-
valid: true,
131-
error: null,
114+
state: 'logged-in',
132115
username: payload.username,
133116
password: payload.password,
134117
}
135118
}
136119

120+
case CREDENTIALS_LOGIN_FAILURE:
121+
return {...state, state: 'invalid'}
122+
137123
case CREDENTIALS_LOGOUT: {
138124
return {
139125
...state,
126+
state: 'logged-out',
140127
username: '',
141128
password: '',
142-
valid: false,
143-
error: null,
144129
}
145130
}
146131

147-
default:
148-
return state
149-
}
150-
}
151-
152-
const initialTokenState = {
153-
status: false,
154-
error: null,
155-
valid: false,
156-
}
157-
function tokenReducer(state = initialTokenState, action) {
158-
const {type, payload, error} = action
159-
switch (type) {
160-
case TOKEN_LOGIN: {
161-
if (error === true) {
162-
return {
163-
...state,
164-
valid: false,
165-
error: payload,
166-
status: false,
167-
}
168-
}
169-
170-
return {
171-
...state,
172-
valid: payload === true,
173-
error: null,
174-
status: payload,
175-
}
176-
}
177-
178-
case TOKEN_LOGOUT: {
132+
case SET_LOGIN_CREDENTIALS: {
179133
return {
180134
...state,
181-
valid: false,
182-
error: null,
183-
status: false,
135+
username: payload.username,
136+
password: payload.password,
184137
}
185138
}
186139

@@ -189,20 +142,29 @@ function tokenReducer(state = initialTokenState, action) {
189142
}
190143
}
191144

192-
const initialSettingsState = {
145+
export type SettingsState = {
146+
theme: string,
147+
dietaryPreferences: [],
148+
credentials: CredentialsState,
149+
feedbackDisabled: boolean,
150+
}
151+
152+
const initialSettingsState: SettingsState = {
193153
theme: 'All About Olaf',
194154
dietaryPreferences: [],
195155

196-
credentials: undefined,
197-
token: undefined,
156+
credentials: initialCredentialsState,
198157
feedbackDisabled: false,
199158
}
200-
export function settings(state: Object = initialSettingsState, action: Object) {
159+
160+
export function settings(
161+
state: SettingsState = initialSettingsState,
162+
action: Object,
163+
) {
201164
// start out by running the reducers for the complex chunks of the state
202165
state = {
203166
...state,
204167
credentials: credentialsReducer(state.credentials, action),
205-
token: tokenReducer(state.token, action),
206168
}
207169

208170
const {type, payload} = action

source/navigation.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ import {
2323
} from './views/building-hours'
2424
import TransportationView, {BusMapView} from './views/transportation'
2525
import SettingsView from './views/settings'
26-
import SISLoginView from './views/settings/login'
2726
import CreditsView from './views/settings/credits'
2827
import PrivacyView from './views/settings/privacy'
2928
import LegalView from './views/settings/legal'
@@ -73,7 +72,6 @@ export const AppNavigator = StackNavigator(
7372
NewsView: {screen: NewsView},
7473
PrivacyView: {screen: PrivacyView},
7574
SettingsView: {screen: SettingsView},
76-
SISLoginView: {screen: SISLoginView},
7775
SISView: {screen: SISView},
7876
// SnapshotsView: {screen: SnapshotsView},
7977
StreamingView: {screen: StreamingView},

source/storybook/index.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ import CreditsView from '../views/settings/credits'
5252
import PrivacyView from '../views/settings/privacy'
5353
import LegalView from '../views/settings/legal'
5454
import CredentialsLoginSection from '../views/settings/sections/login-credentials'
55-
import TokenLoginSection from '../views/settings/sections/login-token'
5655
import OddsAndEndsSection from '../views/settings/sections/odds-and-ends'
5756
import SupportSection from '../views/settings/sections/support'
5857
import {FaqView} from '../views/faqs'
@@ -141,7 +140,6 @@ export class SnapshotsView extends React.Component {
141140
view: () => <CredentialsLoginSection />,
142141
delay: 100,
143142
},
144-
'section-token': {view: () => <TokenLoginSection />, delay: 100},
145143
'section-support': {
146144
view: () => <Nav>{props => <SupportSection {...props} />}</Nav>,
147145
delay: 100,

source/views/settings/login.js

Lines changed: 0 additions & 52 deletions
This file was deleted.

0 commit comments

Comments
 (0)