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

Fix #996

Merged
merged 1 commit into from
Jan 14, 2025
Merged

Fix #996

Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 0 additions & 3 deletions build/blocks/rsvp-anonymous-checkbox/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@
"label": {
"type": "string",
"default": "List me as anonymous."
},
"inputId": {
"type": "string"
}
},
"supports": {
Expand Down
2 changes: 1 addition & 1 deletion build/blocks/rsvp-anonymous-checkbox/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-data', 'wp-element', 'wp-i18n'), 'version' => '43cba41cee556ecbaf3f');
<?php return array('dependencies' => array('react-jsx-runtime', 'wp-block-editor', 'wp-blocks', 'wp-data', 'wp-i18n'), 'version' => 'd901b75e96794dd35cf1');
2 changes: 1 addition & 1 deletion build/blocks/rsvp-anonymous-checkbox/index.js

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

7 changes: 1 addition & 6 deletions build/blocks/rsvp-anonymous-checkbox/render.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,7 @@
use GatherPress\Core\Rsvp;

$gatherpress_enable_anonymous_rsvp = get_post_meta( get_the_ID(), 'gatherpress_enable_anonymous_rsvp', true );
$gatherpress_input_id = $block->attributes['inputId'] ?? null;

// This should never be empty.
if ( empty( $gatherpress_input_id ) ) {
return;
}
$gatherpress_input_id = sprintf( 'gatherpress_%s', wp_rand() );

// If enable anonymous rsvp is set to 0, displaying as anonymous are not permitted. Do not render the block.
if ( empty( $gatherpress_enable_anonymous_rsvp ) ) {
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' => 'd1f201278353398a6f95');
<?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' => '2b2da48340048effaf67');
2 changes: 1 addition & 1 deletion build/blocks/rsvp-response-v2/index.js

Large diffs are not rendered by default.

3 changes: 0 additions & 3 deletions src/blocks/rsvp-anonymous-checkbox/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@
"label": {
"type": "string",
"default": "List me as anonymous."
},
"inputId": {
"type": "string"
}
},
"supports": {
Expand Down
17 changes: 1 addition & 16 deletions src/blocks/rsvp-anonymous-checkbox/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,8 @@
*/
import { __ } from '@wordpress/i18n';
import { useBlockProps, RichText } from '@wordpress/block-editor';
import { useEffect } from '@wordpress/element';
import { useSelect } from '@wordpress/data';

/**
* External dependencies.
*/
import { v4 as uuidv4 } from 'uuid';

/**
* Edit component for the RSVP Anonymous Checkbox Block.
*
Expand All @@ -27,14 +21,7 @@ import { v4 as uuidv4 } from 'uuid';
* @return {JSX.Element} The rendered edit interface for the block.
*/
const Edit = ({ attributes, setAttributes }) => {
const { label, inputId } = attributes;

// Generate UUID for input if not already set.
useEffect(() => {
if (!inputId) {
setAttributes({ inputId: 'input-' + uuidv4() });
}
}, [inputId, setAttributes]);
const { label } = attributes;

const enableAnonymousRsvp = useSelect(
(select) =>
Expand All @@ -53,13 +40,11 @@ const Edit = ({ attributes, setAttributes }) => {
<p {...blockProps}>
<input
type="checkbox"
id={inputId}
aria-label={label || __('Anonymous Checkbox', 'gatherpress')}
disabled={true}
/>
<RichText
tagName="label"
htmlFor={inputId}
value={label}
onChange={(newLabel) => setAttributes({ label: newLabel })}
placeholder={__('Enter label…', 'gatherpress')}
Expand Down
7 changes: 1 addition & 6 deletions src/blocks/rsvp-anonymous-checkbox/render.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,7 @@
use GatherPress\Core\Rsvp;

$gatherpress_enable_anonymous_rsvp = get_post_meta( get_the_ID(), 'gatherpress_enable_anonymous_rsvp', true );
$gatherpress_input_id = $block->attributes['inputId'] ?? null;

// This should never be empty.
if ( empty( $gatherpress_input_id ) ) {
return;
}
$gatherpress_input_id = sprintf( 'gatherpress_%s', wp_rand() );

// If enable anonymous rsvp is set to 0, displaying as anonymous are not permitted. Do not render the block.
if ( empty( $gatherpress_enable_anonymous_rsvp ) ) {
Expand Down
28 changes: 15 additions & 13 deletions src/blocks/rsvp-response-v2/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ async function fetchRsvpResponses(postId) {
const Edit = ({ attributes, setAttributes, context }) => {
const blockProps = useBlockProps();
const [editMode, setEditMode] = useState(false);
const [showEmptyRsvpMessage, setShowEmptyRsvpMessage] = useState(false);
const [showEmptyRsvpBlock, setShowEmptyRsvpBlock] = useState(false);
const [defaultStatus, setDefaultStatus] = useState('attending');
const [responses, setResponses] = useState(null);
const [loading, setLoading] = useState(true);
Expand All @@ -67,27 +67,29 @@ const Edit = ({ attributes, setAttributes, context }) => {
const { rsvpLimitEnabled, rsvpLimit } = attributes;

useEffect(() => {
const emptyBlocks = document.querySelectorAll(
const emptyBlocks = global.document.querySelectorAll(
'.gatherpress--empty-rsvp'
);
const responseBlocks = document.querySelectorAll(
const responseBlocks = global.document.querySelectorAll(
'.gatherpress--rsvp-responses'
);

emptyBlocks.forEach((block) => {
block.classList.toggle(
'gatherpress--is-not-visible',
!showEmptyRsvpMessage
block.style.setProperty(
'display',
showEmptyRsvpBlock ? 'block' : 'none',
'important'
);
});

responseBlocks.forEach((block) => {
block.classList.toggle(
'gatherpress--is-not-visible',
showEmptyRsvpMessage
);
if (!showEmptyRsvpBlock) {
block.style.removeProperty('display');
} else {
block.style.setProperty('display', 'none', 'important');
}
});
}, [showEmptyRsvpMessage, responses]);
}, [showEmptyRsvpBlock, responses]);

// Fetch responses when postId changes.
useEffect(() => {
Expand Down Expand Up @@ -146,8 +148,8 @@ const Edit = ({ attributes, setAttributes, context }) => {
<PanelBody>
<ToggleControl
label={__('Show Empty RSVP Block', 'gatherpress')}
checked={showEmptyRsvpMessage}
onChange={(value) => setShowEmptyRsvpMessage(value)}
checked={showEmptyRsvpBlock}
onChange={(value) => setShowEmptyRsvpBlock(value)}
help={__(
'Toggle to show or hide the Empty RSVP block.',
'gatherpress'
Expand Down
Loading