From 235c173cd371033ac3d08804d1303fbe3fbc41d0 Mon Sep 17 00:00:00 2001 From: Mike Auteri Date: Thu, 9 Jan 2025 16:59:29 -0500 Subject: [PATCH] Work on RSVP V2. --- build/blocks/rsvp-response-v2/index.asset.php | 2 +- build/blocks/rsvp-response-v2/index.js | 21 +---- build/blocks/rsvp-response-v2/view.asset.php | 2 +- build/blocks/rsvp-response-v2/view.js | 2 +- build/blocks/rsvp-v2/view.asset.php | 2 +- build/blocks/rsvp-v2/view.js | 2 +- includes/core/classes/blocks/class-rsvp.php | 8 ++ includes/core/classes/class-assets.php | 18 ++-- .../core/classes/class-event-rest-api.php | 1 + src/blocks/rsvp-response-v2/edit.js | 53 +++++------ src/blocks/rsvp-response-v2/template.js | 91 ++++++------------- src/blocks/rsvp-v2/view.js | 29 +++++- src/helpers/interactivity.js | 16 ++-- 13 files changed, 108 insertions(+), 139 deletions(-) diff --git a/build/blocks/rsvp-response-v2/index.asset.php b/build/blocks/rsvp-response-v2/index.asset.php index 39e3326ce..5126818a5 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' => 'ec2efa427b68d8cb99fa'); + array('react-jsx-runtime', 'wp-api-fetch', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-core-data', 'wp-data', 'wp-element', 'wp-i18n'), 'version' => '4d77e2724b82476c72b0'); diff --git a/build/blocks/rsvp-response-v2/index.js b/build/blocks/rsvp-response-v2/index.js index 0b7bf187d..ede8377af 100644 --- a/build/blocks/rsvp-response-v2/index.js +++ b/build/blocks/rsvp-response-v2/index.js @@ -1,20 +1 @@ -(()=>{"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,a.__)("Attending (%d)","gatherpress"),metadata:{ -// Translators: %d is the count of attendees. -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,a.__)("Attending (%d)","gatherpress")+"",metadata:{ -// Translators: %d is the count of attendees. -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,a.__)("Waiting List (%d)","gatherpress")+"",metadata:{ -// Translators: %d is the count of users on the waiting list. -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,a.__)("Not Attending (%d)","gatherpress")+"",metadata:{ -// Translators: %d is the count of users not attending. -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,C=(0,l.useSelect)((t=>t("core/block-editor").getBlocks(e)),[e]);return(0,i.useEffect)((()=>{C.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,C,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={291:0,507: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 +(()=>{"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.apiFetch;var p=s.n(l);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"),[l,h]=(0,i.useState)(r),v=l[e].responses,{userList:m}=(0,d.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")=>{p()({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: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={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")},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",label:v.attending,metadata:{name:v.attending}},[["gatherpress/dropdown-item",{text:`${v.attending}`,metadata:{name:v.attending},className:"gatherpress--rsvp-attending"}],["gatherpress/dropdown-item",{text:`${v.waitingList}`,metadata:{name:v.waitingList},className:"gatherpress--rsvp-waiting-list"}],["gatherpress/dropdown-item",{text:`${v.notAttending}`,metadata:{name:v.notAttending},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 gatherpress--is-not-visible"},[["core/paragraph",{content:v.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.","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)(f,{edit:({context:e})=>{var t;const s=(0,n.useBlockProps)(),[r,l]=(0,i.useState)(!1),[p,d]=(0,i.useState)(!1),[c,v]=(0,i.useState)("attending"),[f,w]=(0,i.useState)(null),[x,_]=(0,i.useState)(!0),[b,S]=(0,i.useState)(null),y=null!==(t=e?.postId)&&void 0!==t?t:null;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",!p)})),t.forEach((e=>{e.classList.toggle("gatherpress--is-not-visible",p)}))}),[p,f]),(0,i.useEffect)((()=>{if(!y)return w(null),void _(!1);_(!0),S(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()}(y).then((e=>{w(e.data),_(!1)})).catch((e=>{S(e.message),_(!1)}))}),[y]),x?(0,g.jsx)("div",{...s,children:(0,g.jsx)(o.Spinner,{})}):b?(0,g.jsx)("div",{...s,children:(0,g.jsx)("p",{children:(0,a.__)("Failed to load RSVP responses.","gatherpress")})}):(0,g.jsx)("div",{...s,children:(0,g.jsxs)(n.BlockContextProvider,{value:{"gatherpress/rsvpResponses":f},children:[(0,g.jsx)(n.InspectorControls,{children:(0,g.jsx)(o.PanelBody,{children:(0,g.jsx)(o.ToggleControl,{label:(0,a.__)("Show Empty RSVP Block","gatherpress"),checked:p,onChange:e=>d(e),help:(0,a.__)("Toggle to show or hide the Empty RSVP block.","gatherpress")})})}),(0,g.jsx)(n.BlockControls,{children:(0,g.jsx)(o.ToolbarGroup,{children:(0,g.jsx)(o.ToolbarButton,{label:(0,a.__)("Edit","gatherpress"),text:r?(0,a.__)("Preview","gatherpress"):(0,a.__)("Edit","gatherpress"),onClick:e=>{e.preventDefault(),l(!r)}})})}),r&&(0,g.jsx)(h,{defaultStatus:c,setDefaultStatus:v}),!r&&(0,g.jsx)(n.InnerBlocks,{template:m})]})})},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[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.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),(()=>{var e={291:0,507: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-response-v2/view.asset.php b/build/blocks/rsvp-response-v2/view.asset.php index d115f412f..b9c402db0 100644 --- a/build/blocks/rsvp-response-v2/view.asset.php +++ b/build/blocks/rsvp-response-v2/view.asset.php @@ -1 +1 @@ - array('@wordpress/interactivity'), 'version' => '48d3665bfb0eeb1d6e1e', 'type' => 'module'); + array('@wordpress/interactivity'), 'version' => 'ea95e70d3e3463abfdea', 'type' => 'module'); diff --git a/build/blocks/rsvp-response-v2/view.js b/build/blocks/rsvp-response-v2/view.js index a1ceaada7..f6abafa43 100644 --- a/build/blocks/rsvp-response-v2/view.js +++ b/build/blocks/rsvp-response-v2/view.js @@ -1 +1 @@ -import*as t from"@wordpress/interactivity";var e={d:(t,s)=>{for(var r in s)e.o(s,r)&&!e.o(t,r)&&Object.defineProperty(t,r,{enumerable:!0,get:s[r]})}};e.g=function(){if("object"==typeof globalThis)return globalThis;try{return this||new Function("return this")()}catch(t){if("object"==typeof window)return window}}(),e.o=(t,e)=>Object.prototype.hasOwnProperty.call(t,e);const s=(r={getContext:()=>t.getContext,getElement:()=>t.getElement,store:()=>t.store},n={},e.d(n,r),n);var r,n;function o(t,e){const s=function(){if("object"==typeof GatherPress)return"eventDetails".split(".").reduce(((t,e)=>t&&t[e]),GatherPress)}();t.posts[e]||(t.posts[e]={eventResponses:{attending:s.responses.attending.count||0,waitingList:s.responses.waiting_list.count||0,notAttending:s.responses.not_attending.count||0},currentUser:{status:s.currentUser?.status||"no_status",guests:s.currentUser?.guests||0,anonymous:s.currentUser?.anonymous||0},rsvpSelection:"attending"})}const{state:a,actions:i}=(0,s.store)("gatherpress",{state:{posts:{}},actions:{processRsvpSelection(t){i.linkHandler(t);const e=(0,s.getElement)();if(e&&e.ref){const t=e.ref.getAttribute("data-status");if(t){const e=(0,s.getContext)(),r=e?.postId||0;o(a,r),r&&(a.posts[r].rsvpSelection=t)}}}},callbacks:{processRsvpDropdown(){const t=(0,s.getContext)(),e=t?.postId||0;o(a,e);const r=(0,s.getElement)();if(r&&r.ref&&!r.ref.hasAttribute("data-label")){const t=r.ref.textContent.trim();t&&r.ref.setAttribute("data-label",t)}const n=r.ref.parentElement,i=n?.classList||[],c=r.ref.getAttribute("data-label"),p=r.ref.getAttribute("data-status")===a.posts[e].rsvpSelection||"attending"===r.ref.getAttribute("data-status")&&"no_status"===a.posts[e].rsvpSelection,l=r.ref.closest(".wp-block-gatherpress-dropdown"),d=l.querySelector(".wp-block-gatherpress-dropdown__trigger");let g=0;if(i.contains("gatherpress--rsvp-attending")?g=a.posts[e]?.eventResponses?.attending||0:i.contains("gatherpress--rsvp-waiting-list")?g=a.posts[e]?.eventResponses?.waitingList||0:i.contains("gatherpress--rsvp-not-attending")&&(g=a.posts[e]?.eventResponses?.notAttending||0),c){const t=c.replace("%d",g);r.ref.textContent=t}if(p){const t=r.ref.textContent.trim();l.querySelectorAll("[data-status]").forEach((t=>{t.classList.remove("gatherpress--is-disabled"),t.removeAttribute("tabindex"),t.removeAttribute("aria-disabled")})),r.ref.classList.add("gatherpress--is-disabled"),r.ref.setAttribute("tabindex","-1"),r.ref.setAttribute("aira-disabled","true"),d.textContent=t}0!==g||i.contains("gatherpress--rsvp-attending")?n.classList.remove("gatherpress--is-not-visible"):n.classList.add("gatherpress--is-not-visible");const u=l.querySelectorAll(".wp-block-gatherpress-dropdown-item:not(.gatherpress--is-not-visible)");1===u.length&&u[0].classList.contains("gatherpress--rsvp-attending")?(d.classList.add("gatherpress--is-disabled"),d.setAttribute("tabindex","-1")):(d.classList.remove("gatherpress--is-disabled"),d.setAttribute("tabindex","0"))}}}); \ No newline at end of file +import*as t from"@wordpress/interactivity";var e={d:(t,s)=>{for(var r in s)e.o(s,r)&&!e.o(t,r)&&Object.defineProperty(t,r,{enumerable:!0,get:s[r]})}};e.g=function(){if("object"==typeof globalThis)return globalThis;try{return this||new Function("return this")()}catch(t){if("object"==typeof window)return window}}(),e.o=(t,e)=>Object.prototype.hasOwnProperty.call(t,e);const s=(r={getContext:()=>t.getContext,getElement:()=>t.getElement,store:()=>t.store},n={},e.d(n,r),n);var r,n;function o(t,e){t.posts[e]||(t.posts[e]={eventResponses:{attending:0,waitingList:0,notAttending:0},currentUser:{status:"no_status",guests:0,anonymous:0},rsvpSelection:"attending"})}const{state:a,actions:i}=(0,s.store)("gatherpress",{state:{posts:{}},actions:{processRsvpSelection(t){i.linkHandler(t);const e=(0,s.getElement)();if(e&&e.ref){const t=e.ref.getAttribute("data-status");if(t){const e=(0,s.getContext)(),r=e?.postId||0;o(a,r),r&&(a.posts[r].rsvpSelection=t)}}}},callbacks:{processRsvpDropdown(){const t=(0,s.getContext)(),e=t?.postId||0;o(a,e);const r=(0,s.getElement)();if(r&&r.ref&&!r.ref.hasAttribute("data-label")){const t=r.ref.textContent.trim();t&&r.ref.setAttribute("data-label",t)}const n=r.ref.parentElement,i=n?.classList||[],p=r.ref.getAttribute("data-label"),l=r.ref.getAttribute("data-status")===a.posts[e].rsvpSelection||"attending"===r.ref.getAttribute("data-status")&&"no_status"===a.posts[e].rsvpSelection,c=r.ref.closest(".wp-block-gatherpress-dropdown"),d=c.querySelector(".wp-block-gatherpress-dropdown__trigger");let g=0;if(i.contains("gatherpress--rsvp-attending")?g=a.posts[e]?.eventResponses?.attending||0:i.contains("gatherpress--rsvp-waiting-list")?g=a.posts[e]?.eventResponses?.waitingList||0:i.contains("gatherpress--rsvp-not-attending")&&(g=a.posts[e]?.eventResponses?.notAttending||0),p){const t=p.replace("%d",g);r.ref.textContent=t}if(l){const t=r.ref.textContent.trim();c.querySelectorAll("[data-status]").forEach((t=>{t.classList.remove("gatherpress--is-disabled"),t.removeAttribute("tabindex"),t.removeAttribute("aria-disabled")})),r.ref.classList.add("gatherpress--is-disabled"),r.ref.setAttribute("tabindex","-1"),r.ref.setAttribute("aira-disabled","true"),d.textContent=t}0!==g||i.contains("gatherpress--rsvp-attending")?n.classList.remove("gatherpress--is-not-visible"):n.classList.add("gatherpress--is-not-visible");const b=c.querySelectorAll(".wp-block-gatherpress-dropdown-item:not(.gatherpress--is-not-visible)");1===b.length&&b[0].classList.contains("gatherpress--rsvp-attending")?(d.classList.add("gatherpress--is-disabled"),d.setAttribute("tabindex","-1")):(d.classList.remove("gatherpress--is-disabled"),d.setAttribute("tabindex","0"))}}}); \ No newline at end of file diff --git a/build/blocks/rsvp-v2/view.asset.php b/build/blocks/rsvp-v2/view.asset.php index 55a948e00..014b60970 100644 --- a/build/blocks/rsvp-v2/view.asset.php +++ b/build/blocks/rsvp-v2/view.asset.php @@ -1 +1 @@ - array('@wordpress/interactivity'), 'version' => 'a1e4da2c2d7fdb0cc5a8', 'type' => 'module'); + array('@wordpress/interactivity'), 'version' => 'b0320c156315a0a86662', 'type' => 'module'); diff --git a/build/blocks/rsvp-v2/view.js b/build/blocks/rsvp-v2/view.js index 0dec83016..78c71b1c4 100644 --- a/build/blocks/rsvp-v2/view.js +++ b/build/blocks/rsvp-v2/view.js @@ -1 +1 @@ -import*as t from"@wordpress/interactivity";var e={d:(t,s)=>{for(var n in s)e.o(s,n)&&!e.o(t,n)&&Object.defineProperty(t,n,{enumerable:!0,get:s[n]})}};e.g=function(){if("object"==typeof globalThis)return globalThis;try{return this||new Function("return this")()}catch(t){if("object"==typeof window)return window}}(),e.o=(t,e)=>Object.prototype.hasOwnProperty.call(t,e);const s=(n={getContext:()=>t.getContext,getElement:()=>t.getElement,store:()=>t.store},o={},e.d(o,n),o);var n,o;function r(t){if("object"==typeof GatherPress)return t.split(".").reduce(((t,e)=>t&&t[e]),GatherPress)}function u(t,e){const s=r("eventDetails");t.posts[e]||(t.posts[e]={eventResponses:{attending:s.responses.attending.count||0,waitingList:s.responses.waiting_list.count||0,notAttending:s.responses.not_attending.count||0},currentUser:{status:s.currentUser?.status||"no_status",guests:s.currentUser?.guests||0,anonymous:s.currentUser?.anonymous||0},rsvpSelection:"attending"})}function a(t,e,s=null,n=null){["no_status","waiting_list"].includes(e.status)||fetch(r("urls.eventApiUrl")+"/rsvp",{method:"POST",headers:{"Content-Type":"application/json","X-WP-Nonce":r("misc.nonce")},body:JSON.stringify({post_id:t,status:e.status,guests:e.guests,anonymous:e.anonymous})}).then((t=>t.json())).then((e=>{e.success&&(s&&(s.activePostId=t,s.posts[t]={...s.posts[t],eventResponses:{attending:e.responses.attending.count,waitingList:e.responses.waiting_list.count,notAttending:e.responses.not_attending.count},currentUser:{status:e.status,guests:e.guests,anonymous:e.anonymous},rsvpSelection:e.status}),"function"==typeof n&&n(e))})).catch((()=>{}))}const{state:i,actions:c}=(0,s.store)("gatherpress",{actions:{updateGuestCount(){const t=(0,s.getElement)(),e=(0,s.getContext)().postId||0,n=i.posts[e].currentUser;n.guests=parseInt(t.ref.value,10),u(i,e),a(e,n,i,(()=>{setTimeout((()=>{t.ref.focus()}),1)}))},updateAnonymous(){const t=(0,s.getElement)(),e=(0,s.getContext)().postId||0,n=i.posts[e].currentUser;n.anonymous=t.ref.checked?1:0,u(i,e),a(e,n,i,(()=>{setTimeout((()=>{t.ref.focus()}),1)}))},updateRsvp(t=null){var e;t&&t.preventDefault();const n=(0,s.getElement)(),o=(0,s.getContext)(),r=o?.postId||0,u=null!==(e=n.ref.getAttribute("data-set-status"))&&void 0!==e?e:"",p=i.posts[r].currentUser.status;let l="not_attending";t?["attending","waiting_list","not_attending"].includes(u)?l=u:["not_attending","no_status"].includes(p)&&(l="attending"):l=p,a(r,{status:l,guests:i.posts[r].currentUser.guests,anonymous:i.posts[r].currentUser.anonymous},i,(()=>{const t=n.ref.closest("[data-rsvp-status]"),e=t.getAttribute("data-rsvp-status"),s=t.closest(".wp-block-gatherpress-rsvp-v2");if(["not_attending","no_status"].includes(e)){const t=s.querySelector('[data-rsvp-status="attending"] .gatherpress--update-rsvp');c.openModal(null,t)}setTimeout((()=>{c.closeModal(null,n.ref)}),1)}))}},callbacks:{monitorAnonymousStatus(){const t=(0,s.getElement)(),e=(0,s.getContext)().postId||0;u(i,e),t.ref.checked=i.posts[e].currentUser.anonymous},setGuestCount(){const t=(0,s.getElement)(),e=(0,s.getContext)().postId||0;u(i,e),t.ref.value=i.posts[e].currentUser.guests},renderRsvpBlock(){var t;const e=(0,s.getElement)(),n=(0,s.getContext)(),o=null!==(t=i.posts[n.postId]?.currentUser?.status)&&void 0!==t?t:r("eventDetails.currentUser.status");e.ref.querySelectorAll("[data-rsvp-status]").forEach((t=>{const e=t.parentNode;t.getAttribute("data-rsvp-status")===o?(t.style.display="",e.insertBefore(t,e.firstChild)):t.style.display="none"}))},updateGuestCountDisplay(){const t=(0,s.getContext)(),e=t?.postId||0;u(i,t);const n=parseInt(i.posts[e]?.currentUser?.guests||0,10),o=(0,s.getElement)(),r=o.ref.getAttribute("data-guest-singular"),a=o.ref.getAttribute("data-guest-plural");let c="";0{for(var n in s)e.o(s,n)&&!e.o(t,n)&&Object.defineProperty(t,n,{enumerable:!0,get:s[n]})}};e.g=function(){if("object"==typeof globalThis)return globalThis;try{return this||new Function("return this")()}catch(t){if("object"==typeof window)return window}}(),e.o=(t,e)=>Object.prototype.hasOwnProperty.call(t,e);const s=(n={getContext:()=>t.getContext,getElement:()=>t.getElement,store:()=>t.store},o={},e.d(o,n),o);var n,o;function r(t){if("object"==typeof GatherPress)return t.split(".").reduce(((t,e)=>t&&t[e]),GatherPress)}function u(t,e){t.posts[e]||(t.posts[e]={eventResponses:{attending:0,waitingList:0,notAttending:0},currentUser:{status:"no_status",guests:0,anonymous:0},rsvpSelection:"attending"})}function a(t,e,s=null,n=null){["no_status","waiting_list"].includes(e.status)||fetch(r("urls.eventApiUrl")+"/rsvp",{method:"POST",headers:{"Content-Type":"application/json","X-WP-Nonce":r("misc.nonce")},body:JSON.stringify({post_id:t,status:e.status,guests:e.guests,anonymous:e.anonymous})}).then((t=>t.json())).then((e=>{e.success&&(s&&(s.posts[t]={...s.posts[t],eventResponses:{attending:e.responses.attending.count,waitingList:e.responses.waiting_list.count,notAttending:e.responses.not_attending.count},currentUser:{status:e.status,guests:e.guests,anonymous:e.anonymous},rsvpSelection:e.status}),"function"==typeof n&&n(e))})).catch((()=>{}))}const{state:i,actions:c}=(0,s.store)("gatherpress",{actions:{updateGuestCount(){const t=(0,s.getElement)(),e=(0,s.getContext)().postId||0,n=i.posts[e].currentUser;n.guests=parseInt(t.ref.value,10),u(i,e),a(e,n,i,(()=>{setTimeout((()=>{t.ref.focus()}),1)}))},updateAnonymous(){const t=(0,s.getElement)(),e=(0,s.getContext)().postId||0,n=i.posts[e].currentUser;n.anonymous=t.ref.checked?1:0,u(i,e),a(e,n,i,(()=>{setTimeout((()=>{t.ref.focus()}),1)}))},updateRsvp(t=null){var e;t&&t.preventDefault();const n=(0,s.getElement)(),o=(0,s.getContext)(),r=o?.postId||0,u=null!==(e=n.ref.getAttribute("data-set-status"))&&void 0!==e?e:"",p=i.posts[r].currentUser.status;let l="not_attending";t?["attending","waiting_list","not_attending"].includes(u)?l=u:["not_attending","no_status"].includes(p)&&(l="attending"):l=p,a(r,{status:l,guests:i.posts[r].currentUser.guests,anonymous:i.posts[r].currentUser.anonymous},i,(()=>{const t=n.ref.closest("[data-rsvp-status]"),e=t.getAttribute("data-rsvp-status"),s=t.closest(".wp-block-gatherpress-rsvp-v2");if(["not_attending","no_status"].includes(e)){const t=s.querySelector('[data-rsvp-status="attending"] .gatherpress--update-rsvp');c.openModal(null,t)}setTimeout((()=>{c.closeModal(null,n.ref)}),1)}))}},callbacks:{monitorAnonymousStatus(){const t=(0,s.getElement)(),e=(0,s.getContext)().postId||0;u(i,e),t.ref.checked=i.posts[e].currentUser.anonymous},setGuestCount(){const t=(0,s.getElement)(),e=(0,s.getContext)().postId||0;u(i,e),t.ref.value=i.posts[e].currentUser.guests},renderRsvpBlock(){const t=(0,s.getElement)(),e=(0,s.getContext)().postId||0;u(i,e);const n=JSON.parse(t.ref.getAttribute("data-user-details"));t.ref.removeAttribute("data-user-details"),n&&(i.posts[e]={...i.posts[e],currentUser:{status:n?.status||"no_status",guests:n?.guests||0,anonymous:n?.anonymous||0}}),t.ref.querySelectorAll("[data-rsvp-status]").forEach((t=>{const s=t.parentNode;t.getAttribute("data-rsvp-status")===i.posts[e].currentUser.status?(t.style.display="",s.insertBefore(t,s.firstChild)):t.style.display="none"}))},updateGuestCountDisplay(){const t=(0,s.getContext)(),e=t?.postId||0;u(i,t);const n=parseInt(i.posts[e]?.currentUser?.guests||0,10),o=(0,s.getElement)(),r=o.ref.getAttribute("data-guest-singular"),a=o.ref.getAttribute("data-guest-plural");let c="";0rsvp ) { + $user_data = $event->rsvp->get( get_current_user_id() ); + } + $filtered_data = array_intersect_key( $user_data, array_flip( array( 'status', 'guests', 'anonymous' ) ) ); + // Set dynamic attributes for interactivity. $tag->set_attribute( 'data-wp-interactive', 'gatherpress' ); $tag->set_attribute( 'data-wp-context', wp_json_encode( array( 'postId' => get_the_ID() ) ) ); + $tag->set_attribute( 'data-user-details', wp_json_encode( $filtered_data ) ); $tag->set_attribute( 'data-wp-watch', 'callbacks.renderRsvpBlock' ); } diff --git a/includes/core/classes/class-assets.php b/includes/core/classes/class-assets.php index 3ffeb0462..6a3645b11 100644 --- a/includes/core/classes/class-assets.php +++ b/includes/core/classes/class-assets.php @@ -127,6 +127,15 @@ public function add_global_object(): void { public function block_enqueue_scripts(): void { // @todo remove once new blocks are completed. wp_enqueue_style( 'dashicons' ); + + $asset = $this->get_asset_data( 'utility_style' ); + + wp_register_style( + 'gatherpress-utility-style', + $this->build . 'utility_style.css', + $asset['dependencies'], + $asset['version'] + ); } /** @@ -142,12 +151,7 @@ public function maybe_enqueue_styles( string $block_content, array $block ): str if ( 0 === strpos( $block['blockName'], 'gatherpress/' ) ) { $asset = $this->get_asset_data( 'utility_style' ); - wp_enqueue_style( - 'gatherpress-utility-style', - $this->build . 'utility_style.css', - $asset['dependencies'], - $asset['version'] - ); + wp_enqueue_style( 'gatherpress-utility-style' ); } return $block_content; @@ -270,6 +274,8 @@ public function editor_enqueue_scripts(): void { true ); + wp_enqueue_style( 'gatherpress-utility-style' ); + wp_set_script_translations( 'gatherpress-editor', 'gatherpress' ); } diff --git a/includes/core/classes/class-event-rest-api.php b/includes/core/classes/class-event-rest-api.php index 754be0c36..fa0700902 100644 --- a/includes/core/classes/class-event-rest-api.php +++ b/includes/core/classes/class-event-rest-api.php @@ -20,6 +20,7 @@ use WP_REST_Request; use WP_REST_Response; use WP_REST_Server; +use WP_User; /** * Class Event_Rest_Api. diff --git a/src/blocks/rsvp-response-v2/edit.js b/src/blocks/rsvp-response-v2/edit.js index d793ac3f3..640c482e4 100644 --- a/src/blocks/rsvp-response-v2/edit.js +++ b/src/blocks/rsvp-response-v2/edit.js @@ -17,7 +17,6 @@ import { Spinner, } from '@wordpress/components'; import { useState, useEffect } from '@wordpress/element'; -import { useSelect } from '@wordpress/data'; /** * Internal dependencies. @@ -46,14 +45,13 @@ async function fetchRsvpResponses(postId) { /** * Edit component for the GatherPress RSVP Response block. * - * @param {Object} root0 - The props object passed to the component. - * @param {string} root0.clientId - The block client ID. - * @param {Object} root0.context - Block context data containing postId and event info. + * @param {Object} root0 - The props object passed to the component. + * @param {Object} root0.context - Block context data containing postId and event info. * @since 1.0.0 * * @return {JSX.Element} The rendered edit interface for the block. */ -const Edit = ({ clientId, context }) => { +const Edit = ({ context }) => { const blockProps = useBlockProps(); const [editMode, setEditMode] = useState(false); const [showEmptyRsvpMessage, setShowEmptyRsvpMessage] = useState(false); @@ -62,38 +60,29 @@ const Edit = ({ clientId, context }) => { const [loading, setLoading] = useState(true); const [error, setError] = useState(null); const postId = context?.postId ?? null; - const innerBlocks = useSelect( - (select) => select('core/block-editor').getBlocks(clientId), - [clientId] - ); useEffect(() => { - innerBlocks.forEach((block) => { - const blockElement = global.document.getElementById( - `block-${block.clientId}` + const emptyBlocks = document.querySelectorAll( + '.gatherpress--empty-rsvp' + ); + const responseBlocks = document.querySelectorAll( + '.gatherpress--rsvp-responses' + ); + + emptyBlocks.forEach((block) => { + block.classList.toggle( + 'gatherpress--is-not-visible', + !showEmptyRsvpMessage ); + }); - if (blockElement) { - const isRsvpResponsesBlock = - block.attributes?.className?.includes( - 'gatherpress--rsvp-responses' - ); - const isEmptyRsvpBlock = block.attributes?.className?.includes( - 'gatherpress--empty-rsvp' - ); - - if (showEmptyRsvpMessage && isEmptyRsvpBlock) { - blockElement.style.display = ''; - } else if (showEmptyRsvpMessage && isRsvpResponsesBlock) { - blockElement.style.display = 'none'; - } else if (!showEmptyRsvpMessage && isEmptyRsvpBlock) { - blockElement.style.display = 'none'; - } else if (!showEmptyRsvpMessage && isRsvpResponsesBlock) { - blockElement.style.display = ''; - } - } + responseBlocks.forEach((block) => { + block.classList.toggle( + 'gatherpress--is-not-visible', + showEmptyRsvpMessage + ); }); - }, [showEmptyRsvpMessage, innerBlocks, editMode]); + }, [showEmptyRsvpMessage, responses]); // Fetch responses when postId changes. useEffect(() => { diff --git a/src/blocks/rsvp-response-v2/template.js b/src/blocks/rsvp-response-v2/template.js index 8dbe4ef20..f3380d900 100644 --- a/src/blocks/rsvp-response-v2/template.js +++ b/src/blocks/rsvp-response-v2/template.js @@ -3,6 +3,22 @@ */ import { __ } from '@wordpress/i18n'; +/* translators: %d is the count of attendees */ +const attending = __('Attending (%d)', 'gatherpress'); + +/* translators: %d is the count of users on the waiting list */ +const waitingList = __('Waiting List (%d)', 'gatherpress'); + +/* translators: %d is the count of users not attending */ +const notAttending = __('Not Attending (%d)', 'gatherpress'); + +const translations = { + attending, + waitingList, + notAttending, + noOne: __('No one is attending this event yet.', 'gatherpress'), +}; + const TEMPLATE = [ [ 'core/group', @@ -10,78 +26,43 @@ const TEMPLATE = [ style: { spacing: { blockGap: 'var:preset|spacing|20', - margin: { - bottom: 'var:preset|spacing|30', - }, + margin: { bottom: 'var:preset|spacing|30' }, }, }, - layout: { - type: 'flex', - flexWrap: 'nowrap', - }, + layout: { type: 'flex', flexWrap: 'nowrap' }, }, [ - [ - 'gatherpress/icon', - { - icon: 'groups', - }, - ], + ['gatherpress/icon', { icon: 'groups' }], [ 'gatherpress/dropdown', { actAsSelect: true, dropdownId: 'dropdown-7968ad05-cf12-41ae-8392-7fb01e166188', - // Translators: %d is the count of attendees. - label: __('Attending (%d)', 'gatherpress'), - metadata: { - // Translators: %d is the count of attendees. - name: __('Attending (%d)', 'gatherpress'), - }, + label: translations.attending, + metadata: { name: translations.attending }, }, [ [ 'gatherpress/dropdown-item', { - text: - '' + - // Translators: %d is the count of attendees. - __('Attending (%d)', 'gatherpress') + - '', - metadata: { - // Translators: %d is the count of attendees. - name: __('Attending (%d)', 'gatherpress'), - }, + text: `${translations.attending}`, + metadata: { name: translations.attending }, className: 'gatherpress--rsvp-attending', }, ], [ 'gatherpress/dropdown-item', { - text: - '' + - // Translators: %d is the count of users on the waiting list. - __('Waiting List (%d)', 'gatherpress') + - '', - metadata: { - // Translators: %d is the count of users on the waiting list. - name: __('Waiting List (%d)', 'gatherpress'), - }, + text: `${translations.waitingList}`, + metadata: { name: translations.waitingList }, className: 'gatherpress--rsvp-waiting-list', }, ], [ 'gatherpress/dropdown-item', { - text: - '' + - // Translators: %d is the count of users not attending. - __('Not Attending (%d)', 'gatherpress') + - '', - metadata: { - // Translators: %d is the count of users not attending. - name: __('Not Attending (%d)', 'gatherpress'), - }, + text: `${translations.notAttending}`, + metadata: { name: translations.notAttending }, className: 'gatherpress--rsvp-not-attending', }, ], @@ -106,22 +87,10 @@ const TEMPLATE = [ [ 'core/group', { - metadata: { - name: __('Empty RSVP', 'gatherpress'), - }, - className: 'gatherpress--empty-rsvp', + metadata: { name: __('Empty RSVP', 'gatherpress') }, + className: 'gatherpress--empty-rsvp gatherpress--is-not-visible', }, - [ - [ - 'core/paragraph', - { - content: __( - 'No one is attending this event yet.', - 'gatherpress' - ), - }, - ], - ], + [['core/paragraph', { content: translations.noOne }]], ], ]; diff --git a/src/blocks/rsvp-v2/view.js b/src/blocks/rsvp-v2/view.js index 8a5b77d62..339d466c3 100644 --- a/src/blocks/rsvp-v2/view.js +++ b/src/blocks/rsvp-v2/view.js @@ -6,7 +6,6 @@ import { store, getElement, getContext } from '@wordpress/interactivity'; /** * Internal dependencies. */ -import { getFromGlobal } from '../../helpers/globals'; import { initPostContext, sendRsvpApiRequest, @@ -136,9 +135,26 @@ const { state, actions } = store('gatherpress', { renderRsvpBlock() { const element = getElement(); const context = getContext(); - const status = - state.posts[context.postId]?.currentUser?.status ?? - getFromGlobal('eventDetails.currentUser.status'); + const postId = context.postId || 0; + + initPostContext(state, postId); + + const userDetails = JSON.parse( + element.ref.getAttribute('data-user-details') + ); + // Delete attribute after setting variable. This is just to kick things off... + element.ref.removeAttribute('data-user-details'); + + if (userDetails) { + state.posts[postId] = { + ...state.posts[postId], + currentUser: { + status: userDetails?.status || 'no_status', + guests: userDetails?.guests || 0, + anonymous: userDetails?.anonymous || 0, + }, + }; + } const innerBlocks = element.ref.querySelectorAll('[data-rsvp-status]'); @@ -146,7 +162,10 @@ const { state, actions } = store('gatherpress', { innerBlocks.forEach((innerBlock) => { const parent = innerBlock.parentNode; - if (innerBlock.getAttribute('data-rsvp-status') === status) { + if ( + innerBlock.getAttribute('data-rsvp-status') === + state.posts[postId].currentUser.status + ) { innerBlock.style.display = ''; // Move the visible block to the start of its parent. diff --git a/src/helpers/interactivity.js b/src/helpers/interactivity.js index 80767ef4f..ab914320f 100644 --- a/src/helpers/interactivity.js +++ b/src/helpers/interactivity.js @@ -41,19 +41,17 @@ import { getFromGlobal } from './globals'; * // } */ export function initPostContext(state, postId) { - const eventDetails = getFromGlobal('eventDetails'); - if (!state.posts[postId]) { state.posts[postId] = { eventResponses: { - attending: eventDetails.responses.attending.count || 0, - waitingList: eventDetails.responses.waiting_list.count || 0, - notAttending: eventDetails.responses.not_attending.count || 0, + attending: 0, + waitingList: 0, + notAttending: 0, }, currentUser: { - status: eventDetails.currentUser?.status || 'no_status', - guests: eventDetails.currentUser?.guests || 0, - anonymous: eventDetails.currentUser?.anonymous || 0, + status: 'no_status', + guests: 0, + anonymous: 0, }, rsvpSelection: 'attending', }; @@ -76,7 +74,6 @@ export function initPostContext(state, postId) { * @param {number} [args.guests=0] - The number of additional guests. * @param {boolean} [args.anonymous=false] - Whether the RSVP is anonymous. * @param {Object} [state=null] - A state object to update with the API response data. - * Should contain `activePostId` and `posts` structure. * @param {Function} [onSuccess=null] - A callback function to execute on a successful API response. * Receives the API response as its argument. * @@ -119,7 +116,6 @@ export function sendRsvpApiRequest( .then((res) => { if (res.success) { if (state) { - state.activePostId = postId; state.posts[postId] = { ...state.posts[postId], eventResponses: {