Skip to content

Commit

Permalink
Merge 50f5470 into f319e84
Browse files Browse the repository at this point in the history
  • Loading branch information
devbucket committed Apr 5, 2019
2 parents f319e84 + 50f5470 commit 3ee8ad6
Showing 1 changed file with 28 additions and 18 deletions.
46 changes: 28 additions & 18 deletions libraries/common/selectors/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,32 +8,40 @@ import { getUrl } from './url';
export const getUserState = state => state.user;

/**
* @param {Object} state The current application state.
* @return {Object}
* Gets user.login from the redux store.
* @param {Object} state The application state.
* @return {Object|null}
*/
export const getUserData = createSelector(
export const getLoginData = createSelector(
getUserState,
(user) => {
if (!user.data) {
if (!user || !user.login) {
return null;
}

return user.data;
return user.login;
}
);

/**
* @param {Object} state The current application state.
* @return {Object|null}
* @deprecated
*/
export const getUserLogin = createSelector(
export const getUserLogin = getLoginData;

/**
* @param {Object} state The current application state.
* @return {Object}
*/
export const getUserData = createSelector(
getUserState,
(userState) => {
if (!userState) {
(user) => {
if (!user.data) {
return null;
}

return userState.login;
return user.data;
}
);

Expand All @@ -43,7 +51,7 @@ export const getUserLogin = createSelector(
* @return {boolean}
*/
export const isUserLoggedIn = createSelector(
getUserLogin,
getLoginData,
(login) => {
if (!login) {
return false;
Expand Down Expand Up @@ -98,19 +106,21 @@ export const getUserEmail = createSelector(
}
);

/**
* Gets user.login from the redux store.
* @param {Object} state The application state.
* @return {Object|null}
*/
export const getLoginData = state => state.user.login;

/**
* Selects the disabled state of the login action from the redux store.
* @param {Object} state The application state.
* @return {Object|null}
*/
export const isUserLoginDisabled = state => getLoginData(state).disabled;
export const isUserLoginDisabled = createSelector(
getLoginData,
(login) => {
if (!login) {
return false;
}

return login.disabled;
}
);

/**
* Gets the register url.
Expand Down

0 comments on commit 3ee8ad6

Please sign in to comment.