Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Send a Message / WhatsApp block #15050

Merged
merged 32 commits into from
Jun 27, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
0f475a7
Initial addition of send a message block into Jetpack block scaffolding
apeatling Mar 19, 2020
46cefae
Switch to innerblocks for supporting WhatsApp block within main Send …
apeatling May 21, 2020
4164f71
Make sure that innerblocks are registered and can load front end styles
apeatling May 21, 2020
1548ec7
[not verified] Add WhatsApp button innerblock.
apeatling May 21, 2020
7b98d9b
[not verified] Remove commented out old class component from WhatsApp…
apeatling May 21, 2020
7b18026
Move phone number and message settings to the block toolbar as well a…
apeatling May 22, 2020
a8a9533
Update settings icon to something more appropriate
apeatling May 22, 2020
5187b9f
Update message block icon and support flex alignment inside the block.
apeatling May 25, 2020
7e7b9d0
Fix up number validation, and auto select the WhatsApp button block w…
apeatling May 25, 2020
25096c3
[not verified] Make sure parent block has wrapper on front end.
apeatling May 26, 2020
329401e
[not verified] Make sure the form settings popover has correct paddin…
apeatling May 26, 2020
46ed165
Use constants for color names
apeatling May 26, 2020
805dc97
Hide the child block inserter on WP 5.3
apeatling Jun 12, 2020
3488a44
Allow Send A Message block for free Jetpack plan
aaronrobertshaw Jun 8, 2020
cba0d02
Deconstruct params in function
apeatling Jun 16, 2020
66650d7
Explicitly disable html support
apeatling Jun 16, 2020
6d810b3
Add comment for the phone number validation regex
apeatling Jun 16, 2020
91cf8ee
Remove superfluous save
apeatling Jun 16, 2020
8a0da2f
Switch to useDispatch
apeatling Jun 16, 2020
5b1879c
Add useEffect dependencies
apeatling Jun 17, 2020
364b50a
Fix undefined classname in front end.
apeatling Jun 17, 2020
c320ed7
Remove alignment support.
apeatling Jun 17, 2020
0ec321e
Fix missing translation
apeatling Jun 22, 2020
64f5ca3
Fix missing textdomain
apeatling Jun 22, 2020
407c267
Switch to Jetpack geo API
apeatling Jun 22, 2020
a5cd52b
URL encode inline svg to fix icons in IE11
apeatling Jun 22, 2020
6213265
Fix inline block buttons when more than one whatsapp button exists.
apeatling Jun 23, 2020
8d7c32d
Update extensions/blocks/send-a-message/index.js
apeatling Jun 24, 2020
7ce2c8b
Update extensions/blocks/send-a-message/variations.js
apeatling Jun 24, 2020
bc61c07
Update extensions/blocks/send-a-message/whatsapp-button/index.js
apeatling Jun 24, 2020
10ff879
Remove spaces
apeatling Jun 25, 2020
a24fc30
Support line breaks in button
apeatling Jun 25, 2020
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
1 change: 1 addition & 0 deletions class.jetpack-plan.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class Jetpack_Plan {
'supports' => array(
'opentable',
'calendly',
'send-a-message',
),
),
'personal' => array(
Expand Down
17 changes: 17 additions & 0 deletions extensions/blocks/send-a-message/edit.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/**
* External dependencies
*/
import { InnerBlocks } from '@wordpress/block-editor';

export default function SendAMessageEdit( { className } ) {
// Default template is single WhatsApp block until we offer
// more services
const DEFAULT_TEMPLATE = [ [ 'jetpack/whatsapp-button', {} ] ];
const ALLOWED_BLOCKS = [ 'jetpack/whatsapp-button' ];

return (
<div className={ className }>
<InnerBlocks template={ DEFAULT_TEMPLATE } allowedBlocks={ ALLOWED_BLOCKS } />
</div>
);
}
16 changes: 16 additions & 0 deletions extensions/blocks/send-a-message/editor.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/**
* Internal dependencies
*/
import registerJetpackBlock from '../../shared/register-jetpack-block';
import { name, settings } from '.';
import {
name as whatsAppButtonBlockName,
settings as whatsAppButtonBlockSettings,
} from './whatsapp-button';

registerJetpackBlock( name, settings, [
{
name: whatsAppButtonBlockName,
settings: whatsAppButtonBlockSettings,
},
] );
16 changes: 16 additions & 0 deletions extensions/blocks/send-a-message/editor.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
.wp-block-jetpack-send-a-message {
.block-editor-block-list__layout {
display: inline-flex;

.wp-block {
margin-top: 0px;
margin-bottom: 0px;
margin-right: 10px;
}
}

.block-list-appender, .block-editor-inserter {
/* Until we have more service buttons available */
display: none;
}
}
51 changes: 51 additions & 0 deletions extensions/blocks/send-a-message/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/**
* External dependencies
*/
import { __, _x } from '@wordpress/i18n';
import { InnerBlocks } from '@wordpress/block-editor';
import { Path } from '@wordpress/components';

/**
* Internal dependencies
*/
import edit from './edit';
import variations from './variations';
import renderMaterialIcon from '../../shared/render-material-icon';
import { supportsCollections } from '../../shared/block-category';

/**
* Style dependencies
*/
import './editor.scss';

export const name = 'send-a-message';
export const title = __( 'Send A Message', 'jetpack' );

export const settings = {
title,
description: __( 'Let your visitors send you messages with the tap of a button.', 'jetpack' ),
icon: renderMaterialIcon(
<Path d="M21 6h-2v9H6v2c0 .55.45 1 1 1h11l4 4V7c0-.55-.45-1-1-1zm-4 6V3c0-.55-.45-1-1-1H3c-.55 0-1 .45-1 1v14l4-4h10c.55 0 1-.45 1-1z" />
),
category: supportsCollections() ? 'grow' : 'jetpack',
keywords: [
_x( 'whatsapp', 'keyword', 'jetpack' ),
_x( 'messenger', 'keyword', 'jetpack' ),
_x( 'contact', 'keyword', 'jetpack' ),
_x( 'support', 'keyword', 'jetpack' ),
],
supports: {
html: false,
},
attributes: {},
edit,
save: props => {
return (
<div className={ props.className }>
<InnerBlocks.Content />
</div>
);
},
variations,
example: {},
};
46 changes: 46 additions & 0 deletions extensions/blocks/send-a-message/send-a-message.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php
/**
* Send a Message Block.
*
* @package Jetpack
*/

namespace Automattic\Jetpack\Extensions\Send_A_Message;

require_once dirname( __FILE__ ) . '/whatsapp-button/whatsapp-button.php';

use Jetpack;
use Jetpack_Gutenberg;

const FEATURE_NAME = 'send-a-message';
const BLOCK_NAME = 'jetpack/' . FEATURE_NAME;

/**
* Registers the block for use in Gutenberg
* This is done via an action so that we can disable
* registration if we need to.
*/
function register_block() {
jetpack_register_block(
BLOCK_NAME,
array(
'render_callback' => __NAMESPACE__ . '\render_block',
'plan_check' => true,
)
);
}
add_action( 'init', __NAMESPACE__ . '\register_block' );

/**
* Render callback.
*
* @param array $attributes Array containing the block attributes.
* @param string $content String containing the block content.
*
* @return string
*/
function render_block( $attributes, $content ) {
Jetpack_Gutenberg::load_styles_as_required( FEATURE_NAME );

return $content;
}
241 changes: 241 additions & 0 deletions extensions/blocks/send-a-message/shared/countrycodes.js

Large diffs are not rendered by default.

25 changes: 25 additions & 0 deletions extensions/blocks/send-a-message/variations.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/**
* External dependencies
*/
import { __ } from '@wordpress/i18n';

/**
* Internal dependencies
*/
import whatsAppIcon from './whatsapp-button/icon';

const variations = [
{
isDefault: true,
name: 'whatsapp-button',
title: __( 'WhatsApp Button', 'jetpack' ),
description: __(
'Let your visitors send you messages on WhatsApp with the tap of a button.',
'jetpack'
),
icon: whatsAppIcon,
innerBlocks: [ [ 'jetpack/whatsapp-button', {} ] ],
},
];

export default variations;
31 changes: 31 additions & 0 deletions extensions/blocks/send-a-message/whatsapp-button/attributes.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/**
* External dependencies
*/
import { __ } from '@wordpress/i18n';

export default {
countryCode: {
type: 'string',
},
phoneNumber: {
type: 'string',
},
firstMessage: {
type: 'string',
default: __( 'Hi, I got your WhatsApp information from your website.', 'jetpack' ),
},
buttonText: {
type: 'array',
source: 'children',
selector: 'a.whatsapp-block__button',
default: __( 'Chat on WhatsApp', 'jetpack' ),
},
backgroundColor: {
type: 'string',
default: '#25D366',
},
colorClass: {
type: 'string',
default: 'dark',
},
};
Loading