Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 9 additions & 10 deletions assets/reader-activation/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,14 @@ function domReady( callback ) {
/**
* Converts FormData into an object.
*
* @param {FormData} formData The form data to convert.
* @param {Array} ignoredKeys Keys to ignore.
* @param {FormData} formData The form data to convert.
* @param {Array} includedFields Form fields to include.
*
* @return {Object} The converted form data.
*/
const convertFormDataToObject = ( formData, ignoredKeys = [] ) =>
const convertFormDataToObject = ( formData, includedFields = [] ) =>
Array.from( formData.entries() ).reduce( ( acc, [ key, val ] ) => {
if ( ignoredKeys.includes( key ) ) {
if ( ! includedFields.includes( key ) ) {
return acc;
}
if ( key.indexOf( '[]' ) > -1 ) {
Expand Down Expand Up @@ -249,6 +249,10 @@ const convertFormDataToObject = ( formData, ignoredKeys = [] ) =>
/**
* Third party auth.
*/
const loginsElements = document.querySelectorAll( '.newspack-reader__logins' );
[ ...loginsElements ].forEach( element => {
element.classList.remove( 'newspack-reader__logins--disabled' );
} );
const googleLoginElements = document.querySelectorAll( '.newspack-reader__logins__google' );
googleLoginElements.forEach( googleLoginElement => {
const googleLoginForm = googleLoginElement.closest( 'form' );
Expand All @@ -271,12 +275,7 @@ const convertFormDataToObject = ( formData, ignoredKeys = [] ) =>
}

const metadata = googleLoginForm
? convertFormDataToObject( new FormData( googleLoginForm ), [
'email',
'password',
'_wp_http_referer',
'newspack_reader_registration',
] )
? convertFormDataToObject( new FormData( googleLoginForm ), [ 'lists[]' ] )
: {};
metadata.current_page_url = window.location.href;
fetch( '/wp-json/newspack/v1/login/google' )
Expand Down
7 changes: 7 additions & 0 deletions assets/reader-activation/auth.scss
Original file line number Diff line number Diff line change
Expand Up @@ -300,13 +300,20 @@
}
}
}
&--disabled {
button {
opacity: 0.5;
pointer-events: none;
}
}
button {
display: flex;
justify-content: center;
align-items: center;
width: 100%;
background-color: wp-colors.$gray-100;
color: black;
transition: all 300ms;
span {
padding-left: 10px;
}
Expand Down
5 changes: 3 additions & 2 deletions includes/class-reader-activation.php
Original file line number Diff line number Diff line change
Expand Up @@ -676,12 +676,13 @@ public static function render_third_party_auth() {
if ( ! Google_OAuth::is_oauth_configured() ) {
return;
}
$class = function( ...$parts ) {
$class = function( ...$parts ) {
array_unshift( $parts, 'logins' );
return self::get_element_class_name( $parts );
};
$classnames = implode( ' ', [ $class(), $class() . '--disabled' ] );
?>
<div class="<?php echo \esc_attr( $class() ); ?>">
<div class="<?php echo \esc_attr( $classnames ); ?>">
<div class="<?php echo \esc_attr( $class( 'separator' ) ); ?>">
<div></div>
<div>
Expand Down