-
Notifications
You must be signed in to change notification settings - Fork 800
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MailChimp Block: refactor Edit component to function (#36746)
- Loading branch information
1 parent
46fd90e
commit 3253fc8
Showing
8 changed files
with
291 additions
and
240 deletions.
There are no files selected for viewing
4 changes: 4 additions & 0 deletions
4
projects/plugins/jetpack/changelog/update-refactor-mailchimp-block
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
Significance: patch | ||
Type: other | ||
|
||
MailChimp block: refactor Edit component to function |
79 changes: 79 additions & 0 deletions
79
projects/plugins/jetpack/extensions/blocks/mailchimp/body.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
import { InnerBlocks, RichText } from '@wordpress/block-editor'; | ||
import { TextControl } from '@wordpress/components'; | ||
import { __ } from '@wordpress/i18n'; | ||
import classnames from 'classnames'; | ||
import { | ||
BLOCK_CLASS, | ||
NOTIFICATION_ERROR, | ||
NOTIFICATION_PROCESSING, | ||
NOTIFICATION_SUCCESS, | ||
DEFAULT_EMAIL_PLACEHOLDER, | ||
DEFAULT_CONSENT_TEXT, | ||
DEFAULT_PROCESSING_LABEL, | ||
DEFAULT_SUCCESS_LABEL, | ||
DEFAULT_ERROR_LABEL, | ||
} from './constants'; | ||
|
||
const innerButtonBlock = { | ||
name: 'jetpack/button', | ||
attributes: { | ||
element: 'button', | ||
text: __( 'Join my Mailchimp audience', 'jetpack' ), | ||
uniqueId: 'mailchimp-widget-id', | ||
}, | ||
}; | ||
|
||
const Body = ( { attributes, setAttributes, className, audition } ) => { | ||
const { | ||
emailPlaceholder = DEFAULT_EMAIL_PLACEHOLDER, | ||
consentText = DEFAULT_CONSENT_TEXT, | ||
processingLabel = DEFAULT_PROCESSING_LABEL, | ||
successLabel = DEFAULT_SUCCESS_LABEL, | ||
errorLabel = DEFAULT_ERROR_LABEL, | ||
} = attributes; | ||
|
||
const notification = { | ||
[ NOTIFICATION_PROCESSING ]: processingLabel, | ||
[ NOTIFICATION_SUCCESS ]: successLabel, | ||
[ NOTIFICATION_ERROR ]: errorLabel, | ||
}[ audition ]; | ||
|
||
return ( | ||
<div | ||
className={ classnames( className, { | ||
[ `${ BLOCK_CLASS }_notication-audition` ]: audition, | ||
} ) } | ||
> | ||
<TextControl | ||
aria-label={ emailPlaceholder } | ||
className={ `${ BLOCK_CLASS }_text-input` } | ||
disabled | ||
onChange={ () => false } | ||
placeholder={ emailPlaceholder } | ||
title={ __( 'You can edit the email placeholder in the sidebar.', 'jetpack' ) } | ||
type="email" | ||
/> | ||
<InnerBlocks | ||
template={ [ [ innerButtonBlock.name, innerButtonBlock.attributes ] ] } | ||
templateLock="all" | ||
/> | ||
<RichText | ||
tagName="p" | ||
placeholder={ __( 'Write consent text', 'jetpack' ) } | ||
value={ consentText } | ||
onChange={ value => setAttributes( { consentText: value } ) } | ||
inlineToolbar | ||
/> | ||
{ audition && ( | ||
<div | ||
className={ `${ BLOCK_CLASS }_notification ${ BLOCK_CLASS }_${ audition }` } | ||
role={ audition === NOTIFICATION_ERROR ? 'alert' : 'status' } | ||
> | ||
{ notification } | ||
</div> | ||
) } | ||
</div> | ||
); | ||
}; | ||
|
||
export default Body; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.