Skip to content

Commit

Permalink
Added RSVP V2 Past template.
Browse files Browse the repository at this point in the history
  • Loading branch information
mauteri committed Dec 24, 2024
1 parent d1c6b23 commit a03a851
Show file tree
Hide file tree
Showing 10 changed files with 69 additions and 19 deletions.
2 changes: 1 addition & 1 deletion build/blocks/rsvp-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-block-editor', 'wp-blocks', 'wp-components', 'wp-data', 'wp-element', 'wp-i18n'), 'version' => 'd3c10d7fd3f8c7c4d5e4');
<?php return array('dependencies' => array('react-jsx-runtime', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-data', 'wp-element', 'wp-i18n'), 'version' => '3f67a48656b64332157d');
4 changes: 2 additions & 2 deletions build/blocks/rsvp-v2/index.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion build/utility_style-rtl.css

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.asset.php
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<?php return array('dependencies' => array(), 'version' => '5b2edc0f3c5de93d7a01');
<?php return array('dependencies' => array(), 'version' => 'eaf74a388a7076b33c99');
2 changes: 1 addition & 1 deletion build/utility_style.css

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

32 changes: 19 additions & 13 deletions includes/core/classes/blocks/class-rsvp.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
defined( 'ABSPATH' ) || exit; // @codeCoverageIgnore

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

Expand Down Expand Up @@ -76,6 +77,7 @@ public function transform_block_content( string $block_content, array $block ):
$block_instance = Block::get_instance();

if ( self::BLOCK_NAME === $block['blockName'] ) {
$event = new Event( get_the_ID() );
$inner_blocks = isset( $block['innerBlocks'] ) ? $block['innerBlocks'] : array();
$tag = new WP_HTML_Tag_Processor( $block_content );
$attributes = isset( $block['attrs'] ) ? $block['attrs'] : array();
Expand All @@ -102,21 +104,25 @@ public function transform_block_content( string $block_content, array $block ):
// Serialize the current inner blocks for the saved status.
$serialized_inner_blocks[ $saved_status ] = serialize_blocks( $inner_blocks );

// Render inner blocks for all statuses.
$inner_blocks_markup = '';
foreach ( $serialized_inner_blocks as $status => $serialized_inner_block ) {
$inner_blocks_markup .= sprintf(
'<div style="display:none;" data-rsvp-status="%s">%s</div>',
esc_attr( $status ),
do_blocks( $serialized_inner_block )
);
if ( $event->has_event_past() ) {
$inner_blocks_markup = do_blocks( $serialized_inner_blocks['past'] ?? '' );
} else {
// Render inner blocks for all statuses.
$inner_blocks_markup = '';
foreach ( $serialized_inner_blocks as $status => $serialized_inner_block ) {
$inner_blocks_markup .= sprintf(
'<div style="display:none;" data-rsvp-status="%s">%s</div>',
esc_attr( $status ),
do_blocks( $serialized_inner_block )
);
}

// Set dynamic attributes for interactivity.
$tag->set_attribute( 'data-wp-interactive', 'gatherpress' );
$tag->set_attribute( 'data-wp-context', wp_json_encode( array( 'postId' => get_the_ID() ) ) );
$tag->set_attribute( 'data-wp-watch', 'callbacks.renderRsvpBlock' );
}

// Set dynamic attributes for interactivity.
$tag->set_attribute( 'data-wp-interactive', 'gatherpress' );
$tag->set_attribute( 'data-wp-context', wp_json_encode( array( 'postId' => get_the_ID() ) ) );
$tag->set_attribute( 'data-wp-watch', 'callbacks.renderRsvpBlock' );

// Get the updated block content.
$block_content = $tag->get_updated_html();

Expand Down
7 changes: 7 additions & 0 deletions src/blocks/rsvp-v2/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,13 @@ const Edit = ({ attributes, setAttributes, clientId }) => {
),
value: 'not_attending',
},
{
label: __(
'Past Event (Event has already occurred)',
'gatherpress'
),
value: 'past',
},
]}
onChange={handleStatusChange}
/>
Expand Down
2 changes: 2 additions & 0 deletions src/blocks/rsvp-v2/templates.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import ATTENDING from './templates/attending';
import NO_STATUS from './templates/no-status';
import NOT_ATTENDING from './templates/not-attending';
import WAITING_LIST from './templates/waiting-list';
import PAST from './templates/past';

/**
* RSVP block templates mapped by status.
Expand All @@ -19,6 +20,7 @@ const TEMPLATES = {
attending: ATTENDING,
waiting_list: WAITING_LIST,
not_attending: NOT_ATTENDING,
past: PAST,
};

export default TEMPLATES;
29 changes: 29 additions & 0 deletions src/blocks/rsvp-v2/templates/past.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/**
* WordPress dependencies.
*/
import { __ } from '@wordpress/i18n';

const PAST = [
[
'core/buttons',
{
align: 'center',
layout: { type: 'flex', justifyContent: 'center' },
metadata: {
name: __('RSVP Buttons', 'gatherpress'),
},
},
[
[
'core/button',
{
text: __('Past Event', 'gatherpress'),
tagName: 'button',
className: 'gatherpress--is-disabled',
},
],
],
],
];

export default PAST;
6 changes: 6 additions & 0 deletions src/utility.scss
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,9 @@
.gatherpress--close-modal {
cursor: pointer;
}

.gatherpress--is-disabled {
pointer-events: none;
opacity: 0.6;
cursor: not-allowed;
}

0 comments on commit a03a851

Please sign in to comment.