Client: redux setup

This commit is contained in:
SamR1
2017-12-17 14:02:41 +01:00
parent 2a77b6d607
commit 115e999e48
8 changed files with 317 additions and 56 deletions

View File

@ -0,0 +1,9 @@
import { combineReducers } from 'redux'
import user from './user'
const reducers = combineReducers({
user,
})
export default reducers

View File

@ -0,0 +1,21 @@
const user = (state = null, action) => {
switch (action.type) {
case 'AUTH_ERROR':
case 'PROFILE_ERROR':
case 'LOGOUT':
window.localStorage.removeItem('authToken')
return null
case 'PROFILE_SUCCESS':
return {
id: action.message.data.id,
username: action.message.data.username,
email: action.message.data.email,
isAdmin: action.message.data.is_admin,
createdAt: action.message.data.created_at,
}
default:
return state
}
}
export default user