From a16788ffc9a835aae074985373ba61cd4afbf01e Mon Sep 17 00:00:00 2001 From: Mike Auteri Date: Tue, 14 Jan 2025 08:56:53 -0500 Subject: [PATCH] Fix --- .../blocks/rsvp-anonymous-checkbox/block.json | 3 -- .../rsvp-anonymous-checkbox/index.asset.php | 2 +- build/blocks/rsvp-anonymous-checkbox/index.js | 2 +- .../blocks/rsvp-anonymous-checkbox/render.php | 7 +---- build/blocks/rsvp-response-v2/index.asset.php | 2 +- build/blocks/rsvp-response-v2/index.js | 2 +- src/blocks/rsvp-anonymous-checkbox/block.json | 3 -- src/blocks/rsvp-anonymous-checkbox/edit.js | 17 +---------- src/blocks/rsvp-anonymous-checkbox/render.php | 7 +---- src/blocks/rsvp-response-v2/edit.js | 28 ++++++++++--------- 10 files changed, 22 insertions(+), 51 deletions(-) diff --git a/build/blocks/rsvp-anonymous-checkbox/block.json b/build/blocks/rsvp-anonymous-checkbox/block.json index daa6ed3f8..31872e016 100644 --- a/build/blocks/rsvp-anonymous-checkbox/block.json +++ b/build/blocks/rsvp-anonymous-checkbox/block.json @@ -15,9 +15,6 @@ "label": { "type": "string", "default": "List me as anonymous." - }, - "inputId": { - "type": "string" } }, "supports": { diff --git a/build/blocks/rsvp-anonymous-checkbox/index.asset.php b/build/blocks/rsvp-anonymous-checkbox/index.asset.php index feac32eda..2c85d040c 100644 --- a/build/blocks/rsvp-anonymous-checkbox/index.asset.php +++ b/build/blocks/rsvp-anonymous-checkbox/index.asset.php @@ -1 +1 @@ - array('react-jsx-runtime', 'wp-block-editor', 'wp-blocks', 'wp-data', 'wp-element', 'wp-i18n'), 'version' => '43cba41cee556ecbaf3f'); + array('react-jsx-runtime', 'wp-block-editor', 'wp-blocks', 'wp-data', 'wp-i18n'), 'version' => 'd901b75e96794dd35cf1'); diff --git a/build/blocks/rsvp-anonymous-checkbox/index.js b/build/blocks/rsvp-anonymous-checkbox/index.js index c7c298a35..a938e438b 100644 --- a/build/blocks/rsvp-anonymous-checkbox/index.js +++ b/build/blocks/rsvp-anonymous-checkbox/index.js @@ -1 +1 @@ -(()=>{"use strict";var e,t={2887:()=>{const e=window.wp.blocks,t=window.wp.i18n,r=window.wp.blockEditor,o=window.wp.element,n=window.wp.data,s={randomUUID:"undefined"!=typeof crypto&&crypto.randomUUID&&crypto.randomUUID.bind(crypto)};let a;const i=new Uint8Array(16);function l(){if(!a){if("undefined"==typeof crypto||!crypto.getRandomValues)throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");a=crypto.getRandomValues.bind(crypto)}return a(i)}const p=[];for(let e=0;e<256;++e)p.push((e+256).toString(16).slice(1));const c=function(e,t,r){if(s.randomUUID&&!t&&!e)return s.randomUUID();const o=(e=e||{}).random||(e.rng||l)();if(o[6]=15&o[6]|64,o[8]=63&o[8]|128,t){r=r||0;for(let e=0;e<16;++e)t[r+e]=o[e];return t}return function(e,t=0){return(p[e[t+0]]+p[e[t+1]]+p[e[t+2]]+p[e[t+3]]+"-"+p[e[t+4]]+p[e[t+5]]+"-"+p[e[t+6]]+p[e[t+7]]+"-"+p[e[t+8]]+p[e[t+9]]+"-"+p[e[t+10]]+p[e[t+11]]+p[e[t+12]]+p[e[t+13]]+p[e[t+14]]+p[e[t+15]]).toLowerCase()}(o)},u=window.ReactJSXRuntime,d=JSON.parse('{"$schema":"https://schemas.wp.org/trunk/block.json","apiVersion":3,"name":"gatherpress/rsvp-anonymous-checkbox","version":"1.0.0","title":"RSVP Anonymous Checkbox","description":"Allows users to choose to remain anonymous in the RSVP response, preventing their name or photo from being displayed.","category":"gatherpress","ancestor":["gatherpress/rsvp-v2"],"icon":"yes","example":{},"attributes":{"label":{"type":"string","default":"List me as anonymous."},"inputId":{"type":"string"}},"supports":{"align":["left","center","right"],"spacing":{"margin":true,"padding":true},"color":{"text":true,"background":true},"html":false,"interactivity":true},"textdomain":"gatherpress","editorScript":"file:./index.js","style":"file:./style-index.css","render":"file:./render.php"}');(0,e.registerBlockType)(d,{edit:({attributes:e,setAttributes:s})=>{const{label:a,inputId:i}=e;(0,o.useEffect)((()=>{i||s({inputId:"input-"+c()})}),[i,s]);const l=(0,n.useSelect)((e=>e("core/editor").getEditedPostAttribute("meta")?.gatherpress_enable_anonymous_rsvp),[]),p=(0,r.useBlockProps)({className:1!==l?"gatherpress--is-not-visible":""});return(0,u.jsxs)("p",{...p,children:[(0,u.jsx)("input",{type:"checkbox",id:i,"aria-label":a||(0,t.__)("Anonymous Checkbox","gatherpress"),disabled:!0}),(0,u.jsx)(r.RichText,{tagName:"label",htmlFor:i,value:a,onChange:e=>s({label:e}),placeholder:(0,t.__)("Enter label…","gatherpress"),"aria-label":(0,t.__)("Editable label for anonymous checkbox","gatherpress"),allowedFormats:["core/bold","core/italic"],multiline:!1})]})},save:()=>null})}},r={};function o(e){var n=r[e];if(void 0!==n)return n.exports;var s=r[e]={exports:{}};return t[e](s,s.exports,o),s.exports}o.m=t,e=[],o.O=(t,r,n,s)=>{if(!r){var a=1/0;for(c=0;c=s)&&Object.keys(o.O).every((e=>o.O[e](r[l])))?r.splice(l--,1):(i=!1,s0&&e[c-1][2]>s;c--)e[c]=e[c-1];e[c]=[r,n,s]},o.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),(()=>{var e={5962:0,7614:0};o.O.j=t=>0===e[t];var t=(t,r)=>{var n,s,[a,i,l]=r,p=0;if(a.some((t=>0!==e[t]))){for(n in i)o.o(i,n)&&(o.m[n]=i[n]);if(l)var c=l(o)}for(t&&t(r);po(2887)));n=o.O(n)})(); \ No newline at end of file +(()=>{"use strict";var e,r={8064:()=>{const e=window.wp.blocks,r=window.wp.i18n,t=window.wp.blockEditor,s=window.wp.data,o=window.ReactJSXRuntime,a=JSON.parse('{"$schema":"https://schemas.wp.org/trunk/block.json","apiVersion":3,"name":"gatherpress/rsvp-anonymous-checkbox","version":"1.0.0","title":"RSVP Anonymous Checkbox","description":"Allows users to choose to remain anonymous in the RSVP response, preventing their name or photo from being displayed.","category":"gatherpress","ancestor":["gatherpress/rsvp-v2"],"icon":"yes","example":{},"attributes":{"label":{"type":"string","default":"List me as anonymous."}},"supports":{"align":["left","center","right"],"spacing":{"margin":true,"padding":true},"color":{"text":true,"background":true},"html":false,"interactivity":true},"textdomain":"gatherpress","editorScript":"file:./index.js","style":"file:./style-index.css","render":"file:./render.php"}');(0,e.registerBlockType)(a,{edit:({attributes:e,setAttributes:a})=>{const{label:n}=e,i=(0,s.useSelect)((e=>e("core/editor").getEditedPostAttribute("meta")?.gatherpress_enable_anonymous_rsvp),[]),l=(0,t.useBlockProps)({className:1!==i?"gatherpress--is-not-visible":""});return(0,o.jsxs)("p",{...l,children:[(0,o.jsx)("input",{type:"checkbox","aria-label":n||(0,r.__)("Anonymous Checkbox","gatherpress"),disabled:!0}),(0,o.jsx)(t.RichText,{tagName:"label",value:n,onChange:e=>a({label:e}),placeholder:(0,r.__)("Enter label…","gatherpress"),"aria-label":(0,r.__)("Editable label for anonymous checkbox","gatherpress"),allowedFormats:["core/bold","core/italic"],multiline:!1})]})},save:()=>null})}},t={};function s(e){var o=t[e];if(void 0!==o)return o.exports;var a=t[e]={exports:{}};return r[e](a,a.exports,s),a.exports}s.m=r,e=[],s.O=(r,t,o,a)=>{if(!t){var n=1/0;for(c=0;c=a)&&Object.keys(s.O).every((e=>s.O[e](t[l])))?t.splice(l--,1):(i=!1,a0&&e[c-1][2]>a;c--)e[c]=e[c-1];e[c]=[t,o,a]},s.o=(e,r)=>Object.prototype.hasOwnProperty.call(e,r),(()=>{var e={5962:0,7614:0};s.O.j=r=>0===e[r];var r=(r,t)=>{var o,a,[n,i,l]=t,p=0;if(n.some((r=>0!==e[r]))){for(o in i)s.o(i,o)&&(s.m[o]=i[o]);if(l)var c=l(s)}for(r&&r(t);ps(8064)));o=s.O(o)})(); \ No newline at end of file diff --git a/build/blocks/rsvp-anonymous-checkbox/render.php b/build/blocks/rsvp-anonymous-checkbox/render.php index 452685926..fcec0e960 100644 --- a/build/blocks/rsvp-anonymous-checkbox/render.php +++ b/build/blocks/rsvp-anonymous-checkbox/render.php @@ -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 ) ) { diff --git a/build/blocks/rsvp-response-v2/index.asset.php b/build/blocks/rsvp-response-v2/index.asset.php index f118a4550..0882629c9 100644 --- a/build/blocks/rsvp-response-v2/index.asset.php +++ b/build/blocks/rsvp-response-v2/index.asset.php @@ -1 +1 @@ - 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'); + 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'); diff --git a/build/blocks/rsvp-response-v2/index.js b/build/blocks/rsvp-response-v2/index.js index 39906893a..42cfb7378 100644 --- a/build/blocks/rsvp-response-v2/index.js +++ b/build/blocks/rsvp-response-v2/index.js @@ -1 +1 @@ -(()=>{"use strict";var e,t={8392:(e,t,s)=>{const r=window.wp.blocks,a=window.wp.blockEditor,n=window.wp.i18n,o=window.wp.components,i=window.wp.element,p=window.wp.apiFetch;var l=s.n(p);const d=window.wp.data,c=window.wp.coreData;function g(e){if("object"==typeof GatherPress)return e.split(".").reduce(((e,t)=>e&&e[t]),GatherPress)}const u=window.ReactJSXRuntime,h=({defaultStatus:e,setDefaultStatus:t})=>{var s;const r=g("eventDetails.responses"),a=g("eventDetails.postId"),[p,h]=(0,i.useState)(r),m=p[e].responses,{userList:v}=(0,d.useSelect)((e=>{const{getEntityRecords:t}=e(c.store);return{userList:t("root","user",{per_page:-1})}}),[]),f=null!==(s=v?.reduce(((e,t)=>({...e,[t.username]:t})),{}))&&void 0!==s?s:{},b=(e,t="attending")=>{l()({path:g("urls.eventApiPath")+"/rsvp",method:"POST",data:{post_id:a,status:t,user_id:e,_wpnonce:g("misc.nonce")}}).then((e=>{h(e.responses),function(e,t){if("object"!=typeof GatherPress)return;const s="eventDetails.responses".split("."),r=s.pop();s.reduce(((e,t)=>{var s;return null!==(s=e[t])&&void 0!==s?s:e[t]={}}),GatherPress)[r]=t}(0,e.responses)}))};return(0,u.jsxs)(u.Fragment,{children:[(0,u.jsx)(o.SelectControl,{label:(0,n.__)("RSVP Status","gatherpress"),value:e,options:[{label:(0,n._x)("Attending","List Status","gatherpress"),value:"attending"},{label:(0,n._x)("Waiting List","List Status","gatherpress"),value:"waiting_list"},{label:(0,n._x)("Not Attending","List Status","gatherpress"),value:"not_attending"}],onChange:e=>t(e)}),(0,u.jsx)(o.FormTokenField,{label:(0,n.__)("Members","gatherpress"),value:m&&m.map((e=>({id:e.id,value:e.name}))),tokenizeOnSpace:!0,onChange:async t=>{t.length>m.length?t.forEach((t=>{f[t]&&b(f[t].id,e)})):m.forEach((e=>{!1===t.some((t=>t.id===e.id))&&b(e.id,"no_status")}))},suggestions:Object.keys(f),maxSuggestions:20},"query-controls-topics-select")]})},m={attending:(0,n.__)("Attending (%d)","gatherpress"),waitingList:(0,n.__)("Waiting List (%d)","gatherpress"),notAttending:(0,n.__)("Not Attending (%d)","gatherpress"),noOne:(0,n.__)("No one is attending this event yet.","gatherpress")},v=[["core/group",{style:{spacing:{blockGap:"var:preset|spacing|20",margin:{bottom:"var:preset|spacing|30"}}},layout:{type:"flex",flexWrap:"nowrap",justifyContent:"space-between"}},[["core/group",{style:{spacing:{blockGap:"var:preset|spacing|20",margin:{bottom:"var:preset|spacing|30"}}},layout:{type:"flex",flexWrap:"nowrap"}},[["gatherpress/icon",{icon:"groups"}],["gatherpress/dropdown",{actAsSelect:!0,dropdownId:"dropdown-7968ad05-cf12-41ae-8392-7fb01e166188",label:m.attending,metadata:{name:m.attending}},[["gatherpress/dropdown-item",{text:`${m.attending}`,metadata:{name:m.attending},className:"gatherpress--rsvp-attending"}],["gatherpress/dropdown-item",{text:`${m.waitingList}`,metadata:{name:m.waitingList},className:"gatherpress--rsvp-waiting-list"}],["gatherpress/dropdown-item",{text:`${m.notAttending}`,metadata:{name:m.notAttending},className:"gatherpress--rsvp-not-attending"}]]]]],["gatherpress/rsvp-response-toggle"]]],["core/group",{layout:{type:"grid",columns:3,justifyContent:"center",alignContent:"space-around",minimumColumnWidth:"8rem"},className:"gatherpress--rsvp-responses"},[["gatherpress/rsvp-template",{}]]],["core/group",{metadata:{name:(0,n.__)("Empty RSVP","gatherpress")},className:"gatherpress--empty-rsvp gatherpress--is-not-visible"},[["core/paragraph",{content:m.noOne}]]]],f=JSON.parse('{"$schema":"https://schemas.wp.org/trunk/block.json","apiVersion":3,"name":"gatherpress/rsvp-response-v2","version":"2.0.0","title":"RSVP Response V2","category":"gatherpress","icon":"groups","example":{},"description":"Displays a list of members who have confirmed their attendance for an event.","usesContext":["postId","queryId"],"attributes":{"rsvpLimitEnabled":{"type":"boolean","default":false},"rsvpLimit":{"type":"number","default":8}},"supports":{"gatherpress":{"postIdOverride":true},"align":["wide","full"],"interactivity":true,"html":false},"providesContext":{"commentId":"commentId","postId":"postId","gatherpress/rsvpLimitEnabled":"rsvpLimitEnabled","gatherpress/rsvpLimit":"rsvpLimit"},"textdomain":"gatherpress","editorScript":"file:./index.js","style":"file:./style-index.css","viewScriptModule":"file:./view.js"}');(0,r.registerBlockType)(f,{edit:({attributes:e,setAttributes:t,context:s})=>{var r,p;const l=(0,a.useBlockProps)(),[d,c]=(0,i.useState)(!1),[m,f]=(0,i.useState)(!1),[b,w]=(0,i.useState)("attending"),[_,x]=(0,i.useState)(null),[y,S]=(0,i.useState)(!0),[j,k]=(0,i.useState)(null),L=null!==(r=null!==(p=e?.postId)&&void 0!==p?p:s?.postId)&&void 0!==r?r:null,{rsvpLimitEnabled:P,rsvpLimit:C}=e;return(0,i.useEffect)((()=>{const e=document.querySelectorAll(".gatherpress--empty-rsvp"),t=document.querySelectorAll(".gatherpress--rsvp-responses");e.forEach((e=>{e.classList.toggle("gatherpress--is-not-visible",!m)})),t.forEach((e=>{e.classList.toggle("gatherpress--is-not-visible",m)}))}),[m,_]),(0,i.useEffect)((()=>{if(!L)return x(null),void S(!1);S(!0),k(null),async function(e){const t=g("urls.eventApiUrl");return(await fetch(`${t}/rsvp-responses?post_id=${e}`)).json()}(L).then((e=>{x(e.data),S(!1)})).catch((e=>{k(e.message),S(!1)}))}),[L]),y?(0,u.jsx)("div",{...l,children:(0,u.jsx)(o.Spinner,{})}):j?(0,u.jsx)("div",{...l,children:(0,u.jsx)("p",{children:(0,n.__)("Failed to load RSVP responses.","gatherpress")})}):(0,u.jsx)("div",{...l,children:(0,u.jsxs)(a.BlockContextProvider,{value:{"gatherpress/rsvpResponses":_,"gatherpress/rsvpLimitEnabled":P,"gatherpress/rsvpLimit":C,postId:L},children:[(0,u.jsx)(a.InspectorControls,{children:(0,u.jsxs)(o.PanelBody,{children:[(0,u.jsx)(o.ToggleControl,{label:(0,n.__)("Show Empty RSVP Block","gatherpress"),checked:m,onChange:e=>f(e),help:(0,n.__)("Toggle to show or hide the Empty RSVP block.","gatherpress")}),(0,u.jsx)(o.ToggleControl,{label:(0,n.__)("Limit RSVP Display","gatherpress"),checked:P,onChange:()=>t({rsvpLimitEnabled:!P}),help:(0,n.__)("Enable to limit the number of RSVPs displayed in this block.","gatherpress")}),P&&(0,u.jsx)(o.__experimentalNumberControl,{label:(0,n.__)("RSVP Display Limit","gatherpress"),value:C,onChange:e=>t({rsvpLimit:parseInt(e,10)||8}),min:1,max:100,help:(0,n.__)("Set the maximum number of RSVPs to display. Default is 8.","gatherpress")})]})}),(0,u.jsx)(a.BlockControls,{children:(0,u.jsx)(o.ToolbarGroup,{children:(0,u.jsx)(o.ToolbarButton,{label:(0,n.__)("Edit","gatherpress"),text:d?(0,n.__)("Preview","gatherpress"):(0,n.__)("Edit","gatherpress"),onClick:e=>{e.preventDefault(),c(!d)}})})}),d&&(0,u.jsx)(h,{defaultStatus:b,setDefaultStatus:w}),!d&&(0,u.jsx)(a.InnerBlocks,{template:v})]})})},save:()=>(0,u.jsx)("div",{...a.useBlockProps.save(),children:(0,u.jsx)(a.InnerBlocks.Content,{})})})}},s={};function r(e){var a=s[e];if(void 0!==a)return a.exports;var n=s[e]={exports:{}};return t[e](n,n.exports,r),n.exports}r.m=t,e=[],r.O=(t,s,a,n)=>{if(!s){var o=1/0;for(d=0;d=n)&&Object.keys(r.O).every((e=>r.O[e](s[p])))?s.splice(p--,1):(i=!1,n0&&e[d-1][2]>n;d--)e[d]=e[d-1];e[d]=[s,a,n]},r.n=e=>{var t=e&&e.__esModule?()=>e.default:()=>e;return r.d(t,{a:t}),t},r.d=(e,t)=>{for(var s in t)r.o(t,s)&&!r.o(e,s)&&Object.defineProperty(e,s,{enumerable:!0,get:t[s]})},r.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),(()=>{var e={8291:0,6507:0};r.O.j=t=>0===e[t];var t=(t,s)=>{var a,n,[o,i,p]=s,l=0;if(o.some((t=>0!==e[t]))){for(a in i)r.o(i,a)&&(r.m[a]=i[a]);if(p)var d=p(r)}for(t&&t(s);lr(8392)));a=r.O(a)})(); \ No newline at end of file +(()=>{"use strict";var e,t={8392:(e,t,s)=>{const r=window.wp.blocks,n=window.wp.blockEditor,a=window.wp.i18n,o=window.wp.components,i=window.wp.element,p=window.wp.apiFetch;var l=s.n(p);const d=window.wp.data,c=window.wp.coreData;function u(e){if("object"==typeof GatherPress)return e.split(".").reduce(((e,t)=>e&&e[t]),GatherPress)}const g=window.ReactJSXRuntime,h=({defaultStatus:e,setDefaultStatus:t})=>{var s;const r=u("eventDetails.responses"),n=u("eventDetails.postId"),[p,h]=(0,i.useState)(r),m=p[e].responses,{userList:v}=(0,d.useSelect)((e=>{const{getEntityRecords:t}=e(c.store);return{userList:t("root","user",{per_page:-1})}}),[]),f=null!==(s=v?.reduce(((e,t)=>({...e,[t.username]:t})),{}))&&void 0!==s?s:{},b=(e,t="attending")=>{l()({path:u("urls.eventApiPath")+"/rsvp",method:"POST",data:{post_id:n,status:t,user_id:e,_wpnonce:u("misc.nonce")}}).then((e=>{h(e.responses),function(e,t){if("object"!=typeof GatherPress)return;const s="eventDetails.responses".split("."),r=s.pop();s.reduce(((e,t)=>{var s;return null!==(s=e[t])&&void 0!==s?s:e[t]={}}),GatherPress)[r]=t}(0,e.responses)}))};return(0,g.jsxs)(g.Fragment,{children:[(0,g.jsx)(o.SelectControl,{label:(0,a.__)("RSVP Status","gatherpress"),value:e,options:[{label:(0,a._x)("Attending","List Status","gatherpress"),value:"attending"},{label:(0,a._x)("Waiting List","List Status","gatherpress"),value:"waiting_list"},{label:(0,a._x)("Not Attending","List Status","gatherpress"),value:"not_attending"}],onChange:e=>t(e)}),(0,g.jsx)(o.FormTokenField,{label:(0,a.__)("Members","gatherpress"),value:m&&m.map((e=>({id:e.id,value:e.name}))),tokenizeOnSpace:!0,onChange:async t=>{t.length>m.length?t.forEach((t=>{f[t]&&b(f[t].id,e)})):m.forEach((e=>{!1===t.some((t=>t.id===e.id))&&b(e.id,"no_status")}))},suggestions:Object.keys(f),maxSuggestions:20},"query-controls-topics-select")]})},m={attending:(0,a.__)("Attending (%d)","gatherpress"),waitingList:(0,a.__)("Waiting List (%d)","gatherpress"),notAttending:(0,a.__)("Not Attending (%d)","gatherpress"),noOne:(0,a.__)("No one is attending this event yet.","gatherpress")},v=[["core/group",{style:{spacing:{blockGap:"var:preset|spacing|20",margin:{bottom:"var:preset|spacing|30"}}},layout:{type:"flex",flexWrap:"nowrap",justifyContent:"space-between"}},[["core/group",{style:{spacing:{blockGap:"var:preset|spacing|20",margin:{bottom:"var:preset|spacing|30"}}},layout:{type:"flex",flexWrap:"nowrap"}},[["gatherpress/icon",{icon:"groups"}],["gatherpress/dropdown",{actAsSelect:!0,dropdownId:"dropdown-7968ad05-cf12-41ae-8392-7fb01e166188",label:m.attending,metadata:{name:m.attending}},[["gatherpress/dropdown-item",{text:`${m.attending}`,metadata:{name:m.attending},className:"gatherpress--rsvp-attending"}],["gatherpress/dropdown-item",{text:`${m.waitingList}`,metadata:{name:m.waitingList},className:"gatherpress--rsvp-waiting-list"}],["gatherpress/dropdown-item",{text:`${m.notAttending}`,metadata:{name:m.notAttending},className:"gatherpress--rsvp-not-attending"}]]]]],["gatherpress/rsvp-response-toggle"]]],["core/group",{layout:{type:"grid",columns:3,justifyContent:"center",alignContent:"space-around",minimumColumnWidth:"8rem"},className:"gatherpress--rsvp-responses"},[["gatherpress/rsvp-template",{}]]],["core/group",{metadata:{name:(0,a.__)("Empty RSVP","gatherpress")},className:"gatherpress--empty-rsvp gatherpress--is-not-visible"},[["core/paragraph",{content:m.noOne}]]]],f=JSON.parse('{"$schema":"https://schemas.wp.org/trunk/block.json","apiVersion":3,"name":"gatherpress/rsvp-response-v2","version":"2.0.0","title":"RSVP Response V2","category":"gatherpress","icon":"groups","example":{},"description":"Displays a list of members who have confirmed their attendance for an event.","usesContext":["postId","queryId"],"attributes":{"rsvpLimitEnabled":{"type":"boolean","default":false},"rsvpLimit":{"type":"number","default":8}},"supports":{"gatherpress":{"postIdOverride":true},"align":["wide","full"],"interactivity":true,"html":false},"providesContext":{"commentId":"commentId","postId":"postId","gatherpress/rsvpLimitEnabled":"rsvpLimitEnabled","gatherpress/rsvpLimit":"rsvpLimit"},"textdomain":"gatherpress","editorScript":"file:./index.js","style":"file:./style-index.css","viewScriptModule":"file:./view.js"}');(0,r.registerBlockType)(f,{edit:({attributes:e,setAttributes:t,context:r})=>{var p,l;const d=(0,n.useBlockProps)(),[c,m]=(0,i.useState)(!1),[f,b]=(0,i.useState)(!1),[w,y]=(0,i.useState)("attending"),[_,x]=(0,i.useState)(null),[S,j]=(0,i.useState)(!0),[k,P]=(0,i.useState)(null),L=null!==(p=null!==(l=e?.postId)&&void 0!==l?l:r?.postId)&&void 0!==p?p:null,{rsvpLimitEnabled:C,rsvpLimit:E}=e;return(0,i.useEffect)((()=>{const e=s.g.document.querySelectorAll(".gatherpress--empty-rsvp"),t=s.g.document.querySelectorAll(".gatherpress--rsvp-responses");e.forEach((e=>{e.style.setProperty("display",f?"block":"none","important")})),t.forEach((e=>{f?e.style.setProperty("display","none","important"):e.style.removeProperty("display")}))}),[f,_]),(0,i.useEffect)((()=>{if(!L)return x(null),void j(!1);j(!0),P(null),async function(e){const t=u("urls.eventApiUrl");return(await fetch(`${t}/rsvp-responses?post_id=${e}`)).json()}(L).then((e=>{x(e.data),j(!1)})).catch((e=>{P(e.message),j(!1)}))}),[L]),S?(0,g.jsx)("div",{...d,children:(0,g.jsx)(o.Spinner,{})}):k?(0,g.jsx)("div",{...d,children:(0,g.jsx)("p",{children:(0,a.__)("Failed to load RSVP responses.","gatherpress")})}):(0,g.jsx)("div",{...d,children:(0,g.jsxs)(n.BlockContextProvider,{value:{"gatherpress/rsvpResponses":_,"gatherpress/rsvpLimitEnabled":C,"gatherpress/rsvpLimit":E,postId:L},children:[(0,g.jsx)(n.InspectorControls,{children:(0,g.jsxs)(o.PanelBody,{children:[(0,g.jsx)(o.ToggleControl,{label:(0,a.__)("Show Empty RSVP Block","gatherpress"),checked:f,onChange:e=>b(e),help:(0,a.__)("Toggle to show or hide the Empty RSVP block.","gatherpress")}),(0,g.jsx)(o.ToggleControl,{label:(0,a.__)("Limit RSVP Display","gatherpress"),checked:C,onChange:()=>t({rsvpLimitEnabled:!C}),help:(0,a.__)("Enable to limit the number of RSVPs displayed in this block.","gatherpress")}),C&&(0,g.jsx)(o.__experimentalNumberControl,{label:(0,a.__)("RSVP Display Limit","gatherpress"),value:E,onChange:e=>t({rsvpLimit:parseInt(e,10)||8}),min:1,max:100,help:(0,a.__)("Set the maximum number of RSVPs to display. Default is 8.","gatherpress")})]})}),(0,g.jsx)(n.BlockControls,{children:(0,g.jsx)(o.ToolbarGroup,{children:(0,g.jsx)(o.ToolbarButton,{label:(0,a.__)("Edit","gatherpress"),text:c?(0,a.__)("Preview","gatherpress"):(0,a.__)("Edit","gatherpress"),onClick:e=>{e.preventDefault(),m(!c)}})})}),c&&(0,g.jsx)(h,{defaultStatus:w,setDefaultStatus:y}),!c&&(0,g.jsx)(n.InnerBlocks,{template:v})]})})},save:()=>(0,g.jsx)("div",{...n.useBlockProps.save(),children:(0,g.jsx)(n.InnerBlocks.Content,{})})})}},s={};function r(e){var n=s[e];if(void 0!==n)return n.exports;var a=s[e]={exports:{}};return t[e](a,a.exports,r),a.exports}r.m=t,e=[],r.O=(t,s,n,a)=>{if(!s){var o=1/0;for(d=0;d=a)&&Object.keys(r.O).every((e=>r.O[e](s[p])))?s.splice(p--,1):(i=!1,a0&&e[d-1][2]>a;d--)e[d]=e[d-1];e[d]=[s,n,a]},r.n=e=>{var t=e&&e.__esModule?()=>e.default:()=>e;return r.d(t,{a:t}),t},r.d=(e,t)=>{for(var s in t)r.o(t,s)&&!r.o(e,s)&&Object.defineProperty(e,s,{enumerable:!0,get:t[s]})},r.g=function(){if("object"==typeof globalThis)return globalThis;try{return this||new Function("return this")()}catch(e){if("object"==typeof window)return window}}(),r.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),(()=>{var e={8291:0,6507:0};r.O.j=t=>0===e[t];var t=(t,s)=>{var n,a,[o,i,p]=s,l=0;if(o.some((t=>0!==e[t]))){for(n in i)r.o(i,n)&&(r.m[n]=i[n]);if(p)var d=p(r)}for(t&&t(s);lr(8392)));n=r.O(n)})(); \ No newline at end of file diff --git a/src/blocks/rsvp-anonymous-checkbox/block.json b/src/blocks/rsvp-anonymous-checkbox/block.json index 47f0f79d6..f667c5123 100644 --- a/src/blocks/rsvp-anonymous-checkbox/block.json +++ b/src/blocks/rsvp-anonymous-checkbox/block.json @@ -13,9 +13,6 @@ "label": { "type": "string", "default": "List me as anonymous." - }, - "inputId": { - "type": "string" } }, "supports": { diff --git a/src/blocks/rsvp-anonymous-checkbox/edit.js b/src/blocks/rsvp-anonymous-checkbox/edit.js index 98d3f2781..42fb92139 100644 --- a/src/blocks/rsvp-anonymous-checkbox/edit.js +++ b/src/blocks/rsvp-anonymous-checkbox/edit.js @@ -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. * @@ -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) => @@ -53,13 +40,11 @@ const Edit = ({ attributes, setAttributes }) => {

setAttributes({ label: newLabel })} placeholder={__('Enter label…', 'gatherpress')} diff --git a/src/blocks/rsvp-anonymous-checkbox/render.php b/src/blocks/rsvp-anonymous-checkbox/render.php index 452685926..fcec0e960 100644 --- a/src/blocks/rsvp-anonymous-checkbox/render.php +++ b/src/blocks/rsvp-anonymous-checkbox/render.php @@ -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 ) ) { diff --git a/src/blocks/rsvp-response-v2/edit.js b/src/blocks/rsvp-response-v2/edit.js index cd812149d..1bed7026b 100644 --- a/src/blocks/rsvp-response-v2/edit.js +++ b/src/blocks/rsvp-response-v2/edit.js @@ -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); @@ -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(() => { @@ -146,8 +148,8 @@ const Edit = ({ attributes, setAttributes, context }) => { setShowEmptyRsvpMessage(value)} + checked={showEmptyRsvpBlock} + onChange={(value) => setShowEmptyRsvpBlock(value)} help={__( 'Toggle to show or hide the Empty RSVP block.', 'gatherpress'