2017-06-08 02:56:52 +02:00
|
|
|
import * as types from "constants/action_types";
|
2017-06-01 18:20:12 +02:00
|
|
|
|
2017-06-08 02:56:52 +02:00
|
|
|
const reducers = {};
|
2017-06-01 18:20:12 +02:00
|
|
|
|
|
|
|
const defaultState = {
|
|
|
|
authenticationIsPending: false,
|
2017-06-08 23:15:34 +02:00
|
|
|
userIsPending: false,
|
2017-06-02 02:51:52 +02:00
|
|
|
emailNewIsPending: false,
|
2017-06-08 02:56:52 +02:00
|
|
|
emailNewErrorMessage: "",
|
|
|
|
emailToVerify: "",
|
|
|
|
user: undefined,
|
|
|
|
};
|
2017-06-01 18:20:12 +02:00
|
|
|
|
|
|
|
reducers[types.AUTHENTICATION_STARTED] = function(state, action) {
|
|
|
|
return Object.assign({}, state, {
|
2017-06-08 02:56:52 +02:00
|
|
|
authenticationIsPending: true,
|
2017-06-08 23:15:34 +02:00
|
|
|
userIsPending: true,
|
|
|
|
user: defaultState.user,
|
2017-06-08 02:56:52 +02:00
|
|
|
});
|
|
|
|
};
|
2017-06-01 18:20:12 +02:00
|
|
|
|
|
|
|
reducers[types.AUTHENTICATION_SUCCESS] = function(state, action) {
|
|
|
|
return Object.assign({}, state, {
|
|
|
|
authenticationIsPending: false,
|
2017-06-08 23:15:34 +02:00
|
|
|
userIsPending: false,
|
2017-06-01 18:20:12 +02:00
|
|
|
user: action.data.user,
|
2017-06-08 02:56:52 +02:00
|
|
|
});
|
|
|
|
};
|
2017-06-01 18:20:12 +02:00
|
|
|
|
|
|
|
reducers[types.AUTHENTICATION_FAILURE] = function(state, action) {
|
|
|
|
return Object.assign({}, state, {
|
|
|
|
authenticationIsPending: false,
|
2017-06-08 23:15:34 +02:00
|
|
|
userIsPending: false,
|
|
|
|
user: null,
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
reducers[types.USER_FETCH_STARTED] = function(state, action) {
|
|
|
|
return Object.assign({}, state, {
|
|
|
|
userIsPending: true,
|
|
|
|
user: defaultState.user,
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
reducers[types.USER_FETCH_SUCCESS] = function(state, action) {
|
|
|
|
return Object.assign({}, state, {
|
|
|
|
userIsPending: false,
|
|
|
|
user: action.data.user,
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
reducers[types.USER_FETCH_FAILURE] = function(state, action) {
|
|
|
|
return Object.assign({}, state, {
|
|
|
|
userIsPending: true,
|
2017-06-01 18:20:12 +02:00
|
|
|
user: null,
|
2017-06-08 02:56:52 +02:00
|
|
|
});
|
|
|
|
};
|
2017-06-01 18:20:12 +02:00
|
|
|
|
2017-06-02 02:51:52 +02:00
|
|
|
reducers[types.USER_EMAIL_NEW_STARTED] = function(state, action) {
|
|
|
|
return Object.assign({}, state, {
|
|
|
|
emailNewIsPending: true,
|
2017-06-08 02:56:52 +02:00
|
|
|
emailNewErrorMessage: "",
|
|
|
|
});
|
|
|
|
};
|
2017-06-02 02:51:52 +02:00
|
|
|
|
|
|
|
reducers[types.USER_EMAIL_NEW_SUCCESS] = function(state, action) {
|
2017-06-08 02:56:52 +02:00
|
|
|
let user = Object.assign({}, state.user);
|
2017-07-20 21:03:01 +02:00
|
|
|
user.primary_email = action.data.email;
|
2017-06-02 02:51:52 +02:00
|
|
|
return Object.assign({}, state, {
|
2017-06-08 02:56:52 +02:00
|
|
|
emailToVerify: action.data.email,
|
2017-06-02 02:51:52 +02:00
|
|
|
emailNewIsPending: false,
|
2017-06-08 02:56:52 +02:00
|
|
|
user: user,
|
|
|
|
});
|
|
|
|
};
|
2017-06-02 02:51:52 +02:00
|
|
|
|
|
|
|
reducers[types.USER_EMAIL_NEW_EXISTS] = function(state, action) {
|
2017-06-08 02:56:52 +02:00
|
|
|
let user = Object.assign({}, state.user);
|
2017-06-02 02:51:52 +02:00
|
|
|
return Object.assign({}, state, {
|
2017-06-08 02:56:52 +02:00
|
|
|
emailToVerify: action.data.email,
|
2017-06-02 02:51:52 +02:00
|
|
|
emailNewIsPending: false,
|
2017-06-08 02:56:52 +02:00
|
|
|
});
|
|
|
|
};
|
2017-06-02 02:51:52 +02:00
|
|
|
|
|
|
|
reducers[types.USER_EMAIL_NEW_FAILURE] = function(state, action) {
|
|
|
|
return Object.assign({}, state, {
|
|
|
|
emailNewIsPending: false,
|
2017-06-08 02:56:52 +02:00
|
|
|
emailNewErrorMessage: action.data.error,
|
|
|
|
});
|
|
|
|
};
|
2017-06-02 02:51:52 +02:00
|
|
|
|
2017-06-03 01:09:52 +02:00
|
|
|
reducers[types.USER_EMAIL_VERIFY_STARTED] = function(state, action) {
|
|
|
|
return Object.assign({}, state, {
|
|
|
|
emailVerifyIsPending: true,
|
2017-06-08 02:56:52 +02:00
|
|
|
emailVerifyErrorMessage: "",
|
|
|
|
});
|
|
|
|
};
|
2017-06-03 01:09:52 +02:00
|
|
|
|
|
|
|
reducers[types.USER_EMAIL_VERIFY_SUCCESS] = function(state, action) {
|
2017-06-08 02:56:52 +02:00
|
|
|
let user = Object.assign({}, state.user);
|
2017-07-20 21:03:01 +02:00
|
|
|
user.primary_email = action.data.email;
|
2017-06-03 01:09:52 +02:00
|
|
|
return Object.assign({}, state, {
|
2017-06-08 02:56:52 +02:00
|
|
|
emailToVerify: "",
|
2017-06-03 01:09:52 +02:00
|
|
|
emailVerifyIsPending: false,
|
2017-06-08 02:56:52 +02:00
|
|
|
user: user,
|
|
|
|
});
|
|
|
|
};
|
2017-06-03 01:09:52 +02:00
|
|
|
|
|
|
|
reducers[types.USER_EMAIL_VERIFY_FAILURE] = function(state, action) {
|
|
|
|
return Object.assign({}, state, {
|
|
|
|
emailVerifyIsPending: false,
|
2017-06-08 02:56:52 +02:00
|
|
|
emailVerifyErrorMessage: action.data.error,
|
|
|
|
});
|
|
|
|
};
|
2017-06-02 02:51:52 +02:00
|
|
|
|
2017-07-19 01:00:13 +02:00
|
|
|
reducers[types.USER_IDENTITY_VERIFY_STARTED] = function(state, action) {
|
|
|
|
return Object.assign({}, state, {
|
|
|
|
identityVerifyIsPending: true,
|
|
|
|
identityVerifyErrorMessage: "",
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
reducers[types.USER_IDENTITY_VERIFY_SUCCESS] = function(state, action) {
|
|
|
|
return Object.assign({}, state, {
|
|
|
|
identityVerifyIsPending: false,
|
|
|
|
identityVerifyErrorMessage: "",
|
|
|
|
user: action.data.user,
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
reducers[types.USER_IDENTITY_VERIFY_FAILURE] = function(state, action) {
|
|
|
|
return Object.assign({}, state, {
|
|
|
|
identityVerifyIsPending: false,
|
|
|
|
identityVerifyErrorMessage: action.data.error,
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2017-07-21 08:23:39 +02:00
|
|
|
reducers[types.FETCH_ACCESS_TOKEN_SUCCESS] = function(state, action) {
|
|
|
|
const { token } = action.data;
|
|
|
|
|
|
|
|
return Object.assign({}, state, {
|
|
|
|
accessToken: token,
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
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;
|
|
|
|
}
|