Client: login/register
Client: login/register Client: login/register Client: login/register Client: login/register Client: login/register Client: login/register Client: login/register Client: login/register
This commit is contained in:
@ -1,9 +1,76 @@
|
||||
import { combineReducers } from 'redux'
|
||||
|
||||
import user from './user'
|
||||
import initial from './initial'
|
||||
|
||||
const message = (state = initial.message, action) => {
|
||||
switch (action.type) {
|
||||
case 'AUTH_ERROR':
|
||||
case 'PROFILE_ERROR':
|
||||
return action.message
|
||||
case 'LOGOUT':
|
||||
return ''
|
||||
case 'PROFILE_SUCCESS':
|
||||
return ''
|
||||
default:
|
||||
return state
|
||||
}
|
||||
}
|
||||
|
||||
const user = (state = initial.user, action) => {
|
||||
switch (action.type) {
|
||||
case 'AUTH_ERROR':
|
||||
case 'PROFILE_ERROR':
|
||||
case 'LOGOUT':
|
||||
window.localStorage.removeItem('authToken')
|
||||
return initial.user
|
||||
case 'PROFILE_SUCCESS':
|
||||
return {
|
||||
id: action.message.data.id,
|
||||
username: action.message.data.username,
|
||||
email: action.message.data.email,
|
||||
isAdmin: action.message.data.admin,
|
||||
createdAt: action.message.data.created_at,
|
||||
isAuthenticated: true
|
||||
}
|
||||
default:
|
||||
return state
|
||||
}
|
||||
}
|
||||
|
||||
const formData = (state = initial.formData, action) => {
|
||||
switch (action.type) {
|
||||
case 'UPDATE_FORMDATA_EMAIL':
|
||||
return {
|
||||
formData: {
|
||||
...state.formData,
|
||||
email: action.email
|
||||
},
|
||||
}
|
||||
case 'UPDATE_FORMDATA_USERNAME':
|
||||
return {
|
||||
formData: {
|
||||
...state.formData,
|
||||
username: action.username
|
||||
},
|
||||
}
|
||||
case 'UPDATE_FORMDATA_PASSWORD':
|
||||
return {
|
||||
formData: {
|
||||
...state.formData,
|
||||
password: action.password
|
||||
},
|
||||
}
|
||||
case 'PROFILE_SUCCESS':
|
||||
return initial.formData
|
||||
default:
|
||||
return state
|
||||
}
|
||||
}
|
||||
|
||||
const reducers = combineReducers({
|
||||
message,
|
||||
user,
|
||||
formData,
|
||||
})
|
||||
|
||||
export default reducers
|
||||
|
18
mpwo_client/src/reducers/initial.js
Normal file
18
mpwo_client/src/reducers/initial.js
Normal file
@ -0,0 +1,18 @@
|
||||
export default {
|
||||
message: '',
|
||||
user: {
|
||||
id: '',
|
||||
username: '',
|
||||
email: '',
|
||||
createdAt: '',
|
||||
isAdmin: false,
|
||||
isAuthenticated: false,
|
||||
},
|
||||
formData: {
|
||||
formData: {
|
||||
username: '',
|
||||
email: '',
|
||||
password: ''
|
||||
}
|
||||
},
|
||||
}
|
@ -1,21 +0,0 @@
|
||||
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