-
Notifications
You must be signed in to change notification settings - Fork 805
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Send Email Preview feature (#31021)
- Loading branch information
Showing
6 changed files
with
216 additions
and
10 deletions.
There are no files selected for viewing
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: minor | ||
Type: enhancement | ||
|
||
enhancement Add Email Preview Feature |
24 changes: 24 additions & 0 deletions
24
.../plugins/jetpack/extensions/blocks/subscriptions/email-preview-illustration.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
103 changes: 103 additions & 0 deletions
103
projects/plugins/jetpack/extensions/blocks/subscriptions/email-preview.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,103 @@ | ||
import { useBreakpointMatch } from '@automattic/jetpack-components'; | ||
import apiFetch from '@wordpress/api-fetch'; | ||
import { | ||
Button, | ||
// eslint-disable-next-line wpcalypso/no-unsafe-wp-apis | ||
__experimentalHStack as HStack, | ||
// eslint-disable-next-line wpcalypso/no-unsafe-wp-apis | ||
__experimentalVStack as VStack, | ||
Modal, | ||
TextControl, | ||
Icon, | ||
} from '@wordpress/components'; | ||
import { useSelect } from '@wordpress/data'; | ||
import { useState } from '@wordpress/element'; | ||
import { __ } from '@wordpress/i18n'; | ||
import './email-preview.scss'; | ||
import { check } from '@wordpress/icons'; | ||
import illustration from './email-preview-illustration.svg'; | ||
|
||
export default function EmailPreview( { isModalOpen, closeModal } ) { | ||
const [ emailSent, setEmailSent ] = useState( false ); | ||
const [ emailSending, setEmailSending ] = useState( false ); | ||
const [ errorMessage, setErrorMessage ] = useState( false ); | ||
const postId = useSelect( select => select( 'core/editor' ).getCurrentPostId() ); | ||
const [ isSmall ] = useBreakpointMatch( 'sm' ); | ||
|
||
const sendEmailPreview = () => { | ||
setEmailSending( true ); | ||
apiFetch( { | ||
path: '/wpcom/v2/send-email-preview/', | ||
method: 'POST', | ||
data: { | ||
id: postId, | ||
}, | ||
} ) | ||
.then( () => { | ||
setEmailSending( false ); | ||
setEmailSent( true ); | ||
} ) | ||
.catch( e => { | ||
setEmailSending( false ); | ||
if ( e.message ) { | ||
setErrorMessage( e.message ); | ||
} else { | ||
setErrorMessage( | ||
__( 'Whoops, we have encountered an error. Please try again later.', 'jetpack' ) | ||
); | ||
} | ||
} ); | ||
}; | ||
|
||
return ( | ||
<> | ||
{ isModalOpen && ( | ||
<Modal | ||
className="jetpack-email-preview" | ||
onRequestClose={ () => { | ||
closeModal(); | ||
setEmailSent( false ); | ||
} } | ||
> | ||
<HStack alignment="topLeft"> | ||
<VStack className="jetpack-email-preview__main" alignment="topLeft"> | ||
<h1 className="jetpack-email-preview__title"> | ||
{ __( 'Send a test email', 'jetpack' ) } | ||
</h1> | ||
{ errorMessage && ( | ||
<HStack className="jetpack-email-preview__email-sent">{ errorMessage }</HStack> | ||
) } | ||
{ emailSent ? ( | ||
<HStack className="jetpack-email-preview__email-sent"> | ||
<Icon className="jetpack-email-preview__check" icon={ check } size={ 28 } /> | ||
<div className="jetpack-email-preview__sent_text"> | ||
{ __( 'Email sent successfully', 'jetpack' ) } | ||
</div> | ||
</HStack> | ||
) : ( | ||
<HStack> | ||
<TextControl | ||
className="jetpack-email-preview__email" | ||
value={ window?.Jetpack_Editor_Initial_State?.tracksUserData?.email } | ||
disabled | ||
/> | ||
<Button | ||
className="jetpack-email-preview__button" | ||
variant="primary" | ||
onClick={ sendEmailPreview } | ||
isBusy={ emailSending } | ||
> | ||
{ __( 'Send', 'jetpack' ) } | ||
</Button> | ||
</HStack> | ||
) } | ||
</VStack> | ||
{ ! isSmall && ( | ||
<img className="jetpack-email-preview__img" src={ illustration } alt="" /> | ||
) } | ||
</HStack> | ||
</Modal> | ||
) } | ||
</> | ||
); | ||
} |
62 changes: 62 additions & 0 deletions
62
projects/plugins/jetpack/extensions/blocks/subscriptions/email-preview.scss
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,62 @@ | ||
@import "@automattic/color-studio/dist/color-variables"; | ||
|
||
.jetpack-email-preview { | ||
@media ( min-width: 660px ) { | ||
width: 646px; | ||
} | ||
|
||
h1 { | ||
margin-top: 10px; | ||
} | ||
|
||
.components-modal__content { | ||
margin-top: 52px; | ||
margin-left: 20px; | ||
margin-bottom: 10px; | ||
} | ||
} | ||
|
||
.jetpack-email-preview__img { | ||
height: 110px; | ||
padding-right: 30px; | ||
padding-left: 80px; | ||
margin-left: auto; | ||
} | ||
|
||
.jetpack-email-preview__email-sent { | ||
color: $studio-jetpack-green-30; | ||
.jetpack-email-preview__sent_text { | ||
font-size: 20px; | ||
} | ||
} | ||
|
||
.jetpack-email-preview__check { | ||
fill: currentColor; | ||
} | ||
|
||
.jetpack-email-preview__email { | ||
|
||
> div { | ||
margin-bottom: 0; | ||
} | ||
|
||
.components-text-control__input { | ||
height: 44px; | ||
background-color: $studio-gray-5; | ||
color: $studio-gray; | ||
min-width: 266px; | ||
padding-left: 13px; | ||
font-size: 14px; | ||
} | ||
} | ||
|
||
.jetpack-email-preview__main { | ||
min-width: 462px; | ||
} | ||
|
||
.jetpack-email-preview__button { | ||
height: 44px; | ||
width: 80px; | ||
justify-content: center; | ||
align-items: center; | ||
} |
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