File size: 3,159 Bytes
1e92f2d |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
import { get, includes } from 'lodash';
import { REASONS_FOR_MANUAL_RENEWAL } from './constants';
import 'calypso/state/immediate-login/init';
/**
* Retrieves information about whether an immediate login attempt was made for
* the current instance of Calypso.
* @param {Object} state - Global state tree
* @returns {boolean} - Whether the client request indicates that an immediate
* login attempt was made
*/
export const wasImmediateLoginAttempted = ( state ) => {
return get( state, 'immediateLogin.attempt', false );
};
/**
* Retrieves information about whether an immediate login attempt was
* successful (according to query parameters provided in the client request)
* during the current instance of Calypso.
*
* This and the other selectors in this file are based on information provided
* in the URL (which can be tampered with) so it should not be used to trust
* that the immediate login actually occurred. However, it is appropriate to
* use it to make user interface improvements for the immediate login scenario.
* @param {Object} state - Global state tree
* @returns {boolean} - Whether the client request indicates that an immediate
* login attempt was successful
*/
export const wasImmediateLoginSuccessfulAccordingToClient = ( state ) => {
return get( state, 'immediateLogin.success', false );
};
/**
* Retrieves the reason information provided in the query parameters of
* immediate login request.
* @param {Object} state - Global state tree
* @returns {?string} - Reason for immediate login, or null
*/
export const getImmediateLoginReason = ( state ) => {
return get( state, 'immediateLogin.reason', null );
};
/**
* Retrieves the email address used for the immediate login attempt, according
* to query parameters provided in the client request.
* @param {Object} state - Global state tree
* @returns {?string} - Email address used for the immediate login attempt, or
* null
*/
export const getImmediateLoginEmail = ( state ) => {
return get( state, 'immediateLogin.email', null );
};
/**
* Retrieves the language code for the immediate login attempt, according
* to query parameters provided in the client request.
* @param {Object} state - Global state tree
* @returns {?string} - Two-letter code for the preferred language of the user
* attempting to log in, or null
*/
export const getImmediateLoginLocale = ( state ) => {
return get( state, 'immediateLogin.locale', null );
};
/**
* Retrieves information about whether an immediate login attempt was made from
* a link in an email that requested the user to manually renew a subscription
* (according to query parameters provided in the client request) for the
* current instance of Calypso.
* @param {Object} state - Global state tree
* @returns {boolean} - Whether the client request indicates that an immediate
* login attempt was made from a manual renewal email
*/
export const wasManualRenewalImmediateLoginAttempted = ( state ) => {
return includes( REASONS_FOR_MANUAL_RENEWAL, getImmediateLoginReason( state ) );
};
|