Skip to content

Commit

Permalink
feat(registration-block): hidden input for subscription (#1949)
Browse files Browse the repository at this point in the history
Co-authored-by: Adam Boro <adam@adamboro.com>
  • Loading branch information
miguelpeixe and adekbadek authored Aug 30, 2022
1 parent d293701 commit fc4f4d5
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 11 deletions.
4 changes: 4 additions & 0 deletions assets/blocks/reader-registration/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@
"type": "boolean",
"default": true
},
"hideSubscriptionInput": {
"type": "boolean",
"default": false
},
"newsletterTitle": {
"type": "string",
"default": "Newsletters"
Expand Down
15 changes: 14 additions & 1 deletion assets/blocks/reader-registration/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ export default function ReaderRegistrationEdit( {
privacyLabel,
newsletterSubscription,
displayListDescription,
hideSubscriptionInput,
newsletterTitle,
newsletterLabel,
haveAccountLabel,
Expand Down Expand Up @@ -103,6 +104,10 @@ export default function ReaderRegistrationEdit( {
}
}, [ listConfig ] );

const shouldHideSubscribeInput = () => {
return lists.length === 1 && hideSubscriptionInput;
};

return (
<>
<InspectorControls>
Expand Down Expand Up @@ -142,6 +147,14 @@ export default function ReaderRegistrationEdit( {
setAttributes( { displayListDescription: ! displayListDescription } )
}
/>
<ToggleControl
label={ __( 'Hide newsletter selection and always subscribe', 'newspack' ) }
checked={ hideSubscriptionInput }
disabled={ inFlight || lists.length !== 1 }
onChange={ () =>
setAttributes( { hideSubscriptionInput: ! hideSubscriptionInput } )
}
/>
{ lists.length < 1 && (
<div style={ { marginBottom: '1.5rem' } }>
<Notice isDismissible={ false } status="error">
Expand Down Expand Up @@ -206,7 +219,7 @@ export default function ReaderRegistrationEdit( {
tagName="p"
/>
<div className="newspack-registration__form-content">
{ newsletterSubscription && lists.length ? (
{ ! shouldHideSubscribeInput() && newsletterSubscription && lists.length ? (
<div className="newspack-reader__lists">
{ lists?.length > 1 && (
<RichText
Expand Down
26 changes: 16 additions & 10 deletions assets/blocks/reader-registration/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -159,16 +159,22 @@ function render_block( $attrs, $content ) {
<?php \wp_nonce_field( FORM_ACTION, FORM_ACTION ); ?>
<div class="newspack-registration__form-content">
<?php
if ( isset( $lists ) ) {
Reader_Activation::render_subscription_lists_inputs(
$lists,
array_keys( $lists ),
[
'title' => $attrs['newsletterTitle'],
'single_label' => $attrs['newsletterLabel'],
'show_description' => $attrs['displayListDescription'],
]
);
if ( ! empty( $lists ) ) {
if ( 1 === count( $lists ) && $attrs['hideSubscriptionInput'] ) {
?>
<input type="hidden" name="lists[]" value="<?php echo \esc_attr( key( $lists ) ); ?>">
<?php
} else {
Reader_Activation::render_subscription_lists_inputs(
$lists,
array_keys( $lists ),
[
'title' => $attrs['newsletterTitle'],
'single_label' => $attrs['newsletterLabel'],
'show_description' => $attrs['displayListDescription'],
]
);
}
}
?>
<div class="newspack-registration__main">
Expand Down

0 comments on commit fc4f4d5

Please sign in to comment.