Skip to content

Commit

Permalink
Add empty RSVP message to RSVP Response V2 block.
Browse files Browse the repository at this point in the history
  • Loading branch information
mauteri committed Dec 24, 2024
1 parent d4216fb commit d1c6b23
Show file tree
Hide file tree
Showing 14 changed files with 142 additions and 33 deletions.
7 changes: 6 additions & 1 deletion build/blocks/rsvp-response-v2/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,12 @@
"icon": "groups",
"example": {},
"description": "Displays a list of members who have confirmed their attendance for an event.",
"attributes": {},
"attributes": {
"emptyRsvpMessage": {
"type": "string",
"default": "No one is attending this event yet."
}
},
"supports": {
"align": [
"wide",
Expand Down
2 changes: 1 addition & 1 deletion build/blocks/rsvp-response-v2/index.asset.php
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<?php return array('dependencies' => array('react-jsx-runtime', 'wp-api-fetch', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-core-data', 'wp-data', 'wp-element', 'wp-i18n'), 'version' => '48f7c56a43a37c6a3277');
<?php return array('dependencies' => array('react-jsx-runtime', 'wp-api-fetch', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-core-data', 'wp-data', 'wp-element', 'wp-i18n'), 'version' => '2201207c7bbc3cfad47e');
2 changes: 1 addition & 1 deletion build/blocks/rsvp-response-v2/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion build/blocks/rsvp-template/view.asset.php
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<?php return array('dependencies' => array('@wordpress/interactivity'), 'version' => 'f3f32604eb20c4bc322a', 'type' => 'module');
<?php return array('dependencies' => array('@wordpress/interactivity'), 'version' => '1691210014ab76aac638', 'type' => 'module');
2 changes: 1 addition & 1 deletion build/blocks/rsvp-template/view.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion build/utility_style-rtl.css
Original file line number Diff line number Diff line change
@@ -1 +1 @@
.gatherpress--is-visible{display:block!important}.gatherpress--close-modal,.gatherpress--open-modal{cursor:pointer}
.gatherpress--is-visible{display:block!important}.gatherpress--is-not-visible{display:none!important}.gatherpress--empty-rsvp-message{display:none}.gatherpress--close-modal,.gatherpress--open-modal{cursor:pointer}
2 changes: 1 addition & 1 deletion build/utility_style.asset.php
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<?php return array('dependencies' => array(), 'version' => '1dffb41cd1d8d25c9a5c');
<?php return array('dependencies' => array(), 'version' => '5b2edc0f3c5de93d7a01');
2 changes: 1 addition & 1 deletion build/utility_style.css
Original file line number Diff line number Diff line change
@@ -1 +1 @@
.gatherpress--is-visible{display:block!important}.gatherpress--close-modal,.gatherpress--open-modal{cursor:pointer}
.gatherpress--is-visible{display:block!important}.gatherpress--is-not-visible{display:none!important}.gatherpress--empty-rsvp-message{display:none}.gatherpress--close-modal,.gatherpress--open-modal{cursor:pointer}

Check warning on line 1 in build/utility_style.css

View workflow job for this annotation

GitHub Actions / wp-org-plugin-guidelines

EnqueuedStylesScope

This style is being loaded in all contexts.
31 changes: 28 additions & 3 deletions includes/core/classes/blocks/class-rsvp-response.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
defined( 'ABSPATH' ) || exit; // @codeCoverageIgnore

use GatherPress\Core\Traits\Singleton;
use GatherPress\Core\Event;
use WP_HTML_Tag_Processor;

/**
Expand All @@ -31,6 +32,14 @@ class Rsvp_Response {
*/
use Singleton;

/**
* Constant representing the Block Name.
*
* @since 1.0.0
* @var string
*/
const BLOCK_NAME = 'gatherpress/rsvp-response-v2';

/**
* Class constructor.
*
Expand Down Expand Up @@ -72,15 +81,31 @@ protected function setup_hooks(): void {
* @return string The modified block content with updated attributes.
*/
public function transform_block_content( string $block_content, array $block ): string {
if ( 'gatherpress/rsvp-response-v2' === $block['blockName'] ) {
$tag = new WP_HTML_Tag_Processor( $block_content );
if ( self::BLOCK_NAME === $block['blockName'] ) {
$event = new Event( get_the_ID() );
$tag = new WP_HTML_Tag_Processor( $block_content );
$empty_rsvp_message = $block['attrs']['emptyRsvpMessage'] ?? __( 'No one is attending this event yet.', 'gatherpress' );

if ( ! $event->rsvp ) {
return $block_content;
}

if ( $tag->next_tag() ) {
$tag->set_attribute(
'data-wp-interactive',
'gatherpress/rsvp'
);
$block_content = $tag->get_updated_html();
$responses = (int) $event->rsvp->responses()['attending']['count'];
$visibility_class = empty( $responses ) ? 'gatherpress--is-visible' : '';
$block_content = $tag->get_updated_html();

// @todo: Replace this workaround with a method to properly update inner blocks
// when https://github.com/WordPress/gutenberg/issues/60397 is resolved.
$block_content = preg_replace(
'/(<\/div>)\s*$/',
sprintf( '<p class="gatherpress--empty-rsvp-message %s">' . wp_kses_post( $empty_rsvp_message ) . '</p>$1', esc_attr( $visibility_class ) ),
$block_content
);
}
}

Expand Down
5 changes: 3 additions & 2 deletions includes/core/classes/class-event-rest-api.php
Original file line number Diff line number Diff line change
Expand Up @@ -586,8 +586,9 @@ public function rsvp_status_html( WP_REST_Request $request ): WP_REST_Response {
$success = true;

$response = array(
'success' => $success,
'content' => $content,
'success' => $success,
'content' => $content,
'responses' => $responses,
);

return new WP_REST_Response( $response );
Expand Down
8 changes: 7 additions & 1 deletion src/blocks/rsvp-response-v2/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,13 @@
"icon": "groups",
"example": {},
"description": "Displays a list of members who have confirmed their attendance for an event.",
"attributes": {},
"attributes": {
"emptyRsvpMessage": {
"type": "string",
"default": "No one is attending this event yet."

}
},
"supports": {
"align": [ "wide", "full" ],
"interactivity": true,
Expand Down
Loading

0 comments on commit d1c6b23

Please sign in to comment.