Client: redux setup
This commit is contained in:
9
mpwo_client/src/reducers/index.js
Normal file
9
mpwo_client/src/reducers/index.js
Normal file
@ -0,0 +1,9 @@
|
||||
import { combineReducers } from 'redux'
|
||||
|
||||
import user from './user'
|
||||
|
||||
const reducers = combineReducers({
|
||||
user,
|
||||
})
|
||||
|
||||
export default reducers
|
21
mpwo_client/src/reducers/user.js
Normal file
21
mpwo_client/src/reducers/user.js
Normal 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
|
Reference in New Issue
Block a user