2017-06-08 02:56:52 +02:00
|
|
|
import { createSelector } from "reselect";
|
2017-06-01 18:20:12 +02:00
|
|
|
|
2017-06-08 02:56:52 +02:00
|
|
|
export const _selectState = state => state.user || {};
|
2017-06-01 18:20:12 +02:00
|
|
|
|
|
|
|
export const selectAuthenticationIsPending = createSelector(
|
|
|
|
_selectState,
|
2017-06-08 02:56:52 +02:00
|
|
|
state => state.authenticationIsPending
|
|
|
|
);
|
2017-06-01 18:20:12 +02:00
|
|
|
|
2017-06-08 23:15:34 +02:00
|
|
|
export const selectUserIsPending = createSelector(
|
|
|
|
_selectState,
|
|
|
|
state => state.userIsPending
|
|
|
|
);
|
|
|
|
|
2017-06-02 02:51:52 +02:00
|
|
|
export const selectUser = createSelector(
|
2017-06-01 18:20:12 +02:00
|
|
|
_selectState,
|
2017-06-08 02:56:52 +02:00
|
|
|
state => state.user || {}
|
|
|
|
);
|
2017-06-02 02:51:52 +02:00
|
|
|
|
2017-06-08 02:56:52 +02:00
|
|
|
export const selectEmailToVerify = createSelector(
|
2017-06-03 01:09:52 +02:00
|
|
|
_selectState,
|
2017-06-08 02:56:52 +02:00
|
|
|
state => state.emailToVerify
|
|
|
|
);
|
|
|
|
|
|
|
|
export const selectUserHasEmail = createSelector(
|
|
|
|
selectUser,
|
|
|
|
selectEmailToVerify,
|
2017-06-08 23:15:34 +02:00
|
|
|
(user, email) => (user && user.has_email) || email
|
2017-06-08 02:56:52 +02:00
|
|
|
);
|
|
|
|
|
|
|
|
export const selectUserIsRewardEligible = createSelector(
|
|
|
|
selectUser,
|
2017-06-08 23:15:34 +02:00
|
|
|
user => user && user.is_reward_eligible
|
2017-06-08 02:56:52 +02:00
|
|
|
);
|
|
|
|
|
|
|
|
export const selectUserIsRewardApproved = createSelector(
|
|
|
|
selectUser,
|
2017-06-08 23:15:34 +02:00
|
|
|
user => user && user.is_reward_approved
|
2017-06-08 02:56:52 +02:00
|
|
|
);
|
2017-06-03 01:09:52 +02:00
|
|
|
|
2017-06-02 02:51:52 +02:00
|
|
|
export const selectEmailNewIsPending = createSelector(
|
|
|
|
_selectState,
|
2017-06-08 02:56:52 +02:00
|
|
|
state => state.emailNewIsPending
|
|
|
|
);
|
2017-06-02 02:51:52 +02:00
|
|
|
|
|
|
|
export const selectEmailNewErrorMessage = createSelector(
|
|
|
|
_selectState,
|
2017-06-08 02:56:52 +02:00
|
|
|
state => state.emailNewErrorMessage
|
|
|
|
);
|
2017-06-02 02:51:52 +02:00
|
|
|
|
|
|
|
export const selectEmailNewDeclined = createSelector(
|
|
|
|
_selectState,
|
2017-06-08 02:56:52 +02:00
|
|
|
state => state.emailNewDeclined
|
|
|
|
);
|
2017-06-03 01:09:52 +02:00
|
|
|
|
|
|
|
export const selectEmailVerifyIsPending = createSelector(
|
|
|
|
_selectState,
|
2017-06-08 02:56:52 +02:00
|
|
|
state => state.emailVerifyIsPending
|
|
|
|
);
|
2017-06-03 01:09:52 +02:00
|
|
|
|
|
|
|
export const selectEmailVerifyErrorMessage = createSelector(
|
|
|
|
_selectState,
|
2017-06-08 02:56:52 +02:00
|
|
|
state => state.emailVerifyErrorMessage
|
|
|
|
);
|
|
|
|
|
|
|
|
export const selectUserIsVerificationCandidate = createSelector(
|
|
|
|
selectUserIsRewardEligible,
|
|
|
|
selectUserIsRewardApproved,
|
|
|
|
selectEmailToVerify,
|
|
|
|
selectUser,
|
|
|
|
(isEligible, isApproved, emailToVerify, user) =>
|
2017-06-08 23:15:34 +02:00
|
|
|
(isEligible && !isApproved) || (emailToVerify && user && !user.has_email)
|
2017-06-08 02:56:52 +02:00
|
|
|
);
|
|
|
|
|
|
|
|
export const selectUserIsAuthRequested = createSelector(
|
|
|
|
selectEmailNewDeclined,
|
|
|
|
selectAuthenticationIsPending,
|
|
|
|
selectUserIsVerificationCandidate,
|
|
|
|
selectUserHasEmail,
|
|
|
|
(isEmailDeclined, isPending, isVerificationCandidate, hasEmail) =>
|
|
|
|
!isEmailDeclined && (isPending || !hasEmail || isVerificationCandidate)
|
|
|
|
);
|