lbry-desktop/ui/js/reducers/user.js

95 lines
2.2 KiB
JavaScript
Raw Normal View History

2017-06-01 18:20:12 +02:00
import * as types from 'constants/action_types'
import {
getLocal
} from 'utils'
2017-06-01 18:20:12 +02:00
const reducers = {}
const defaultState = {
authenticationIsPending: false,
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,
})
}
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, {
2017-06-03 01:09:52 +02:00
emailNewExistingEmail: action.data.email,
emailNewIsPending: false,
})
}
reducers[types.USER_EMAIL_NEW_FAILURE] = function(state, action) {
return Object.assign({}, state, {
emailNewIsPending: false,
emailNewErrorMessage: action.data.error
})
}
2017-06-03 01:09:52 +02:00
reducers[types.USER_EMAIL_VERIFY_STARTED] = function(state, action) {
return Object.assign({}, state, {
emailVerifyIsPending: true,
emailVerifyErrorMessage: ''
})
}
reducers[types.USER_EMAIL_VERIFY_SUCCESS] = function(state, action) {
return Object.assign({}, state, {
emailVerifyIsPending: false,
})
}
reducers[types.USER_EMAIL_VERIFY_FAILURE] = function(state, action) {
return Object.assign({}, state, {
emailVerifyIsPending: false,
emailVerifyErrorMessage: 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;
}