From f785e37fab43ba8679e2cdb241298115d299fd59 Mon Sep 17 00:00:00 2001 From: Jori Lallo Date: Mon, 2 May 2016 21:58:39 -0700 Subject: [PATCH] Fixed persistent loading of user and team --- src/actions/SlackAuthAction.js | 14 ++++------- src/index.js | 41 ++++++++++++++++++++----------- src/reducers/team.js | 12 ++++----- src/reducers/user.js | 4 +-- src/scenes/SlackAuth/SlackAuth.js | 2 +- 5 files changed, 40 insertions(+), 33 deletions(-) diff --git a/src/actions/SlackAuthAction.js b/src/actions/SlackAuthAction.js index a01b762a2..1f6df76d0 100644 --- a/src/actions/SlackAuthAction.js +++ b/src/actions/SlackAuthAction.js @@ -3,15 +3,12 @@ import { replace } from 'react-router-redux'; import { client } from 'utils/ApiClient'; import auth from 'utils/auth'; -import { updateUser } from './UserActions'; -import { updateTeam } from './TeamActions'; - export const SLACK_AUTH_PENDING = 'SLACK_AUTH_PENDING'; export const SLACK_AUTH_SUCCESS = 'SLACK_AUTH_SUCCESS'; export const SLACK_AUTH_FAILURE = 'SLACK_AUTH_FAILURE'; const slackAuthPending = makeActionCreator(SLACK_AUTH_PENDING); -const slackAuthSuccess = makeActionCreator(SLACK_AUTH_SUCCESS, 'user'); +const slackAuthSuccess = makeActionCreator(SLACK_AUTH_SUCCESS, 'user', 'team'); const slackAuthFailure = makeActionCreator(SLACK_AUTH_FAILURE, 'error'); export function slackAuthAsync(code) { @@ -23,12 +20,11 @@ export function slackAuthAsync(code) { }) .then(data => { auth.setToken(data.data.accessToken); - dispatch(updateUser(data.data.user)); - dispatch(updateTeam(data.data.team)); + dispatch(slackAuthSuccess(data.data.user, data.data.team)); dispatch(replace('/dashboard')); }) - // .catch((err) => { - // dispatch(push('/error')); - // }) + .catch((err) => { + dispatch(push('/error')); + }) }; }; \ No newline at end of file diff --git a/src/index.js b/src/index.js index 851e6dfa4..b050ea539 100644 --- a/src/index.js +++ b/src/index.js @@ -35,7 +35,32 @@ const store = createStore(reducer, applyMiddleware( routerMiddlewareWithHistory, loggerMiddleware, ), autoRehydrate()); -persistStore(store); + +persistStore(store, { + whitelist: [ + 'user', + 'team', + ] +}, () => { + render(( + + + + + + + + + + + + + + + + ), document.getElementById('root')); +}); function requireAuth(nextState, replace) { if (!auth.loggedIn()) { @@ -46,17 +71,3 @@ function requireAuth(nextState, replace) { } } -render(( - - - - - - - - - - - - -), document.getElementById('root')); diff --git a/src/reducers/team.js b/src/reducers/team.js index 8b822db1c..e86e78c32 100644 --- a/src/reducers/team.js +++ b/src/reducers/team.js @@ -1,12 +1,12 @@ -import { UPDATE_TEAM } from 'actions/TeamActions'; +import { SLACK_AUTH_SUCCESS } from 'actions/SlackAuthAction'; const team = (state = null, action) => { switch (action.type) { - case UPDATE_TEAM: { - return { - ...action.team, - }; - } + case SLACK_AUTH_SUCCESS: { + return { + ...action.team, + }; + } default: return state; } diff --git a/src/reducers/user.js b/src/reducers/user.js index 4c502677a..406d656b5 100644 --- a/src/reducers/user.js +++ b/src/reducers/user.js @@ -1,8 +1,8 @@ -import { UPDATE_USER } from 'actions/UserActions'; +import { SLACK_AUTH_SUCCESS } from 'actions/SlackAuthAction'; const user = (state = null, action) => { switch (action.type) { - case UPDATE_USER: { + case SLACK_AUTH_SUCCESS: { return { ...action.user, }; diff --git a/src/scenes/SlackAuth/SlackAuth.js b/src/scenes/SlackAuth/SlackAuth.js index 9a7cb83a0..410ef8479 100644 --- a/src/scenes/SlackAuth/SlackAuth.js +++ b/src/scenes/SlackAuth/SlackAuth.js @@ -20,7 +20,7 @@ class SlackAuth extends React.Component { render() { return ( -
Loading...
+
); } }