File size: 1,621 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 |
import { translate } from 'i18n-calypso';
/**
* Processes a redux ROUTE_SET action and returns a URL that contains no parameters that
* are related to immediate login.
* @param {string} path - path
* @param {Object} query - query parameters
* @returns {string} - the URL without related params
*/
export const createPathWithoutImmediateLoginInformation = ( path, query ) => {
const relatedParamNames = [
'immediate_login_attempt',
'immediate_login_success',
'login_reason',
'login_email',
'login_locale',
];
const newQuery = Object.keys( query )
.filter( ( k ) => relatedParamNames.indexOf( k ) === -1 )
.map( ( k ) => `${ encodeURIComponent( k ) }=${ encodeURIComponent( query[ k ] ) }` );
return path + ( newQuery.length ? '?' + newQuery.join( '&' ) : '' );
};
/**
* Creates a human-understandable message that communicates that current user was logged in
* @param {string} loginReason - Reason why user were logged in, the message may vary depending on it.
* @param {string} email - Email of currently logged in user
* @returns {string} - Message to show to user
*/
export const createImmediateLoginMessage = ( loginReason, email ) => {
// It's possible to vary the message based on login reason, but currently
// the default message is used in all cases. (Since the user reached this
// page via one click from an email, the expectation is that it's the
// responsibility of the email and the page to make clear to the user why
// they're actually here, not this message.)
return translate( "You're logged in as %(email)s.", { args: { email } } );
};
|