2017-06-01 18:20:12 +02:00
|
|
|
import * as types from 'constants/action_types'
|
2017-06-02 02:51:52 +02:00
|
|
|
import {
|
|
|
|
getLocal
|
|
|
|
} from 'utils'
|
2017-06-01 18:20:12 +02:00
|
|
|
|
|
|
|
const reducers = {}
|
|
|
|
|
|
|
|
const defaultState = {
|
|
|
|
authenticationIsPending: false,
|
2017-06-02 02:51:52 +02:00
|
|
|
emailNewIsPending: false,
|
|
|
|
emailNewErrorMessage: '',
|
|
|
|
emailNewDeclined: getLocal('user_email_declined', false),
|
2017-06-01 18:20:12 +02:00
|
|
|
user: undefined
|
|
|
|
}
|
|
|
|
|
|
|
|
reducers[types.AUTHENTICATION_STARTED] = function(state, action) {
|
|
|
|
return Object.assign({}, state, {
|
|
|
|
authenticationIsPending: true
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
reducers[types.AUTHENTICATION_SUCCESS] = function(state, action) {
|
|
|
|
return Object.assign({}, state, {
|
|
|
|
authenticationIsPending: false,
|
|
|
|
user: action.data.user,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
reducers[types.AUTHENTICATION_FAILURE] = function(state, action) {
|
|
|
|
return Object.assign({}, state, {
|
|
|
|
authenticationIsPending: false,
|
|
|
|
user: null,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2017-06-02 02:51:52 +02:00
|
|
|
reducers[types.USER_EMAIL_DECLINE] = function(state, action) {
|
|
|
|
return Object.assign({}, state, {
|
|
|
|
emailNewDeclined: true
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
reducers[types.USER_EMAIL_NEW_STARTED] = function(state, action) {
|
|
|
|
return Object.assign({}, state, {
|
|
|
|
emailNewIsPending: true,
|
|
|
|
emailNewErrorMessage: ''
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
reducers[types.USER_EMAIL_NEW_SUCCESS] = function(state, action) {
|
|
|
|
return Object.assign({}, state, {
|
|
|
|
emailNewIsPending: false,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
reducers[types.USER_EMAIL_NEW_EXISTS] = function(state, action) {
|
|
|
|
return Object.assign({}, state, {
|
|
|
|
emailNewIsPending: false,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
reducers[types.USER_EMAIL_NEW_FAILURE] = function(state, action) {
|
|
|
|
return Object.assign({}, state, {
|
|
|
|
emailNewIsPending: false,
|
|
|
|
emailNewErrorMessage: action.data.error
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2017-06-01 18:20:12 +02:00
|
|
|
export default function reducer(state = defaultState, action) {
|
|
|
|
const handler = reducers[action.type];
|
|
|
|
if (handler) return handler(state, action);
|
|
|
|
return state;
|
|
|
|
}
|