diff --git a/build/blocks/event-date/block.json b/build/blocks/event-date/block.json index 9566134b0..159ac99ac 100644 --- a/build/blocks/event-date/block.json +++ b/build/blocks/event-date/block.json @@ -10,7 +10,14 @@ "viewportWidth": 350 }, "description": "Displays the date and time for an event.", + "usesContext": [ + "postId", + "queryId" + ], "attributes": { + "postId": { + "type": "number" + }, "eventEnd": { "type": "string" }, diff --git a/build/blocks/event-date/index.asset.php b/build/blocks/event-date/index.asset.php index aedda72b0..e3d275f41 100644 --- a/build/blocks/event-date/index.asset.php +++ b/build/blocks/event-date/index.asset.php @@ -1 +1 @@ - array('moment', 'react-jsx-runtime', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-data', 'wp-date', 'wp-element', 'wp-i18n'), 'version' => '3b2cb4f8293b125f5b7d'); + array('moment', 'react-jsx-runtime', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-data', 'wp-date', 'wp-element', 'wp-i18n'), 'version' => 'be92a6a3195e7f43022b'); diff --git a/build/blocks/event-date/index.js b/build/blocks/event-date/index.js index 08c30e58d..226f1dfc0 100644 --- a/build/blocks/event-date/index.js +++ b/build/blocks/event-date/index.js @@ -1,2 +1,2 @@ -(()=>{"use strict";var e,t={4034:(e,t,r)=>{const n=window.wp.blocks,a=window.moment;var s=r.n(a);function i(e){var t,r,n="";if("string"==typeof e||"number"==typeof e)n+=e;else if("object"==typeof e)if(Array.isArray(e)){var a=e.length;for(t=0;te&&e[t]),GatherPress)}function h(e,t){if("object"!=typeof GatherPress)return;const r=e.split("."),n=r.pop();r.reduce(((e,t)=>{var r;return null!==(r=e[t])&&void 0!==r?r:e[t]={}}),GatherPress)[n]=t}function g(){(0,m.dispatch)("core/editor")?.editPost({meta:{_non_existing_meta:!0}})}function f(){const e=(0,m.select)("core/editor")?.getCurrentPostType();return"gatherpress_event"===e||"gatherpress_venue"===e}const x=window.wp.date,v=window.ReactJSXRuntime,_="YYYY-MM-DD HH:mm:ss",T=s().tz(b()).add(1,"day").set("hour",18).set("minute",0).set("second",0).format(_),D=(s().tz(T,b()).add(2,"hours").format(_),[{label:(0,l.__)("1 hour","gatherpress"),value:1},{label:(0,l.__)("1.5 hours","gatherpress"),value:1.5},{label:(0,l.__)("2 hours","gatherpress"),value:2},{label:(0,l.__)("3 hours","gatherpress"),value:3},{label:(0,l.__)("Set an end time…","gatherpress"),value:!1}]);function j(e){return s().tz(function(){let e=p("eventDetails.dateTime.datetime_start");return e=""!==e?s().tz(e,b()).format(_):T,h("eventDetails.dateTime.datetime_start",e),e}(),b()).add(e,"hours").format(_)}function z(){return k(p("settings.dateFormat"))+" "+k(p("settings.timeFormat"))}function b(e=p("eventDetails.dateTime.timezone")){return s().tz.zone(e)?e:(0,l.__)("GMT","gatherpress")}function w(e=""){const t=/^([+-])(\d{2}):(00|15|30|45)$/,r=e.replace(t,"$1");return r!==e?"UTC"+r+parseInt(e.replace(t,"$2")).toString()+e.replace(t,"$3").replace("00","").replace("15",".25").replace("30",".5").replace("45",".75"):e}function S(e,t=null,r=null){!function(e,t=null){const r=s().tz(p("eventDetails.dateTime.datetime_end"),b()).valueOf(),n=s().tz(e,b()).valueOf();n>=r&&y(s().tz(n,b()).add(2,"hours").format(_),t)}(e,r),h("eventDetails.dateTime.datetime_start",e),"function"==typeof t&&t(e),g()}function y(e,t=null,r=null){!function(e,t=null){const r=s().tz(p("eventDetails.dateTime.datetime_start"),b()).valueOf(),n=s().tz(e,b()).valueOf();n<=r&&S(s().tz(n,b()).subtract(2,"hours").format(_),t)}(e,r),h("eventDetails.dateTime.datetime_end",e),null!==t&&t(e),g()}function k(e){const t={d:"DD",D:"ddd",j:"D",l:"dddd",N:"E",S:"o",w:"e",z:"DDD",W:"W",F:"MMMM",m:"MM",M:"MMM",n:"M",t:"",L:"",o:"YYYY",Y:"YYYY",y:"YY",a:"a",A:"A",B:"",g:"h",G:"H",h:"hh",H:"HH",i:"mm",s:"ss",u:"SSS",e:"zz",I:"",O:"",P:"",T:"",Z:"",c:"",r:"",U:"X"};return String(e).split("").map(((e,r,n)=>{const a=n[r-1];return e in t&&"\\"!==a?t[e]:e})).join("")}function C(){const e="gatherpress_event_past",t=(0,m.dispatch)("core/notices");t.removeNotice(e),function(){const e=s().tz(p("eventDetails.dateTime.datetime_end"),b());return"gatherpress_event"===(0,m.select)("core/editor")?.getCurrentPostType()&&s().tz(b()).valueOf()>e.valueOf()}()&&t.createNotice("warning",(0,l.__)("This event has already passed.","gatherpress"),{id:e,isDismissible:!1})}const O=()=>{const{dateTimeStart:e,duration:t}=(0,m.useSelect)((e=>({dateTimeStart:e("gatherpress/datetime").getDateTimeStart(),duration:e("gatherpress/datetime").getDuration()})),[]),{setDateTimeStart:r,setDateTimeEnd:n}=(0,m.useDispatch)("gatherpress/datetime"),a=(0,x.getSettings)(),i=/a(?!\\)/i.test(a.formats.time.toLowerCase().replace(/\\\\/g,"").split("").reverse().join(""));return(0,u.useEffect)((()=>{r(s().tz(e,b()).format(_)),t&&n(j(t)),C()}),[e,t,r,n]),(0,v.jsx)(c.PanelRow,{children:(0,v.jsxs)(c.Flex,{direction:"column",gap:"1",children:[(0,v.jsx)(c.FlexItem,{children:(0,v.jsx)("h3",{style:{marginBottom:0},children:(0,v.jsx)("label",{htmlFor:"gatherpress-datetime-start",children:(0,l.__)("Date & time start","gatherpress")})})}),(0,v.jsx)(c.FlexItem,{children:(0,v.jsx)(c.Dropdown,{popoverProps:{placement:"bottom-end"},renderToggle:({isOpen:t,onToggle:r})=>(0,v.jsx)(c.Button,{id:"gatherpress-datetime-start",onClick:r,"aria-expanded":t,isLink:!0,children:s().tz(e,b()).format(z())}),renderContent:()=>(0,v.jsx)(c.DateTimePicker,{currentDate:e,onChange:e=>{S(e,r,n)},is12Hour:i})})})]})})},E=()=>{const{dateTimeEnd:e}=(0,m.useSelect)((e=>({dateTimeEnd:e("gatherpress/datetime").getDateTimeEnd()})),[]),{setDateTimeEnd:t,setDateTimeStart:r}=(0,m.useDispatch)("gatherpress/datetime"),n=(0,x.getSettings)(),a=/a(?!\\)/i.test(n.formats.time.toLowerCase().replace(/\\\\/g,"").split("").reverse().join(""));return(0,u.useEffect)((()=>{t(s().tz(e,b()).format(_)),C()})),(0,v.jsx)(c.PanelRow,{children:(0,v.jsxs)(c.Flex,{direction:"column",gap:"1",children:[(0,v.jsx)(c.FlexItem,{children:(0,v.jsx)("h3",{style:{marginBottom:0},children:(0,v.jsx)("label",{htmlFor:"gatherpress-datetime-end",children:(0,l.__)("Date & time end","gatherpress")})})}),(0,v.jsx)(c.FlexItem,{children:(0,v.jsx)(c.Dropdown,{popoverProps:{placement:"bottom-end"},renderToggle:({isOpen:t,onToggle:r})=>(0,v.jsx)(c.Button,{id:"gatherpress-datetime-end",onClick:r,"aria-expanded":t,isLink:!0,children:s().tz(e,b()).format(z())}),renderContent:()=>(0,v.jsx)(c.DateTimePicker,{currentDate:e,onChange:e=>y(e,t,r),is12Hour:a})})})]})})},P=()=>{const{timezone:e}=(0,m.useSelect)((e=>({timezone:e("gatherpress/datetime").getTimezone()})),[]),{setTimezone:t}=(0,m.useDispatch)("gatherpress/datetime"),r=p("misc.timezoneChoices");return(0,u.useEffect)((()=>{t(p("eventDetails.dateTime.timezone"))}),[t]),(0,v.jsx)(c.PanelRow,{children:(0,v.jsx)(c.SelectControl,{label:(0,l.__)("Time Zone","gatherpress"),value:w(e),onChange:e=>{e=function(e=""){const t=/^UTC([+-])(\d+)(.\d+)?$/,r=e.replace(t,"$1");if(r!==e){const n=e.replace(t,"$2").padStart(2,"0");let a=e.replace(t,"$3");return""===a&&(a=":00"),a=a.replace(".25",":15").replace(".5",":30").replace(".75",":45"),r+n+a}return e}(e),t(e),g()},__nexthasnomarginbottom:!0,children:Object.keys(r).map((e=>(0,v.jsx)("optgroup",{label:e,children:Object.keys(r[e]).map((t=>(0,v.jsx)("option",{value:t,children:r[e][t]},t)))},e)))})})},F=()=>{const{duration:e}=(0,m.useSelect)((e=>({duration:e("gatherpress/datetime").getDuration()})),[]),t=(0,m.useDispatch)(),{setDateTimeEnd:r,setDuration:n}=t("gatherpress/datetime");return(0,v.jsx)(c.SelectControl,{label:(0,l.__)("Duration","gatherpress"),value:!!D.some((t=>t.value===e))&&e,options:D,onChange:e=>{(e="false"!==e&&parseFloat(e))&&r(j(e)),n(e)},__nexthasnomarginbottom:!0})},M=()=>{const e=(0,m.useDispatch)("core/editor").editPost;let t=(0,m.useSelect)((e=>e("core/editor").getEditedPostAttribute("meta")?.gatherpress_datetime));try{t=t?JSON.parse(t):{}}catch(e){t={}}const{dateTimeStart:r,dateTimeEnd:n,duration:a,timezone:i}=(0,m.useSelect)((e=>({dateTimeStart:e("gatherpress/datetime").getDateTimeStart(),dateTimeEnd:e("gatherpress/datetime").getDateTimeEnd(),duration:e("gatherpress/datetime").getDuration(),timezone:e("gatherpress/datetime").getTimezone()})),[]),{setDuration:o}=(0,m.useDispatch)("gatherpress/datetime");return(0,u.useEffect)((()=>{const a=JSON.stringify({...t,dateTimeStart:s().tz(r,i).format(_),dateTimeEnd:s().tz(n,i).format(_),timezone:i});e({meta:{gatherpress_datetime:a}})}),[r,n,i,t,e,o,a]),(0,v.jsxs)(v.Fragment,{children:[(0,v.jsx)("section",{children:(0,v.jsx)(O,{})}),(0,v.jsx)("section",{children:a?(0,v.jsx)(F,{}):(0,v.jsx)(E,{})}),(0,v.jsx)("section",{children:(0,v.jsx)(P,{})})]})},Y=(e,t,r)=>{const n=k(p("settings.dateFormat")),a=k(p("settings.timeFormat")),i=p("settings.showTimezone")?"z":"",o=n+" "+a;r=b(r);let d=n+" "+a+" "+i;return s().tz(e,r).format(n)===s().tz(t,r).format(n)&&(d=a+" "+i),(0,l.sprintf)(/* translators: %1$s: datetime start, %2$s: datetime end, %3$s timezone. */ /* translators: %1$s: datetime start, %2$s: datetime end, %3$s timezone. */ -(0,l.__)("%1$s to %2$s %3$s","gatherpress"),s().tz(e,r).format(o),s().tz(t,r).format(d),function(e){return e=b(e),(0,l.__)("GMT","gatherpress")!==e?"":function(e=""){return e.replace(":","")}(p("eventDetails.dateTime.timezone"))}(r))},$=JSON.parse('{"$schema":"https://schemas.wp.org/trunk/block.json","apiVersion":3,"name":"gatherpress/event-date","version":"2.0.0","title":"Event Date","category":"gatherpress","icon":"clock","example":{"viewportWidth":350},"description":"Displays the date and time for an event.","attributes":{"eventEnd":{"type":"string"},"eventStart":{"type":"string"},"textAlign":{"type":"string"}},"supports":{"html":false,"color":{"gradients":true,"link":true,"__experimentalDefaultControls":{"background":true,"text":true,"link":true}},"spacing":{"margin":true,"padding":true},"typography":{"fontSize":true,"lineHeight":true,"__experimentalFontFamily":true,"__experimentalFontWeight":true,"__experimentalFontStyle":true,"__experimentalTextTransform":true,"__experimentalTextDecoration":true,"__experimentalLetterSpacing":true,"__experimentalDefaultControls":{"fontSize":true}},"interactivity":{"clientNavigation":true},"__experimentalBorder":{"radius":true,"color":true,"width":true,"style":true,"__experimentalDefaultControls":{"radius":true,"color":true,"width":true,"style":true}}},"textdomain":"gatherpress","editorScript":"file:./index.js","style":"file:./style-index.css","render":"file:./render.php"}');(0,n.registerBlockType)($,{edit:({attributes:{textAlign:e},setAttributes:t})=>{const r=(0,d.useBlockProps)({className:o({[`has-text-align-${e}`]:e})}),{dateTimeStart:n,dateTimeEnd:a,timezone:s}=(0,m.useSelect)((e=>({dateTimeStart:e("gatherpress/datetime").getDateTimeStart(),dateTimeEnd:e("gatherpress/datetime").getDateTimeEnd(),timezone:e("gatherpress/datetime").getTimezone()})),[]);return(0,v.jsxs)("div",{...r,children:[(0,v.jsx)(d.BlockControls,{children:(0,v.jsx)(d.AlignmentToolbar,{value:e,onChange:e=>t({textAlign:e})})}),Y(n,a,s),f()&&(0,v.jsx)(d.InspectorControls,{children:(0,v.jsx)(c.PanelBody,{children:(0,v.jsx)(c.__experimentalVStack,{spacing:4,children:(0,v.jsx)(M,{})})})})]})},save:()=>null})}},r={};function n(e){var a=r[e];if(void 0!==a)return a.exports;var s=r[e]={exports:{}};return t[e](s,s.exports,n),s.exports}n.m=t,e=[],n.O=(t,r,a,s)=>{if(!r){var i=1/0;for(c=0;c=s)&&Object.keys(n.O).every((e=>n.O[e](r[l])))?r.splice(l--,1):(o=!1,s0&&e[c-1][2]>s;c--)e[c]=e[c-1];e[c]=[r,a,s]},n.n=e=>{var t=e&&e.__esModule?()=>e.default:()=>e;return n.d(t,{a:t}),t},n.d=(e,t)=>{for(var r in t)n.o(t,r)&&!n.o(e,r)&&Object.defineProperty(e,r,{enumerable:!0,get:t[r]})},n.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),(()=>{var e={1532:0,6004:0};n.O.j=t=>0===e[t];var t=(t,r)=>{var a,s,[i,o,l]=r,d=0;if(i.some((t=>0!==e[t]))){for(a in o)n.o(o,a)&&(n.m[a]=o[a]);if(l)var c=l(n)}for(t&&t(r);dn(4034)));a=n.O(a)})(); \ No newline at end of file +(()=>{"use strict";var e,t={4034:(e,t,r)=>{const n=window.wp.blocks,a=window.moment;var s=r.n(a);function i(e){var t,r,n="";if("string"==typeof e||"number"==typeof e)n+=e;else if("object"==typeof e)if(Array.isArray(e)){var a=e.length;for(t=0;te&&e[t]),GatherPress)}function h(e,t){if("object"!=typeof GatherPress)return;const r=e.split("."),n=r.pop();r.reduce(((e,t)=>{var r;return null!==(r=e[t])&&void 0!==r?r:e[t]={}}),GatherPress)[n]=t}function g(){(0,u.dispatch)("core/editor")?.editPost({meta:{_non_existing_meta:!0}})}function f(){const e=(0,u.select)("core/editor")?.getCurrentPostType();return"gatherpress_event"===e||"gatherpress_venue"===e}const x=window.wp.date,v=window.ReactJSXRuntime,_="YYYY-MM-DD HH:mm:ss",T=s().tz(b()).add(1,"day").set("hour",18).set("minute",0).set("second",0).format(_),D=(s().tz(T,b()).add(2,"hours").format(_),[{label:(0,l.__)("1 hour","gatherpress"),value:1},{label:(0,l.__)("1.5 hours","gatherpress"),value:1.5},{label:(0,l.__)("2 hours","gatherpress"),value:2},{label:(0,l.__)("3 hours","gatherpress"),value:3},{label:(0,l.__)("Set an end time…","gatherpress"),value:!1}]);function j(e){return s().tz(function(){let e=p("eventDetails.dateTime.datetime_start");return e=""!==e?s().tz(e,b()).format(_):T,h("eventDetails.dateTime.datetime_start",e),e}(),b()).add(e,"hours").format(_)}function z(){return C(p("settings.dateFormat"))+" "+C(p("settings.timeFormat"))}function b(e=p("eventDetails.dateTime.timezone")){return s().tz.zone(e)?e:(0,l.__)("GMT","gatherpress")}function w(e=""){const t=/^([+-])(\d{2}):(00|15|30|45)$/,r=e.replace(t,"$1");return r!==e?"UTC"+r+parseInt(e.replace(t,"$2")).toString()+e.replace(t,"$3").replace("00","").replace("15",".25").replace("30",".5").replace("45",".75"):e}function y(e,t=null,r=null){!function(e,t=null){const r=s().tz(p("eventDetails.dateTime.datetime_end"),b()).valueOf(),n=s().tz(e,b()).valueOf();n>=r&&S(s().tz(n,b()).add(2,"hours").format(_),t)}(e,r),h("eventDetails.dateTime.datetime_start",e),"function"==typeof t&&t(e),g()}function S(e,t=null,r=null){!function(e,t=null){const r=s().tz(p("eventDetails.dateTime.datetime_start"),b()).valueOf(),n=s().tz(e,b()).valueOf();n<=r&&y(s().tz(n,b()).subtract(2,"hours").format(_),t)}(e,r),h("eventDetails.dateTime.datetime_end",e),null!==t&&t(e),g()}function C(e){const t={d:"DD",D:"ddd",j:"D",l:"dddd",N:"E",S:"o",w:"e",z:"DDD",W:"W",F:"MMMM",m:"MM",M:"MMM",n:"M",t:"",L:"",o:"YYYY",Y:"YYYY",y:"YY",a:"a",A:"A",B:"",g:"h",G:"H",h:"hh",H:"HH",i:"mm",s:"ss",u:"SSS",e:"zz",I:"",O:"",P:"",T:"",Z:"",c:"",r:"",U:"X"};return String(e).split("").map(((e,r,n)=>{const a=n[r-1];return e in t&&"\\"!==a?t[e]:e})).join("")}function k(){const e="gatherpress_event_past",t=(0,u.dispatch)("core/notices");t.removeNotice(e),function(){const e=s().tz(p("eventDetails.dateTime.datetime_end"),b());return"gatherpress_event"===(0,u.select)("core/editor")?.getCurrentPostType()&&s().tz(b()).valueOf()>e.valueOf()}()&&t.createNotice("warning",(0,l.__)("This event has already passed.","gatherpress"),{id:e,isDismissible:!1})}const O=()=>{const{dateTimeStart:e,duration:t}=(0,u.useSelect)((e=>({dateTimeStart:e("gatherpress/datetime").getDateTimeStart(),duration:e("gatherpress/datetime").getDuration()})),[]),{setDateTimeStart:r,setDateTimeEnd:n}=(0,u.useDispatch)("gatherpress/datetime"),a=(0,x.getSettings)(),i=/a(?!\\)/i.test(a.formats.time.toLowerCase().replace(/\\\\/g,"").split("").reverse().join(""));return(0,m.useEffect)((()=>{r(s().tz(e,b()).format(_)),t&&n(j(t)),k()}),[e,t,r,n]),(0,v.jsx)(c.PanelRow,{children:(0,v.jsxs)(c.Flex,{direction:"column",gap:"1",children:[(0,v.jsx)(c.FlexItem,{children:(0,v.jsx)("h3",{style:{marginBottom:0},children:(0,v.jsx)("label",{htmlFor:"gatherpress-datetime-start",children:(0,l.__)("Date & time start","gatherpress")})})}),(0,v.jsx)(c.FlexItem,{children:(0,v.jsx)(c.Dropdown,{popoverProps:{placement:"bottom-end"},renderToggle:({isOpen:t,onToggle:r})=>(0,v.jsx)(c.Button,{id:"gatherpress-datetime-start",onClick:r,"aria-expanded":t,isLink:!0,children:s().tz(e,b()).format(z())}),renderContent:()=>(0,v.jsx)(c.DateTimePicker,{currentDate:e,onChange:e=>{y(e,r,n)},is12Hour:i})})})]})})},E=()=>{const{dateTimeEnd:e}=(0,u.useSelect)((e=>({dateTimeEnd:e("gatherpress/datetime").getDateTimeEnd()})),[]),{setDateTimeEnd:t,setDateTimeStart:r}=(0,u.useDispatch)("gatherpress/datetime"),n=(0,x.getSettings)(),a=/a(?!\\)/i.test(n.formats.time.toLowerCase().replace(/\\\\/g,"").split("").reverse().join(""));return(0,m.useEffect)((()=>{t(s().tz(e,b()).format(_)),k()})),(0,v.jsx)(c.PanelRow,{children:(0,v.jsxs)(c.Flex,{direction:"column",gap:"1",children:[(0,v.jsx)(c.FlexItem,{children:(0,v.jsx)("h3",{style:{marginBottom:0},children:(0,v.jsx)("label",{htmlFor:"gatherpress-datetime-end",children:(0,l.__)("Date & time end","gatherpress")})})}),(0,v.jsx)(c.FlexItem,{children:(0,v.jsx)(c.Dropdown,{popoverProps:{placement:"bottom-end"},renderToggle:({isOpen:t,onToggle:r})=>(0,v.jsx)(c.Button,{id:"gatherpress-datetime-end",onClick:r,"aria-expanded":t,isLink:!0,children:s().tz(e,b()).format(z())}),renderContent:()=>(0,v.jsx)(c.DateTimePicker,{currentDate:e,onChange:e=>S(e,t,r),is12Hour:a})})})]})})},P=()=>{const{timezone:e}=(0,u.useSelect)((e=>({timezone:e("gatherpress/datetime").getTimezone()})),[]),{setTimezone:t}=(0,u.useDispatch)("gatherpress/datetime"),r=p("misc.timezoneChoices");return(0,m.useEffect)((()=>{t(p("eventDetails.dateTime.timezone"))}),[t]),(0,v.jsx)(c.PanelRow,{children:(0,v.jsx)(c.SelectControl,{label:(0,l.__)("Time Zone","gatherpress"),value:w(e),onChange:e=>{e=function(e=""){const t=/^UTC([+-])(\d+)(.\d+)?$/,r=e.replace(t,"$1");if(r!==e){const n=e.replace(t,"$2").padStart(2,"0");let a=e.replace(t,"$3");return""===a&&(a=":00"),a=a.replace(".25",":15").replace(".5",":30").replace(".75",":45"),r+n+a}return e}(e),t(e),g()},__nexthasnomarginbottom:!0,children:Object.keys(r).map((e=>(0,v.jsx)("optgroup",{label:e,children:Object.keys(r[e]).map((t=>(0,v.jsx)("option",{value:t,children:r[e][t]},t)))},e)))})})},F=()=>{const{duration:e}=(0,u.useSelect)((e=>({duration:e("gatherpress/datetime").getDuration()})),[]),t=(0,u.useDispatch)(),{setDateTimeEnd:r,setDuration:n}=t("gatherpress/datetime");return(0,v.jsx)(c.SelectControl,{label:(0,l.__)("Duration","gatherpress"),value:!!D.some((t=>t.value===e))&&e,options:D,onChange:e=>{(e="false"!==e&&parseFloat(e))&&r(j(e)),n(e)},__nexthasnomarginbottom:!0})},M=()=>{const e=(0,u.useDispatch)("core/editor").editPost;let t=(0,u.useSelect)((e=>e("core/editor").getEditedPostAttribute("meta")?.gatherpress_datetime));try{t=t?JSON.parse(t):{}}catch(e){t={}}const{dateTimeStart:r,dateTimeEnd:n,duration:a,timezone:i}=(0,u.useSelect)((e=>({dateTimeStart:e("gatherpress/datetime").getDateTimeStart(),dateTimeEnd:e("gatherpress/datetime").getDateTimeEnd(),duration:e("gatherpress/datetime").getDuration(),timezone:e("gatherpress/datetime").getTimezone()})),[]),{setDuration:o}=(0,u.useDispatch)("gatherpress/datetime");return(0,m.useEffect)((()=>{const a=JSON.stringify({...t,dateTimeStart:s().tz(r,i).format(_),dateTimeEnd:s().tz(n,i).format(_),timezone:i});e({meta:{gatherpress_datetime:a}})}),[r,n,i,t,e,o,a]),(0,v.jsxs)(v.Fragment,{children:[(0,v.jsx)("section",{children:(0,v.jsx)(O,{})}),(0,v.jsx)("section",{children:a?(0,v.jsx)(F,{}):(0,v.jsx)(E,{})}),(0,v.jsx)("section",{children:(0,v.jsx)(P,{})})]})},Y=(e,t,r)=>{const n=C(p("settings.dateFormat")),a=C(p("settings.timeFormat")),i=p("settings.showTimezone")?"z":"",o=n+" "+a;r=b(r);let d=n+" "+a+" "+i;return s().tz(e,r).format(n)===s().tz(t,r).format(n)&&(d=a+" "+i),(0,l.sprintf)(/* translators: %1$s: datetime start, %2$s: datetime end, %3$s timezone. */ /* translators: %1$s: datetime start, %2$s: datetime end, %3$s timezone. */ +(0,l.__)("%1$s to %2$s %3$s","gatherpress"),s().tz(e,r).format(o),s().tz(t,r).format(d),function(e){return e=b(e),(0,l.__)("GMT","gatherpress")!==e?"":function(e=""){return e.replace(":","")}(p("eventDetails.dateTime.timezone"))}(r))},$=JSON.parse('{"$schema":"https://schemas.wp.org/trunk/block.json","apiVersion":3,"name":"gatherpress/event-date","version":"2.0.0","title":"Event Date","category":"gatherpress","icon":"clock","example":{"viewportWidth":350},"description":"Displays the date and time for an event.","usesContext":["postId","queryId"],"attributes":{"postId":{"type":"number"},"eventEnd":{"type":"string"},"eventStart":{"type":"string"},"textAlign":{"type":"string"}},"supports":{"html":false,"color":{"gradients":true,"link":true,"__experimentalDefaultControls":{"background":true,"text":true,"link":true}},"spacing":{"margin":true,"padding":true},"typography":{"fontSize":true,"lineHeight":true,"__experimentalFontFamily":true,"__experimentalFontWeight":true,"__experimentalFontStyle":true,"__experimentalTextTransform":true,"__experimentalTextDecoration":true,"__experimentalLetterSpacing":true,"__experimentalDefaultControls":{"fontSize":true}},"interactivity":{"clientNavigation":true},"__experimentalBorder":{"radius":true,"color":true,"width":true,"style":true,"__experimentalDefaultControls":{"radius":true,"color":true,"width":true,"style":true}}},"textdomain":"gatherpress","editorScript":"file:./index.js","style":"file:./style-index.css","render":"file:./render.php"}');(0,n.registerBlockType)($,{edit:({attributes:{textAlign:e},setAttributes:t})=>{const r=(0,d.useBlockProps)({className:o({[`has-text-align-${e}`]:e})}),{dateTimeStart:n,dateTimeEnd:a,timezone:s}=(0,u.useSelect)((e=>({dateTimeStart:e("gatherpress/datetime").getDateTimeStart(),dateTimeEnd:e("gatherpress/datetime").getDateTimeEnd(),timezone:e("gatherpress/datetime").getTimezone()})),[]);return(0,v.jsxs)("div",{...r,children:[(0,v.jsx)(d.BlockControls,{children:(0,v.jsx)(d.AlignmentToolbar,{value:e,onChange:e=>t({textAlign:e})})}),Y(n,a,s),f()&&(0,v.jsx)(d.InspectorControls,{children:(0,v.jsx)(c.PanelBody,{children:(0,v.jsx)(c.__experimentalVStack,{spacing:4,children:(0,v.jsx)(M,{})})})})]})},save:()=>null})}},r={};function n(e){var a=r[e];if(void 0!==a)return a.exports;var s=r[e]={exports:{}};return t[e](s,s.exports,n),s.exports}n.m=t,e=[],n.O=(t,r,a,s)=>{if(!r){var i=1/0;for(c=0;c=s)&&Object.keys(n.O).every((e=>n.O[e](r[l])))?r.splice(l--,1):(o=!1,s0&&e[c-1][2]>s;c--)e[c]=e[c-1];e[c]=[r,a,s]},n.n=e=>{var t=e&&e.__esModule?()=>e.default:()=>e;return n.d(t,{a:t}),t},n.d=(e,t)=>{for(var r in t)n.o(t,r)&&!n.o(e,r)&&Object.defineProperty(e,r,{enumerable:!0,get:t[r]})},n.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),(()=>{var e={1532:0,6004:0};n.O.j=t=>0===e[t];var t=(t,r)=>{var a,s,[i,o,l]=r,d=0;if(i.some((t=>0!==e[t]))){for(a in o)n.o(o,a)&&(n.m[a]=o[a]);if(l)var c=l(n)}for(t&&t(r);dn(4034)));a=n.O(a)})(); \ No newline at end of file diff --git a/build/blocks/rsvp-response-v2/block.json b/build/blocks/rsvp-response-v2/block.json index 7d27ac4e6..e3158c1a7 100644 --- a/build/blocks/rsvp-response-v2/block.json +++ b/build/blocks/rsvp-response-v2/block.json @@ -8,7 +8,15 @@ "icon": "groups", "example": {}, "description": "Displays a list of members who have confirmed their attendance for an event.", - "attributes": {}, + "attributes": { + "postId": { + "type": "number" + } + }, + "usesContext": [ + "postId", + "queryId" + ], "supports": { "align": [ "wide", diff --git a/build/blocks/rsvp-response-v2/index.asset.php b/build/blocks/rsvp-response-v2/index.asset.php index 55916734e..e7f6d1095 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' => 'b27e09d5e2c12ce3efde'); + array('react-jsx-runtime', 'wp-api-fetch', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-core-data', 'wp-data', 'wp-element', 'wp-i18n'), 'version' => '547942bbde24e852c540'); diff --git a/build/blocks/rsvp-response-v2/index.js b/build/blocks/rsvp-response-v2/index.js index 750a37684..b5afabeca 100644 --- a/build/blocks/rsvp-response-v2/index.js +++ b/build/blocks/rsvp-response-v2/index.js @@ -1,20 +1,20 @@ -(()=>{"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.data,l=window.wp.apiFetch;var d=s.n(l);const 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"),[l,h]=(0,i.useState)(r),m=l[e].responses,{userList:v}=(0,p.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:{},w=(e,t="attending")=>{d()({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]&&w(f[t].id,e)})):m.forEach((e=>{!1===t.some((t=>t.id===e.id))&&w(e.id,"no_status")}))},suggestions:Object.keys(f),maxSuggestions:20},"query-controls-topics-select")]})},m=[["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", +(()=>{"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,l=window.wp.data,p=window.wp.apiFetch;var d=s.n(p);const c=window.wp.coreData;function u(e){if("object"==typeof GatherPress)return e.split(".").reduce(((e,t)=>e&&e[t]),GatherPress)}const h=window.ReactJSXRuntime,g=({defaultStatus:e,setDefaultStatus:t})=>{var s;const r=u("eventDetails.responses"),n=u("eventDetails.postId"),[p,g]=(0,i.useState)(r),v=p[e].responses,{userList:m}=(0,l.useSelect)((e=>{const{getEntityRecords:t}=e(c.store);return{userList:t("root","user",{per_page:-1})}}),[]),f=null!==(s=m?.reduce(((e,t)=>({...e,[t.username]:t})),{}))&&void 0!==s?s:{},w=(e,t="attending")=>{d()({path:u("urls.eventApiPath")+"/rsvp",method:"POST",data:{post_id:n,status:t,user_id:e,_wpnonce:u("misc.nonce")}}).then((e=>{g(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,h.jsxs)(h.Fragment,{children:[(0,h.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,h.jsx)(o.FormTokenField,{label:(0,a.__)("Members","gatherpress"),value:v&&v.map((e=>({id:e.id,value:e.name}))),tokenizeOnSpace:!0,onChange:async t=>{t.length>v.length?t.forEach((t=>{f[t]&&w(f[t].id,e)})):v.forEach((e=>{!1===t.some((t=>t.id===e.id))&&w(e.id,"no_status")}))},suggestions:Object.keys(f),maxSuggestions:20},"query-controls-topics-select")]})},v=[["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", // Translators: %d is the count of attendees. -label:(0,n.__)("Attending (%d)","gatherpress"),metadata:{ +label:(0,a.__)("Attending (%d)","gatherpress"),metadata:{ // Translators: %d is the count of attendees. -name:(0,n.__)("Attending (%d)","gatherpress")}},[["gatherpress/dropdown-item",{text:''+ +name:(0,a.__)("Attending (%d)","gatherpress")}},[["gatherpress/dropdown-item",{text:''+ // Translators: %d is the count of attendees. // Translators: %d is the count of attendees. -(0,n.__)("Attending (%d)","gatherpress")+"",metadata:{ +(0,a.__)("Attending (%d)","gatherpress")+"",metadata:{ // Translators: %d is the count of attendees. -name:(0,n.__)("Attending (%d)","gatherpress")},className:"gatherpress--rsvp-attending"}],["gatherpress/dropdown-item",{text:''+ +name:(0,a.__)("Attending (%d)","gatherpress")},className:"gatherpress--rsvp-attending"}],["gatherpress/dropdown-item",{text:''+ // Translators: %d is the count of users on the waiting list. // Translators: %d is the count of users on the waiting list. -(0,n.__)("Waiting List (%d)","gatherpress")+"",metadata:{ +(0,a.__)("Waiting List (%d)","gatherpress")+"",metadata:{ // Translators: %d is the count of users on the waiting list. -name:(0,n.__)("Waiting List (%d)","gatherpress")},className:"gatherpress--rsvp-waiting-list"}],["gatherpress/dropdown-item",{text:''+ +name:(0,a.__)("Waiting List (%d)","gatherpress")},className:"gatherpress--rsvp-waiting-list"}],["gatherpress/dropdown-item",{text:''+ // Translators: %d is the count of users not attending. // Translators: %d is the count of users not attending. -(0,n.__)("Not Attending (%d)","gatherpress")+"",metadata:{ +(0,a.__)("Not Attending (%d)","gatherpress")+"",metadata:{ // Translators: %d is the count of users not attending. -name:(0,n.__)("Not Attending (%d)","gatherpress")},className:"gatherpress--rsvp-not-attending"}]]]]],["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"},[["core/paragraph",{content:(0,n.__)("No one is attending this event yet.","gatherpress")}]]]],v=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.","attributes":{},"supports":{"align":["wide","full"],"interactivity":true,"html":false},"providesContext":{"commentId":"commentId"},"textdomain":"gatherpress","editorScript":"file:./index.js","style":"file:./style-index.css","viewScriptModule":"file:./view.js"}');(0,r.registerBlockType)(v,{edit:({clientId:e})=>{const t=(0,a.useBlockProps)(),[r,l]=(0,i.useState)(!1),[d,c]=(0,i.useState)(!1),[g,v]=(0,i.useState)("attending"),f=(0,p.useSelect)((t=>t("core/block-editor").getBlocks(e)),[e]);return(0,i.useEffect)((()=>{f.forEach((e=>{const t=s.g.document.getElementById(`block-${e.clientId}`);if(t){const s=e.attributes?.className?.includes("gatherpress--rsvp-responses"),r=e.attributes?.className?.includes("gatherpress--empty-rsvp");d&&r?t.style.display="":d&&s||!d&&r?t.style.display="none":!d&&s&&(t.style.display="")}}))}),[d,f,r]),(0,u.jsxs)("div",{...t,children:[(0,u.jsx)(a.InspectorControls,{children:(0,u.jsx)(o.PanelBody,{children:(0,u.jsx)(o.ToggleControl,{label:(0,n.__)("Show Empty RSVP Block","gatherpress"),checked:d,onChange:e=>c(e),help:(0,n.__)("Toggle to show or hide the Empty RSVP block.","gatherpress")})})}),(0,u.jsx)(a.BlockControls,{children:(0,u.jsx)(o.ToolbarGroup,{children:(0,u.jsx)(o.ToolbarButton,{label:(0,n.__)("Edit","gatherpress"),text:r?(0,n.__)("Preview","gatherpress"):(0,n.__)("Edit","gatherpress"),onClick:e=>{e.preventDefault(),l(!r)}})})}),r&&(0,u.jsx)(h,{defaultStatus:g,setDefaultStatus:v}),!r&&(0,u.jsx)(a.InnerBlocks,{template:m})]})},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.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 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 +name:(0,a.__)("Not Attending (%d)","gatherpress")},className:"gatherpress--rsvp-not-attending"}]]]]],["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"},[["core/paragraph",{content:(0,a.__)("No one is attending this event yet.","gatherpress")}]]]],m=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.","attributes":{"postId":{"type":"number"}},"usesContext":["postId","queryId"],"supports":{"align":["wide","full"],"interactivity":true,"html":false},"providesContext":{"commentId":"commentId"},"textdomain":"gatherpress","editorScript":"file:./index.js","style":"file:./style-index.css","viewScriptModule":"file:./view.js"}');(0,r.registerBlockType)(m,{edit:({clientId:e,context:t})=>{var r;const p=(0,n.useBlockProps)(),[d,c]=(0,i.useState)(!1),[m,f]=(0,i.useState)(!1),[w,_]=(0,i.useState)("attending"),[b,y]=(0,i.useState)(null),[x,S]=(0,i.useState)(!0),[j,k]=(0,i.useState)(null),P=null!==(r=t?.postId)&&void 0!==r?r:null,{updateBlockAttributes:C}=(0,l.useDispatch)("core/block-editor"),E=(0,l.useSelect)((t=>t("core/block-editor").getBlocks(e)),[e]);return(0,i.useEffect)((()=>{E.forEach((e=>{const t=s.g.document.getElementById(`block-${e.clientId}`);if(t){const s=e.attributes?.className?.includes("gatherpress--rsvp-responses"),r=e.attributes?.className?.includes("gatherpress--empty-rsvp");m&&r?t.style.display="":m&&s||!m&&r?t.style.display="none":!m&&s&&(t.style.display="")}}))}),[m,E,d]),(0,i.useEffect)((()=>{if(!P)return y(null),void S(!1);S(!0),k(null),async function(e){const t=u("urls.eventApiUrl"),s=await fetch(`${t}/rsvp-responses?post_id=${e}`);if(!s.ok)throw new Error("Failed to fetch RSVP responses");return s.json()}(P).then((e=>{y(e.data),S(!1)})).catch((e=>{k(e.message),S(!1)}))}),[P]),x?(0,h.jsx)("div",{...p,children:(0,h.jsx)(o.Spinner,{})}):j?(0,h.jsx)("div",{...p,children:(0,h.jsx)("p",{children:(0,a.__)("Failed to load RSVP responses.","gatherpress")})}):(0,h.jsx)("div",{...p,children:(0,h.jsxs)(n.BlockContextProvider,{value:{"gatherpress/rsvpResponses":b},children:[(0,h.jsx)(n.InspectorControls,{children:(0,h.jsx)(o.PanelBody,{children:(0,h.jsx)(o.ToggleControl,{label:(0,a.__)("Show Empty RSVP Block","gatherpress"),checked:m,onChange:e=>f(e),help:(0,a.__)("Toggle to show or hide the Empty RSVP block.","gatherpress")})})}),(0,h.jsx)(n.BlockControls,{children:(0,h.jsx)(o.ToolbarGroup,{children:(0,h.jsx)(o.ToolbarButton,{label:(0,a.__)("Edit","gatherpress"),text:d?(0,a.__)("Preview","gatherpress"):(0,a.__)("Edit","gatherpress"),onClick:e=>{e.preventDefault(),c(!d)}})})}),d&&(0,h.jsx)(g,{defaultStatus:w,setDefaultStatus:_}),!d&&(0,h.jsx)(n.InnerBlocks,{template:v})]})})},save:()=>(0,h.jsx)("div",{...n.useBlockProps.save(),children:(0,h.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[l])))?s.splice(l--,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,l]=s,p=0;if(o.some((t=>0!==e[t]))){for(n in i)r.o(i,n)&&(r.m[n]=i[n]);if(l)var d=l(r)}for(t&&t(s);pr(8392)));n=r.O(n)})(); \ No newline at end of file diff --git a/build/blocks/rsvp-template/block.json b/build/blocks/rsvp-template/block.json index 496e3fab1..83909d0d9 100644 --- a/build/blocks/rsvp-template/block.json +++ b/build/blocks/rsvp-template/block.json @@ -11,6 +11,9 @@ "supports": { "html": false }, + "usesContext": [ + "gatherpress/rsvpResponses" + ], "parent": [ "core/group" ], diff --git a/build/blocks/rsvp-template/index.asset.php b/build/blocks/rsvp-template/index.asset.php index 7019e31fe..137dc540b 100644 --- a/build/blocks/rsvp-template/index.asset.php +++ b/build/blocks/rsvp-template/index.asset.php @@ -1 +1 @@ - array('react-jsx-runtime', 'wp-block-editor', 'wp-blocks', 'wp-data', 'wp-element', 'wp-i18n'), 'version' => '43d10fcaeec09be5e280'); + array('react-jsx-runtime', 'wp-block-editor', 'wp-blocks', 'wp-data', 'wp-element', 'wp-i18n'), 'version' => 'c470b3df551482840cc4'); diff --git a/build/blocks/rsvp-template/index.js b/build/blocks/rsvp-template/index.js index 7caf2735d..14d90f343 100644 --- a/build/blocks/rsvp-template/index.js +++ b/build/blocks/rsvp-template/index.js @@ -1 +1 @@ -(()=>{"use strict";var e,s={2630:()=>{const e=window.wp.blocks,s=window.wp.blockEditor,t=window.wp.data,n=window.wp.element,o=[["core/group",{style:{spacing:{blockGap:0}}},[["core/avatar",{isLink:!0,align:"center"}],["core/comment-author-name",{metadata:{name:(0,window.wp.i18n.__)("Display Name","gatherpress")},textAlign:"center",style:{spacing:{margin:{top:"0",bottom:"0"}}},fontSize:"medium"}],["gatherpress/rsvp-guest-count-display",{align:"center",style:{spacing:{margin:{top:"0",bottom:"0"}}},fontSize:"small"}]]]],r=window.ReactJSXRuntime,i=({response:e,blocks:t,activeRsvpId:n,setActiveRsvpId:i,firstRsvpId:l})=>{const{children:a,...p}=(0,s.useInnerBlocksProps)({},{template:o});return(0,r.jsxs)("div",{...p,children:[e.commentId===(n||l)?a:null,(0,r.jsx)(c,{blocks:t,commentId:e.commentId,setActiveRsvpId:i,isHidden:e.commentId===(n||l)})]})},c=(0,n.memo)((({blocks:e,commentId:t,setActiveRsvpId:n,isHidden:o})=>{const i=(0,s.__experimentalUseBlockPreview)({blocks:e}),c=()=>{n(t)},l={display:o?"none":void 0};return(0,r.jsx)("div",{...i,tabIndex:0,role:"button",style:l,onClick:c,onKeyPress:c})})),l=({responses:e,blocks:t,blockProps:n,activeRsvpId:o,setActiveRsvpId:c,firstRsvpId:l})=>(0,r.jsx)(r.Fragment,{children:e&&e.map((({commentId:e,...a},p)=>{const d=parseInt(e,10);return(0,r.jsx)(s.BlockContextProvider,{value:{commentId:d<0?null:d},children:(0,r.jsx)(i,{response:{commentId:d,...a},blockProps:n,blocks:t,activeRsvpId:o,setActiveRsvpId:c,firstRsvpId:l})},d||p)}))});(0,e.registerBlockType)("gatherpress/rsvp-template",{edit:({clientId:e})=>{var o;const i=(0,s.useBlockProps)(),c=function(){if("object"==typeof GatherPress)return"eventDetails.responses".split(".").reduce(((e,s)=>e&&e[s]),GatherPress)}(),[a,p]=(0,n.useState)(null!==(o=parseInt(c.attending.responses[0]?.commentId,10))&&void 0!==o?o:null),{blocks:d}=(0,t.useSelect)((t=>{const{getBlocks:n}=t(s.store);return{blocks:n(e)}}),[e]);let v=[{commentId:-1}];return c.attending.responses.length&&(v=c.attending.responses),(0,r.jsx)(l,{responses:v,blockProps:i,blocks:d,activeRsvpId:a,setActiveRsvpId:p,firstRsvpId:v[0]?.commentId})},save:()=>(0,r.jsx)(s.InnerBlocks.Content,{})})}},t={};function n(e){var o=t[e];if(void 0!==o)return o.exports;var r=t[e]={exports:{}};return s[e](r,r.exports,n),r.exports}n.m=s,e=[],n.O=(s,t,o,r)=>{if(!t){var i=1/0;for(p=0;p=r)&&Object.keys(n.O).every((e=>n.O[e](t[l])))?t.splice(l--,1):(c=!1,r0&&e[p-1][2]>r;p--)e[p]=e[p-1];e[p]=[t,o,r]},n.o=(e,s)=>Object.prototype.hasOwnProperty.call(e,s),(()=>{var e={2687:0,4967:0};n.O.j=s=>0===e[s];var s=(s,t)=>{var o,r,[i,c,l]=t,a=0;if(i.some((s=>0!==e[s]))){for(o in c)n.o(c,o)&&(n.m[o]=c[o]);if(l)var p=l(n)}for(s&&s(t);an(2630)));o=n.O(o)})(); \ No newline at end of file +(()=>{"use strict";var e,s={6572:()=>{const e=window.wp.blocks,s=window.wp.blockEditor,t=window.wp.data,o=window.wp.element,n=[["core/group",{style:{spacing:{blockGap:0}}},[["core/avatar",{isLink:!0,align:"center"}],["core/comment-author-name",{metadata:{name:(0,window.wp.i18n.__)("Display Name","gatherpress")},textAlign:"center",style:{spacing:{margin:{top:"0",bottom:"0"}}},fontSize:"medium"}],["gatherpress/rsvp-guest-count-display",{align:"center",style:{spacing:{margin:{top:"0",bottom:"0"}}},fontSize:"small"}]]]],r=window.ReactJSXRuntime,c=({response:e,blocks:t,activeRsvpId:o,setActiveRsvpId:c,firstRsvpId:i})=>{const{children:p,...a}=(0,s.useInnerBlocksProps)({},{template:n});return(0,r.jsxs)("div",{...a,children:[e.commentId===(o||i)?p:null,(0,r.jsx)(l,{blocks:t,commentId:e.commentId,setActiveRsvpId:c,isHidden:e.commentId===(o||i)})]})},l=(0,o.memo)((({blocks:e,commentId:t,setActiveRsvpId:o,isHidden:n})=>{const c=(0,s.__experimentalUseBlockPreview)({blocks:e}),l=()=>{o(t)},i={display:n?"none":void 0};return(0,r.jsx)("div",{...c,tabIndex:0,role:"button",style:i,onClick:l,onKeyPress:l})})),i=({responses:e,blocks:t,blockProps:o,activeRsvpId:n,setActiveRsvpId:l,firstRsvpId:i})=>(0,r.jsx)(r.Fragment,{children:e&&e.map((({commentId:e,...p},a)=>{const d=parseInt(e,10);return(0,r.jsx)(s.BlockContextProvider,{value:{commentId:d<0?null:d},children:(0,r.jsx)(c,{response:{commentId:d,...p},blockProps:o,blocks:t,activeRsvpId:n,setActiveRsvpId:l,firstRsvpId:i})},d||a)}))});(0,e.registerBlockType)("gatherpress/rsvp-template",{edit:({clientId:e,context:n})=>{var c,l;const p=(0,s.useBlockProps)(),a=null!==(c=n?.["gatherpress/rsvpResponses"])&&void 0!==c?c:null;console.log("Context:",n),console.log("RSVP Responses:",a);const[d,v]=(0,o.useState)(null!==(l=parseInt(a?.attending?.records?.[0]?.commentId,10))&&void 0!==l?l:null),{blocks:m}=(0,t.useSelect)((t=>{const{getBlocks:o}=t(s.store);return{blocks:o(e)}}),[e]);let u=[{commentId:-1}];return a?.attending?.responses?.length&&(u=a.attending.responses),(0,r.jsx)(i,{responses:u,blockProps:p,blocks:m,activeRsvpId:d,setActiveRsvpId:v,firstRsvpId:u[0]?.commentId})},save:()=>(0,r.jsx)(s.InnerBlocks.Content,{})})}},t={};function o(e){var n=t[e];if(void 0!==n)return n.exports;var r=t[e]={exports:{}};return s[e](r,r.exports,o),r.exports}o.m=s,e=[],o.O=(s,t,n,r)=>{if(!t){var c=1/0;for(a=0;a=r)&&Object.keys(o.O).every((e=>o.O[e](t[i])))?t.splice(i--,1):(l=!1,r0&&e[a-1][2]>r;a--)e[a]=e[a-1];e[a]=[t,n,r]},o.o=(e,s)=>Object.prototype.hasOwnProperty.call(e,s),(()=>{var e={2687:0,4967:0};o.O.j=s=>0===e[s];var s=(s,t)=>{var n,r,[c,l,i]=t,p=0;if(c.some((s=>0!==e[s]))){for(n in l)o.o(l,n)&&(o.m[n]=l[n]);if(i)var a=i(o)}for(s&&s(t);po(6572)));n=o.O(n)})(); \ No newline at end of file diff --git a/build/blocks/rsvp-v2/block.json b/build/blocks/rsvp-v2/block.json index cf674791b..8ca77eb52 100644 --- a/build/blocks/rsvp-v2/block.json +++ b/build/blocks/rsvp-v2/block.json @@ -8,7 +8,14 @@ "icon": "insert", "example": {}, "description": "Enables members to easily confirm their attendance for an event.", + "usesContext": [ + "postId", + "queryId" + ], "attributes": { + "postId": { + "type": "number" + }, "serializedInnerBlocks": { "type": "string", "default": "[]" diff --git a/build/blocks/rsvp-v2/index.asset.php b/build/blocks/rsvp-v2/index.asset.php index 746d8d922..759c6bd50 100644 --- a/build/blocks/rsvp-v2/index.asset.php +++ b/build/blocks/rsvp-v2/index.asset.php @@ -1 +1 @@ - array('react-jsx-runtime', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-data', 'wp-element', 'wp-i18n'), 'version' => '16994ed3407a612a23f5'); + array('react-jsx-runtime', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-data', 'wp-element', 'wp-i18n'), 'version' => '0ee72acf7df38c6627c3'); diff --git a/build/blocks/rsvp-v2/index.js b/build/blocks/rsvp-v2/index.js index 5e25b3039..5c3dfefc9 100644 --- a/build/blocks/rsvp-v2/index.js +++ b/build/blocks/rsvp-v2/index.js @@ -1,3 +1,3 @@ (()=>{"use strict";var e,t={546:()=>{const e=window.wp.blocks,t=window.wp.blockEditor,s=window.wp.components,a=window.wp.i18n,r=window.wp.element,n=window.wp.data,o=[["gatherpress/modal-manager",{style:{spacing:{blockGap:"var:preset|spacing|40"}}},[["core/buttons",{align:"center",layout:{type:"flex",justifyContent:"center"},metadata:{name:(0,a.__)("RSVP Buttons","gatherpress")}},[["core/button",{text:(0,a.__)("Edit RSVP","gatherpress"),tagName:"button",className:"gatherpress--open-modal"}]]],["core/group",{style:{spacing:{blockGap:"0"}}},[["core/group",{style:{spacing:{blockGap:"var:preset|spacing|20"}},layout:{type:"flex",flexWrap:"nowrap"}},[["gatherpress/icon",{icon:"yes-alt",iconSize:24}],["core/paragraph",{style:{spacing:{margin:{top:"0"},padding:{top:"0"}}},content:(0,a.__)("Attending","gatherpress")}]]],["gatherpress/rsvp-guest-count-display",{}]]],["gatherpress/modal",{className:"gatherpress--is-rsvp-modal",metadata:{name:(0,a.__)("RSVP Modal","gatherpress")}},[["gatherpress/modal-content",{},[["core/paragraph",{style:{spacing:{margin:{top:"0"},padding:{top:"0"}}},content:(0,a.__)("You're Attending","gatherpress")}],["core/paragraph",{content:(0,a.__)("To set or change your attending status, simply click the Not Attending button below.","gatherpress")}],["gatherpress/rsvp-guest-count-input",{}],["gatherpress/rsvp-anonymous-checkbox",{}],["core/buttons",{align:"left",layout:{type:"flex",justifyContent:"flex-start"},style:{spacing:{margin:{bottom:"0"},padding:{bottom:"0"}}}},[["core/button",{text:(0,a.__)("Not Attending","gatherpress"),tagName:"button",className:"gatherpress--update-rsvp"}],["core/button",{text:(0,a.__)("Close","gatherpress"),tagName:"button",className:"is-style-outline gatherpress--close-modal"}]]]]]]]]]];function p(e){if("object"==typeof GatherPress)return e.split(".").reduce(((e,t)=>e&&e[t]),GatherPress)}const g=[["gatherpress/modal-manager",{},[["core/buttons",{align:"center",layout:{type:"flex",justifyContent:"center"},metadata:{name:(0,a.__)("RSVP Buttons","gatherpress")}},[["core/button",{text:(0,a.__)("RSVP","gatherpress"),tagName:"button",className:"gatherpress--open-modal"}]]],["gatherpress/modal",{className:"gatherpress--is-rsvp-modal",metadata:{name:(0,a.__)("RSVP Modal","gatherpress")}},[["gatherpress/modal-content",{},[["core/paragraph",{style:{spacing:{margin:{top:"0"},padding:{top:"0"}}},content:(0,a.__)("RSVP to this event","gatherpress")}],["core/paragraph",{content:(0,a.__)("To set or change your attending status, simply click the Attending button below.","gatherpress")}],["gatherpress/rsvp-anonymous-checkbox",{}],["core/buttons",{align:"left",layout:{type:"flex",justifyContent:"flex-start"},style:{spacing:{margin:{bottom:"0"},padding:{bottom:"0"}}}},[["core/button",{text:(0,a.__)("Attending","gatherpress"),tagName:"button",className:"gatherpress--update-rsvp"}],["core/button",{text:(0,a.__)("Close","gatherpress"),tagName:"button",className:"is-style-outline gatherpress--close-modal"}]]]]]]],["gatherpress/modal",{className:"gatherpress--is-login-modal",metadata:{name:(0,a.__)("Login Modal","gatherpress")}},[["gatherpress/modal-content",{},[["core/paragraph",{style:{spacing:{margin:{top:"0"},padding:{top:"0"}}},content:(0,a.__)("Login Required","gatherpress")}],["core/paragraph",{content:(0,a.sprintf)(/* translators: %s: Login URL. */ /* translators: %s: Login URL. */ (0,a.__)('This action requires an account. Please Login to RSVP to this event.',"gatherpress"),p("urls.loginUrl")),className:"gatherpress--has-login-url"}],["core/paragraph",{content:(0,a.sprintf)(/* translators: %s: Registration URL. */ /* translators: %s: Registration URL. */ -(0,a.__)('Don\'t have an account? Register here to create one.',"gatherpress"),p("urls.registrationUrl")),className:"gatherpress--has-registration-url"}],["core/buttons",{align:"left",layout:{type:"flex",justifyContent:"flex-start"},style:{spacing:{margin:{bottom:"0"},padding:{bottom:"0"}}}},[["core/button",{text:(0,a.__)("Close","gatherpress"),tagName:"button",className:"gatherpress--close-modal"}]]]]]]]]]],l=[["gatherpress/modal-manager",{style:{spacing:{blockGap:"var:preset|spacing|40"}}},[["core/buttons",{align:"center",layout:{type:"flex",justifyContent:"center"},metadata:{name:(0,a.__)("RSVP Buttons","gatherpress")}},[["core/button",{text:(0,a.__)("Edit RSVP","gatherpress"),tagName:"button",className:"gatherpress--open-modal"}]]],["core/group",{style:{spacing:{blockGap:"var:preset|spacing|20"}},layout:{type:"flex",flexWrap:"nowrap"}},[["gatherpress/icon",{icon:"dismiss",iconSize:24}],["core/paragraph",{style:{spacing:{margin:{top:"0"},padding:{top:"0"}}},content:(0,a.__)("Not Attending","gatherpress")}]]],["gatherpress/modal",{className:"gatherpress--is-rsvp-modal",metadata:{name:(0,a.__)("RSVP Modal","gatherpress")}},[["gatherpress/modal-content",{},[["core/paragraph",{style:{spacing:{margin:{top:"0"},padding:{top:"0"}}},content:(0,a.__)("You're Not Attending","gatherpress")}],["core/paragraph",{content:(0,a.__)("To set or change your attending status, simply click the Attending button below.","gatherpress")}],["gatherpress/rsvp-anonymous-checkbox",{}],["core/buttons",{align:"left",layout:{type:"flex",justifyContent:"flex-start"},style:{spacing:{margin:{bottom:"0"},padding:{bottom:"0"}}}},[["core/button",{text:(0,a.__)("Attending","gatherpress"),tagName:"button",className:"gatherpress--update-rsvp"}],["core/button",{text:(0,a.__)("Close","gatherpress"),tagName:"button",className:"is-style-outline gatherpress--close-modal"}]]]]]]]]]],i={no_status:g,attending:o,waiting_list:[["gatherpress/modal-manager",{style:{spacing:{blockGap:"var:preset|spacing|40"}}},[["core/buttons",{align:"center",layout:{type:"flex",justifyContent:"center"},metadata:{name:(0,a.__)("RSVP Buttons","gatherpress")}},[["core/button",{text:(0,a.__)("Edit RSVP","gatherpress"),tagName:"button",className:"gatherpress--open-modal"}]]],["core/group",{style:{spacing:{blockGap:"var:preset|spacing|20"}},layout:{type:"flex",flexWrap:"nowrap"}},[["gatherpress/icon",{icon:"editor-help",iconSize:24}],["core/paragraph",{style:{spacing:{margin:{top:"0"},padding:{top:"0"}}},content:(0,a.__)("Waiting List","gatherpress")}]]],["gatherpress/modal",{className:"gatherpress--is-rsvp-modal",metadata:{name:(0,a.__)("RSVP Modal","gatherpress")}},[["gatherpress/modal-content",{},[["core/paragraph",{style:{spacing:{margin:{top:"0"},padding:{top:"0"}}},content:(0,a.__)("You're Wait Listed","gatherpress")}],["core/paragraph",{content:(0,a.__)("To set or change your attending status, simply click the Not Attending button below.","gatherpress")}],["gatherpress/rsvp-anonymous-checkbox",{}],["core/buttons",{align:"left",layout:{type:"flex",justifyContent:"flex-start"},style:{spacing:{margin:{bottom:"0"},padding:{bottom:"0"}}}},[["core/button",{text:(0,a.__)("Not Attending","gatherpress"),tagName:"button",className:"gatherpress--update-rsvp"}],["core/button",{text:(0,a.__)("Close","gatherpress"),tagName:"button",className:"is-style-outline gatherpress--close-modal"}]]]]]]]]]],not_attending:l,past:[["core/buttons",{align:"center",layout:{type:"flex",justifyContent:"center"},metadata:{name:(0,a.__)("RSVP Buttons","gatherpress")}},[["core/button",{text:(0,a.__)("Past Event","gatherpress"),tagName:"button",className:"gatherpress--is-disabled"}]]]]},c=window.ReactJSXRuntime;function u(t){return t.map((([t,s,a])=>(0,e.createBlock)(t,s,u(a||[]))))}const h=JSON.parse('{"$schema":"https://schemas.wp.org/trunk/block.json","apiVersion":3,"name":"gatherpress/rsvp-v2","version":"2.0.0","title":"RSVP V2","category":"gatherpress","icon":"insert","example":{},"description":"Enables members to easily confirm their attendance for an event.","attributes":{"serializedInnerBlocks":{"type":"string","default":"[]"},"selectedStatus":{"type":"string","default":"no_status"}},"supports":{"html":false,"interactivity":true},"textdomain":"gatherpress","editorScript":"file:./index.js","style":"file:./style-index.css","viewScriptModule":"file:./view.js"}');(0,e.registerBlockType)(h,{edit:({attributes:o,setAttributes:p,clientId:g})=>{const{serializedInnerBlocks:l="{}",selectedStatus:h}=o,d=(0,t.useBlockProps)(),{replaceInnerBlocks:m}=(0,n.useDispatch)(t.store),b=(0,n.useSelect)((e=>e(t.store).getBlocks(g)),[g]),_=(0,r.useCallback)(((t,s,a)=>{const r=JSON.parse(l||"{}"),n=(0,e.serialize)(a),o={...r,[t]:n};delete o[s],p({serializedInnerBlocks:JSON.stringify(o)})}),[l,p]),y=(0,r.useCallback)((t=>{const s=JSON.parse(l||"{}")[t];s&&s.length>0&&m(g,(0,e.parse)(s,{}))}),[g,m,l]);return(0,r.useEffect)((()=>{(()=>{const t=JSON.parse(l||"{}"),s=Object.keys(i).reduce(((s,a)=>{if(t[a])return s[a]=t[a],s;if(a!==h){const t=u(i[a]);s[a]=(0,e.serialize)(t)}return s}),{...t});p({serializedInnerBlocks:JSON.stringify(s)})})()}),[l,p,h]),(0,c.jsxs)(c.Fragment,{children:[(0,c.jsx)(t.InspectorControls,{children:(0,c.jsx)(s.PanelBody,{children:(0,c.jsx)(s.SelectControl,{label:(0,a.__)("RSVP Status","gatherpress"),value:h,options:[{label:(0,a.__)("No Status (User has not responded)","gatherpress"),value:"no_status"},{label:(0,a.__)("Attending (User is confirmed)","gatherpress"),value:"attending"},{label:(0,a.__)("Waiting List (Pending confirmation)","gatherpress"),value:"waiting_list"},{label:(0,a.__)("Not Attending (User declined)","gatherpress"),value:"not_attending"},{label:(0,a.__)("Past Event (Event has already occurred)","gatherpress"),value:"past"}],onChange:e=>{y(e),p({selectedStatus:e}),_(h,e,b)}})})}),(0,c.jsx)("div",{...d,children:(0,c.jsx)(t.InnerBlocks,{template:i[h]})})]})},save:()=>(0,c.jsx)("div",{...t.useBlockProps.save(),children:(0,c.jsx)(t.InnerBlocks.Content,{})})})}},s={};function a(e){var r=s[e];if(void 0!==r)return r.exports;var n=s[e]={exports:{}};return t[e](n,n.exports,a),n.exports}a.m=t,e=[],a.O=(t,s,r,n)=>{if(!s){var o=1/0;for(i=0;i=n)&&Object.keys(a.O).every((e=>a.O[e](s[g])))?s.splice(g--,1):(p=!1,n0&&e[i-1][2]>n;i--)e[i]=e[i-1];e[i]=[s,r,n]},a.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),(()=>{var e={6345:0,2525:0};a.O.j=t=>0===e[t];var t=(t,s)=>{var r,n,[o,p,g]=s,l=0;if(o.some((t=>0!==e[t]))){for(r in p)a.o(p,r)&&(a.m[r]=p[r]);if(g)var i=g(a)}for(t&&t(s);la(546)));r=a.O(r)})(); \ No newline at end of file +(0,a.__)('Don\'t have an account? Register here to create one.',"gatherpress"),p("urls.registrationUrl")),className:"gatherpress--has-registration-url"}],["core/buttons",{align:"left",layout:{type:"flex",justifyContent:"flex-start"},style:{spacing:{margin:{bottom:"0"},padding:{bottom:"0"}}}},[["core/button",{text:(0,a.__)("Close","gatherpress"),tagName:"button",className:"gatherpress--close-modal"}]]]]]]]]]],l=[["gatherpress/modal-manager",{style:{spacing:{blockGap:"var:preset|spacing|40"}}},[["core/buttons",{align:"center",layout:{type:"flex",justifyContent:"center"},metadata:{name:(0,a.__)("RSVP Buttons","gatherpress")}},[["core/button",{text:(0,a.__)("Edit RSVP","gatherpress"),tagName:"button",className:"gatherpress--open-modal"}]]],["core/group",{style:{spacing:{blockGap:"var:preset|spacing|20"}},layout:{type:"flex",flexWrap:"nowrap"}},[["gatherpress/icon",{icon:"dismiss",iconSize:24}],["core/paragraph",{style:{spacing:{margin:{top:"0"},padding:{top:"0"}}},content:(0,a.__)("Not Attending","gatherpress")}]]],["gatherpress/modal",{className:"gatherpress--is-rsvp-modal",metadata:{name:(0,a.__)("RSVP Modal","gatherpress")}},[["gatherpress/modal-content",{},[["core/paragraph",{style:{spacing:{margin:{top:"0"},padding:{top:"0"}}},content:(0,a.__)("You're Not Attending","gatherpress")}],["core/paragraph",{content:(0,a.__)("To set or change your attending status, simply click the Attending button below.","gatherpress")}],["gatherpress/rsvp-anonymous-checkbox",{}],["core/buttons",{align:"left",layout:{type:"flex",justifyContent:"flex-start"},style:{spacing:{margin:{bottom:"0"},padding:{bottom:"0"}}}},[["core/button",{text:(0,a.__)("Attending","gatherpress"),tagName:"button",className:"gatherpress--update-rsvp"}],["core/button",{text:(0,a.__)("Close","gatherpress"),tagName:"button",className:"is-style-outline gatherpress--close-modal"}]]]]]]]]]],i={no_status:g,attending:o,waiting_list:[["gatherpress/modal-manager",{style:{spacing:{blockGap:"var:preset|spacing|40"}}},[["core/buttons",{align:"center",layout:{type:"flex",justifyContent:"center"},metadata:{name:(0,a.__)("RSVP Buttons","gatherpress")}},[["core/button",{text:(0,a.__)("Edit RSVP","gatherpress"),tagName:"button",className:"gatherpress--open-modal"}]]],["core/group",{style:{spacing:{blockGap:"var:preset|spacing|20"}},layout:{type:"flex",flexWrap:"nowrap"}},[["gatherpress/icon",{icon:"editor-help",iconSize:24}],["core/paragraph",{style:{spacing:{margin:{top:"0"},padding:{top:"0"}}},content:(0,a.__)("Waiting List","gatherpress")}]]],["gatherpress/modal",{className:"gatherpress--is-rsvp-modal",metadata:{name:(0,a.__)("RSVP Modal","gatherpress")}},[["gatherpress/modal-content",{},[["core/paragraph",{style:{spacing:{margin:{top:"0"},padding:{top:"0"}}},content:(0,a.__)("You're Wait Listed","gatherpress")}],["core/paragraph",{content:(0,a.__)("To set or change your attending status, simply click the Not Attending button below.","gatherpress")}],["gatherpress/rsvp-anonymous-checkbox",{}],["core/buttons",{align:"left",layout:{type:"flex",justifyContent:"flex-start"},style:{spacing:{margin:{bottom:"0"},padding:{bottom:"0"}}}},[["core/button",{text:(0,a.__)("Not Attending","gatherpress"),tagName:"button",className:"gatherpress--update-rsvp"}],["core/button",{text:(0,a.__)("Close","gatherpress"),tagName:"button",className:"is-style-outline gatherpress--close-modal"}]]]]]]]]]],not_attending:l,past:[["core/buttons",{align:"center",layout:{type:"flex",justifyContent:"center"},metadata:{name:(0,a.__)("RSVP Buttons","gatherpress")}},[["core/button",{text:(0,a.__)("Past Event","gatherpress"),tagName:"button",className:"gatherpress--is-disabled"}]]]]},c=window.ReactJSXRuntime;function u(t){return t.map((([t,s,a])=>(0,e.createBlock)(t,s,u(a||[]))))}const d=JSON.parse('{"$schema":"https://schemas.wp.org/trunk/block.json","apiVersion":3,"name":"gatherpress/rsvp-v2","version":"2.0.0","title":"RSVP V2","category":"gatherpress","icon":"insert","example":{},"description":"Enables members to easily confirm their attendance for an event.","usesContext":["postId","queryId"],"attributes":{"postId":{"type":"number"},"serializedInnerBlocks":{"type":"string","default":"[]"},"selectedStatus":{"type":"string","default":"no_status"}},"supports":{"html":false,"interactivity":true},"textdomain":"gatherpress","editorScript":"file:./index.js","style":"file:./style-index.css","viewScriptModule":"file:./view.js"}');(0,e.registerBlockType)(d,{edit:({attributes:o,setAttributes:p,clientId:g})=>{const{serializedInnerBlocks:l="{}",selectedStatus:d}=o,h=(0,t.useBlockProps)(),{replaceInnerBlocks:m}=(0,n.useDispatch)(t.store),b=(0,n.useSelect)((e=>e(t.store).getBlocks(g)),[g]),_=(0,r.useCallback)(((t,s,a)=>{const r=JSON.parse(l||"{}"),n=(0,e.serialize)(a),o={...r,[t]:n};delete o[s],p({serializedInnerBlocks:JSON.stringify(o)})}),[l,p]),y=(0,r.useCallback)((t=>{const s=JSON.parse(l||"{}")[t];s&&s.length>0&&m(g,(0,e.parse)(s,{}))}),[g,m,l]);return(0,r.useEffect)((()=>{(()=>{const t=JSON.parse(l||"{}"),s=Object.keys(i).reduce(((s,a)=>{if(t[a])return s[a]=t[a],s;if(a!==d){const t=u(i[a]);s[a]=(0,e.serialize)(t)}return s}),{...t});p({serializedInnerBlocks:JSON.stringify(s)})})()}),[l,p,d]),(0,c.jsxs)(c.Fragment,{children:[(0,c.jsx)(t.InspectorControls,{children:(0,c.jsx)(s.PanelBody,{children:(0,c.jsx)(s.SelectControl,{label:(0,a.__)("RSVP Status","gatherpress"),value:d,options:[{label:(0,a.__)("No Status (User has not responded)","gatherpress"),value:"no_status"},{label:(0,a.__)("Attending (User is confirmed)","gatherpress"),value:"attending"},{label:(0,a.__)("Waiting List (Pending confirmation)","gatherpress"),value:"waiting_list"},{label:(0,a.__)("Not Attending (User declined)","gatherpress"),value:"not_attending"},{label:(0,a.__)("Past Event (Event has already occurred)","gatherpress"),value:"past"}],onChange:e=>{y(e),p({selectedStatus:e}),_(d,e,b)}})})}),(0,c.jsx)("div",{...h,children:(0,c.jsx)(t.InnerBlocks,{template:i[d]})})]})},save:()=>(0,c.jsx)("div",{...t.useBlockProps.save(),children:(0,c.jsx)(t.InnerBlocks.Content,{})})})}},s={};function a(e){var r=s[e];if(void 0!==r)return r.exports;var n=s[e]={exports:{}};return t[e](n,n.exports,a),n.exports}a.m=t,e=[],a.O=(t,s,r,n)=>{if(!s){var o=1/0;for(i=0;i=n)&&Object.keys(a.O).every((e=>a.O[e](s[g])))?s.splice(g--,1):(p=!1,n0&&e[i-1][2]>n;i--)e[i]=e[i-1];e[i]=[s,r,n]},a.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),(()=>{var e={6345:0,2525:0};a.O.j=t=>0===e[t];var t=(t,s)=>{var r,n,[o,p,g]=s,l=0;if(o.some((t=>0!==e[t]))){for(r in p)a.o(p,r)&&(a.m[r]=p[r]);if(g)var i=g(a)}for(t&&t(s);la(546)));r=a.O(r)})(); \ No newline at end of file diff --git a/includes/core/classes/class-assets.php b/includes/core/classes/class-assets.php index 74c713192..3ffeb0462 100644 --- a/includes/core/classes/class-assets.php +++ b/includes/core/classes/class-assets.php @@ -420,30 +420,17 @@ protected function unregister_blocks(): array { case Venue::POST_TYPE: $blocks = array( 'gatherpress/add-to-calendar', - 'gatherpress/event-date', 'gatherpress/online-event', - 'gatherpress/rsvp', - 'gatherpress/rsvp-anonymous-checkbox', - 'gatherpress/rsvp-guest-count-display', - 'gatherpress/rsvp-guest-count-input', - 'gatherpress/rsvp-v2', - 'gatherpress/rsvp-response', - 'gatherpress/rsvp-response-v2', + 'gatherpress/rsvp', // will be removed when name changes. + 'gatherpress/rsvp-response', // will be removed when name changes. ); break; default: $blocks = array( 'gatherpress/add-to-calendar', - 'gatherpress/event-date', - 'gatherpress/modal', 'gatherpress/online-event', - 'gatherpress/rsvp', - 'gatherpress/rsvp-anonymous-checkbox', - 'gatherpress/rsvp-guest-count-display', - 'gatherpress/rsvp-guest-count-input', - 'gatherpress/rsvp-v2', - 'gatherpress/rsvp-response', - 'gatherpress/rsvp-response-v2', + 'gatherpress/rsvp', // will be removed when name changes. + 'gatherpress/rsvp-response', // will be removed when name changes. 'gatherpress/venue', ); } diff --git a/includes/core/classes/class-event-rest-api.php b/includes/core/classes/class-event-rest-api.php index e54b66c98..68b7d9262 100644 --- a/includes/core/classes/class-event-rest-api.php +++ b/includes/core/classes/class-event-rest-api.php @@ -99,6 +99,7 @@ protected function get_event_routes(): array { $this->email_route(), $this->rsvp_route(), $this->rsvp_status_html_route(), + $this->rsvp_responses_route(), $this->events_list_route(), ); } @@ -208,6 +209,23 @@ protected function rsvp_status_html_route(): array { ); } + protected function rsvp_responses_route(): array { + return array( + 'route' => 'rsvp-responses', + 'args' => array( + 'methods' => WP_REST_Server::READABLE, + 'callback' => array( $this, 'rsvp_responses' ), + 'permission_callback' => '__return_true', + 'args' => array( + 'post_id' => array( + 'required' => true, + 'validate_callback' => array( Validate::class, 'event_post_id' ), + ), + ), + ), + ); + } + /** * Define the REST route for retrieving a list of events. * @@ -606,6 +624,26 @@ public function rsvp_status_html( WP_REST_Request $request ): WP_REST_Response { return new WP_REST_Response( $response ); } + public function rsvp_responses( WP_REST_Request $request ): WP_REST_Response { + $params = $request->get_params(); + $post_id = intval( $params['post_id'] ); + $success = false; + $responses = array(); + + if ( Event::POST_TYPE === get_post_type( $post_id ) ) { + $success = true; + $rsvp = new Rsvp( $post_id ); + $responses = $rsvp->responses(); + } + + $response = array( + 'success' => $success, + 'data' => $responses, + ); + + return new WP_REST_Response( $response ); + } + /** * Prepare event data for the response. * diff --git a/src/blocks/event-date/block.json b/src/blocks/event-date/block.json index ee221ddcd..f8e9bfd02 100644 --- a/src/blocks/event-date/block.json +++ b/src/blocks/event-date/block.json @@ -10,7 +10,11 @@ "viewportWidth": 350 }, "description": "Displays the date and time for an event.", + "usesContext": [ "postId", "queryId" ], "attributes": { + "postId": { + "type": "number" + }, "eventEnd": { "type": "string" }, diff --git a/src/blocks/rsvp-response-v2/block.json b/src/blocks/rsvp-response-v2/block.json index f7f6ef660..5c432850b 100644 --- a/src/blocks/rsvp-response-v2/block.json +++ b/src/blocks/rsvp-response-v2/block.json @@ -8,7 +8,12 @@ "icon": "groups", "example": {}, "description": "Displays a list of members who have confirmed their attendance for an event.", - "attributes": {}, + "attributes": { + "postId": { + "type": "number" + } + }, + "usesContext": [ "postId", "queryId" ], "supports": { "align": [ "wide", "full" ], "interactivity": true, diff --git a/src/blocks/rsvp-response-v2/edit.js b/src/blocks/rsvp-response-v2/edit.js index a965d9539..02f4593ee 100644 --- a/src/blocks/rsvp-response-v2/edit.js +++ b/src/blocks/rsvp-response-v2/edit.js @@ -13,15 +13,35 @@ import { ToggleControl, ToolbarButton, ToolbarGroup, + Spinner, } from '@wordpress/components'; import { useState, useEffect } from '@wordpress/element'; -import { useSelect } from '@wordpress/data'; +import { useSelect, useDispatch } from '@wordpress/data'; +import { BlockContextProvider } from '@wordpress/block-editor'; /** * Internal dependencies. */ import RsvpManager from './rsvp-manager'; import TEMPLATE from './template'; +import { getFromGlobal } from '../../helpers/globals'; + +/** + * Fetch RSVP responses from the API. + * + * @param {number} postId The post ID for which to fetch RSVP responses. + * @returns {Promise} The RSVP responses data. + */ +async function fetchRsvpResponses(postId) { + const apiUrl = getFromGlobal('urls.eventApiUrl'); + const response = await fetch(`${apiUrl}/rsvp-responses?post_id=${postId}`); + + if (!response.ok) { + throw new Error('Failed to fetch RSVP responses'); + } + + return response.json(); +} /** * Edit component for the GatherPress RSVP Response block. @@ -32,12 +52,16 @@ import TEMPLATE from './template'; * * @return {JSX.Element} The rendered edit interface for the block. */ -const Edit = ({ clientId }) => { +const Edit = ({ clientId, context }) => { const blockProps = useBlockProps(); const [editMode, setEditMode] = useState(false); const [showEmptyRsvpMessage, setShowEmptyRsvpMessage] = useState(false); const [defaultStatus, setDefaultStatus] = useState('attending'); - + const [responses, setResponses] = useState(null); + const [loading, setLoading] = useState(true); + const [error, setError] = useState(null); + const postId = context?.postId ?? null; + const { updateBlockAttributes } = useDispatch('core/block-editor'); const innerBlocks = useSelect( (select) => select('core/block-editor').getBlocks(clientId), [clientId] @@ -71,46 +95,87 @@ const Edit = ({ clientId }) => { }); }, [showEmptyRsvpMessage, innerBlocks, editMode]); + // Fetch responses when postId changes. + useEffect(() => { + if (!postId) { + setResponses(null); + setLoading(false); + return; + } + + setLoading(true); + setError(null); + + fetchRsvpResponses(postId) + .then((response) => { + // console.log('Fetched RSVP Responses:', response.data); // Log the responses for testing + setResponses(response.data); + setLoading(false); + }) + .catch((err) => { + setError(err.message); + setLoading(false); + }); + }, [postId]); + const onEditClick = (e) => { e.preventDefault(); setEditMode(!editMode); }; + if (loading) { + return ( + + + + ); + } + + if (error) { + return ( + + {__('Failed to load RSVP responses.', 'gatherpress')} + + ); + } + return ( - - - setShowEmptyRsvpMessage(value)} - help={__( - 'Toggle to show or hide the Empty RSVP block.', - 'gatherpress' - )} - /> - - - - - + + + setShowEmptyRsvpMessage(value)} + help={__( + 'Toggle to show or hide the Empty RSVP block.', + 'gatherpress' + )} + /> + + + + + + + + {editMode && ( + - - - {editMode && ( - - )} - {!editMode && } + )} + {!editMode && } + ); }; diff --git a/src/blocks/rsvp-template/block.json b/src/blocks/rsvp-template/block.json index 8803c7d64..75c8d8f84 100644 --- a/src/blocks/rsvp-template/block.json +++ b/src/blocks/rsvp-template/block.json @@ -11,6 +11,7 @@ "supports": { "html": false }, + "usesContext": [ "gatherpress/rsvpResponses" ], "parent": [ "core/group" ], "ancestor": [ "core/rsvp-response-v2" ], "textdomain": "gatherpress", diff --git a/src/blocks/rsvp-template/edit.js b/src/blocks/rsvp-template/edit.js index 11b6a64c1..239c8211d 100644 --- a/src/blocks/rsvp-template/edit.js +++ b/src/blocks/rsvp-template/edit.js @@ -10,12 +10,12 @@ import { useInnerBlocksProps, } from '@wordpress/block-editor'; import { useSelect } from '@wordpress/data'; +import { memo, useEffect, useState } from '@wordpress/element'; /** * Internal dependencies. */ import { getFromGlobal } from '../../helpers/globals'; -import { memo, useState } from '@wordpress/element'; import TEMPLATE from './template'; const TemplateInnerBlocks = ({ @@ -123,12 +123,25 @@ const List = ({ > ); -const Edit = ({ clientId }) => { +const Edit = ({ clientId, context }) => { const blockProps = useBlockProps(); - const responses = getFromGlobal('eventDetails.responses'); + + // Access the provided RSVP responses context from the parent block. + const rsvpResponses = context?.['gatherpress/rsvpResponses'] ?? null; + + // Log the context for debugging. + console.log('Context:', context); + console.log('RSVP Responses:', rsvpResponses); + + // Initialize active RSVP ID. const [activeRsvpId, setActiveRsvpId] = useState( - parseInt(responses.attending.responses[0]?.commentId, 10) ?? null + parseInt( + rsvpResponses?.attending?.records?.[0]?.commentId, + 10 + ) ?? null ); + + // Get the block's inner blocks. const { blocks } = useSelect( (select) => { const { getBlocks } = select(blockEditorStore); @@ -139,10 +152,11 @@ const Edit = ({ clientId }) => { [clientId] ); + // Prepare RSVP data. let rsvps = [{ commentId: -1 }]; - if (responses.attending.responses.length) { - rsvps = responses.attending.responses; + if (rsvpResponses?.attending?.responses?.length) { + rsvps = rsvpResponses.attending.responses; } return ( diff --git a/src/blocks/rsvp-v2/block.json b/src/blocks/rsvp-v2/block.json index 869c82d1b..0196d19f3 100644 --- a/src/blocks/rsvp-v2/block.json +++ b/src/blocks/rsvp-v2/block.json @@ -8,7 +8,11 @@ "icon": "insert", "example": {}, "description": "Enables members to easily confirm their attendance for an event.", + "usesContext": [ "postId", "queryId" ], "attributes": { + "postId": { + "type": "number" + }, "serializedInnerBlocks": { "type": "string", "default": "[]"
{__('Failed to load RSVP responses.', 'gatherpress')}