From 330dc719ad724c2bc6da6baaa88bfb304d07f3b5 Mon Sep 17 00:00:00 2001 From: Mike Auteri Date: Tue, 27 Aug 2024 00:08:55 -0400 Subject: [PATCH] Started work on saving datetimes as meta; fixed bug that called datetime endpoint many times on save rather than just once. --- build/blocks/event-date/index.asset.php | 2 +- build/blocks/event-date/index.js | 4 +- build/panels.asset.php | 2 +- build/panels.js | 4 +- includes/core/classes/class-event-setup.php | 45 +++++++++++++++++++++ includes/core/classes/class-event.php | 23 +++++++++++ src/components/DateTimeRange.js | 2 +- 7 files changed, 75 insertions(+), 7 deletions(-) diff --git a/build/blocks/event-date/index.asset.php b/build/blocks/event-date/index.asset.php index 0c0d6956d..830100ab8 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-api-fetch', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-data', 'wp-date', 'wp-element', 'wp-i18n'), 'version' => '0f22ffb28fbe7d004c9f'); + array('moment', 'react-jsx-runtime', 'wp-api-fetch', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-data', 'wp-date', 'wp-element', 'wp-i18n'), 'version' => '00019915fe473a5617eb'); diff --git a/build/blocks/event-date/index.js b/build/blocks/event-date/index.js index 9f7598a87..018fc8d1b 100644 --- a/build/blocks/event-date/index.js +++ b/build/blocks/event-date/index.js @@ -1,2 +1,2 @@ -(()=>{"use strict";var e,t={110:(e,t,n)=>{const r=window.wp.blocks,s=window.moment;var i=n.n(s);const a=window.wp.i18n,o=window.wp.blockEditor,d=window.wp.components,c=window.wp.element,l=(e,t="")=>{for(const[n,r]of Object.entries(e)){let e=n;t&&(e+="_"+String(t));const s=new CustomEvent(e,{detail:r});dispatchEvent(s)}},m=window.wp.data,p=window.wp.apiFetch;var u=n.n(p);function h(){(0,m.dispatch)("core/editor")?.editPost({meta:{_non_existing_meta:!0}})}function f(e){if("object"==typeof GatherPress)return e.split(".").reduce(((e,t)=>e&&e[t]),GatherPress)}function g(e,t){if("object"!=typeof GatherPress)return;const n=e.split("."),r=n.pop();n.reduce(((e,t)=>{var n;return null!==(n=e[t])&&void 0!==n?n:e[t]={}}),GatherPress)[r]=t}function v(){const e=i().tz(f("eventDetails.dateTime.datetime_end"),S());return"gatherpress_event"===(0,m.select)("core/editor")?.getCurrentPostType()&&i().tz(S()).valueOf()>e.valueOf()}function T(){const e="gatherpress_event_past",t=(0,m.dispatch)("core/notices");t.removeNotice(e),v()&&t.createNotice("warning",(0,a.__)("This event has already passed.","gatherpress"),{id:e,isDismissible:!1})}const x=window.wp.date,j=window.ReactJSXRuntime,D="YYYY-MM-DDTHH:mm:ss",_="YYYY-MM-DD HH:mm:ss",w=i().tz(S()).add(1,"day").set("hour",18).set("minute",0).set("second",0).format(D),z=i().tz(w,S()).add(2,"hours").format(D);function b(){return k(f("settings.dateFormat"))+" "+k(f("settings.timeFormat"))}function S(e=f("eventDetails.dateTime.timezone")){return i().tz.zone(e)?e:(0,a.__)("GMT","gatherpress")}function y(e=""){const t=/^([+-])(\d{2}):(00|15|30|45)$/,n=e.replace(t,"$1");return n!==e?"UTC"+n+parseInt(e.replace(t,"$2")).toString()+e.replace(t,"$3").replace("00","").replace("15",".25").replace("30",".5").replace("45",".75"):e}function O(e,t=null){!function(e){const t=i().tz(f("eventDetails.dateTime.datetime_end"),S()).valueOf(),n=i().tz(e,S()).valueOf();n>=t&&E(i().tz(n,S()).add(2,"hours").format(D))}(e),g("eventDetails.dateTime.datetime_start",e),"function"==typeof t&&t(e),h()}function E(e,t=null){!function(e){const t=i().tz(f("eventDetails.dateTime.datetime_start"),S()).valueOf(),n=i().tz(e,S()).valueOf();n<=t&&O(i().tz(n,S()).subtract(2,"hours").format(D))}(e),g("eventDetails.dateTime.datetime_end",e),null!==t&&t(e),h()}function P(){const e=(0,m.select)("core/editor").isSavingPost(),t=(0,m.select)("core/editor").isAutosavingPost();"gatherpress_event"===(0,m.select)("core/editor")?.getCurrentPostType()&&e&&!t&&u()({path:f("urls.eventRestApi")+"/datetime",method:"POST",data:{post_id:f("eventDetails.postId"),datetime_start:i().tz(f("eventDetails.dateTime.datetime_start"),S()).format(_),datetime_end:i().tz(f("eventDetails.dateTime.datetime_end"),S()).format(_),timezone:f("eventDetails.dateTime.timezone"),_wpnonce:f("misc.nonce")}}).then((()=>{!function(){const e="gatherpress_event_communcation",t=(0,m.dispatch)("core/notices");t.removeNotice(e),"publish"!==(0,m.select)("core/editor").getEditedPostAttribute("status")||v()||t.createNotice("success",(0,a.__)("Send an event update to members via email?","gatherpress"),{id:e,isDismissible:!0,actions:[{onClick:()=>{l({setOpen:!0})},label:(0,a.__)("Compose Message","gatherpress")}]})}()}))}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,n,r)=>{const s=r[n-1];return e in t&&"\\"!==s?t[e]:e})).join("")}const C=e=>{const{isSelected:t}=e,n=t?"none":"block";return(0,j.jsxs)("div",{style:{position:"relative"},children:[e.children,(0,j.jsx)("div",{style:{position:"absolute",top:"0",right:"0",bottom:"0",left:"0",display:n}})]})},M=e=>{const{dateTimeStart:t}=e;return i().tz(t,S()).format(b())},Y=e=>{const{dateTimeEnd:t}=e;return i().tz(t,S()).format(b())},F=e=>{const{dateTimeStart:t,setDateTimeStart:n}=e,r=(0,x.getSettings)(),s=/a(?!\\)/i.test(r.formats.time.toLowerCase().replace(/\\\\/g,"").split("").reverse().join(""));return(0,j.jsx)(d.DateTimePicker,{currentDate:t,onChange:e=>O(e,n),is12Hour:s})},$=e=>{const{dateTimeEnd:t,setDateTimeEnd:n}=e,r=(0,x.getSettings)(),s=/a(?!\\)/i.test(r.formats.time.toLowerCase().replace(/\\\\/g,"").split("").reverse().join(""));return(0,j.jsx)(d.DateTimePicker,{currentDate:t,onChange:e=>E(e,n),is12Hour:s})},I=e=>{const{dateTimeStart:t,setDateTimeStart:n}=e;return(0,c.useEffect)((()=>{n(i().tz(function(){let e=f("eventDetails.dateTime.datetime_start");return e=""!==e?i().tz(e,S()).format(D):w,g("eventDetails.dateTime.datetime_start",e),e}(),S()).format(D)),l({setDateTimeStart:t}),T()})),(0,j.jsx)(d.PanelRow,{children:(0,j.jsxs)(d.Flex,{direction:"column",gap:"0",children:[(0,j.jsx)(d.FlexItem,{children:(0,j.jsx)("label",{htmlFor:"gatherpress-datetime-start",children:(0,a.__)("Start","gatherpress")})}),(0,j.jsx)(d.FlexItem,{children:(0,j.jsx)(d.Dropdown,{popoverProps:{placement:"bottom-end"},renderToggle:({isOpen:e,onToggle:n})=>(0,j.jsx)(d.Button,{id:"gatherpress-datetime-start",onClick:n,"aria-expanded":e,isLink:!0,children:(0,j.jsx)(M,{dateTimeStart:t})}),renderContent:()=>(0,j.jsx)(F,{dateTimeStart:t,setDateTimeStart:n})})})]})})},H=e=>{const{dateTimeEnd:t,setDateTimeEnd:n}=e;return(0,c.useEffect)((()=>{n(i().tz(function(){let e=f("eventDetails.dateTime.datetime_end");return e=""!==e?i().tz(e,S()).format(D):z,g("eventDetails.dateTime.datetime_end",e),e}(),S()).format(D)),l({setDateTimeEnd:t}),T()})),(0,j.jsx)(d.PanelRow,{children:(0,j.jsxs)(d.Flex,{direction:"column",gap:"0",children:[(0,j.jsx)(d.FlexItem,{children:(0,j.jsx)("label",{htmlFor:"gatherpress-datetime-end",children:(0,a.__)("End","gatherpress")})}),(0,j.jsx)(d.FlexItem,{children:(0,j.jsx)(d.Dropdown,{popoverProps:{placement:"bottom-end"},renderToggle:({isOpen:e,onToggle:n})=>(0,j.jsx)(d.Button,{id:"gatherpress-datetime-end",onClick:n,"aria-expanded":e,isLink:!0,children:(0,j.jsx)(Y,{dateTimeEnd:t})}),renderContent:()=>(0,j.jsx)($,{dateTimeEnd:t,setDateTimeEnd:n})})})]})})},G=e=>{const{timezone:t,setTimezone:n}=e,r=f("misc.timezoneChoices");return(0,c.useEffect)((()=>{n(f("eventDetails.dateTime.timezone"))}),[n]),(0,c.useEffect)((()=>{l({setTimezone:f("eventDetails.dateTime.timezone")})})),(0,j.jsx)(d.PanelRow,{children:(0,j.jsx)(d.SelectControl,{label:(0,a.__)("Time Zone","gatherpress"),value:y(t),onChange:e=>{e=function(e=""){const t=/^UTC([+-])(\d+)(.\d+)?$/,n=e.replace(t,"$1");if(n!==e){const r=e.replace(t,"$2").padStart(2,"0");let s=e.replace(t,"$3");return""===s&&(s=":00"),s=s.replace(".25",":15").replace(".5",":30").replace(".75",":45"),n+r+s}return e}(e),n(e),g("eventDetails.dateTime.timezone",e),h()},children:Object.keys(r).map((e=>(0,j.jsx)("optgroup",{label:e,children:Object.keys(r[e]).map((t=>(0,j.jsx)("option",{value:t,children:r[e][t]},t)))},e)))})})},N=()=>{const[e,t]=(0,c.useState)(),[n,r]=(0,c.useState)(),[s,i]=(0,c.useState)();return(0,m.subscribe)(P),(0,j.jsxs)(j.Fragment,{children:[(0,j.jsx)("h3",{children:(0,a.__)("Date & time","gatherpress")}),(0,j.jsx)(I,{dateTimeStart:e,setDateTimeStart:t}),(0,j.jsx)(H,{dateTimeEnd:n,setDateTimeEnd:r}),(0,j.jsx)(G,{timezone:s,setTimezone:i})]})},B=(e,t,n)=>{const r=k(f("settings.dateFormat")),s=k(f("settings.timeFormat")),o=f("settings.showTimezone")?"z":"",d=r+" "+s,c=S(n);let l=r+" "+s+" "+o;return i().tz(e,c).format(r)===i().tz(t,c).format(r)&&(l=s+" "+o),(0,a.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,a.__)("%1$s to %2$s %3$s","gatherpress"),i().tz(e,c).format(d),i().tz(t,c).format(l),(m=S(m=c),(0,a.__)("GMT","gatherpress")!==m?"":function(e=""){return e.replace(":","")}(f("eventDetails.dateTime.timezone"))));var m},L=JSON.parse('{"$schema":"https://schemas.wp.org/trunk/block.json","apiVersion":2,"name":"gatherpress/event-date","version":"1.0.1","title":"Event Date","category":"gatherpress","icon":"clock","example":{},"description":"Displays the date and time for an event.","attributes":{"eventEnd":{"type":"string"},"eventStart":{"type":"string"}},"supports":{"html":false},"textdomain":"gatherpress","editorScript":"file:./index.js","style":"file:./style-index.css","render":"file:./render.php"}');(0,r.registerBlockType)(L,{edit:()=>{const e=(0,o.useBlockProps)(),[t,n]=(0,c.useState)(w),[r,s]=(0,c.useState)(z),[i,a]=(0,c.useState)(S());return((e,t="")=>{for(const[n,r]of Object.entries(e)){let e=n;t&&(e+="_"+String(t)),addEventListener(e,(e=>{r(e.detail)}),!1)}})({setDateTimeEnd:s,setDateTimeStart:n,setTimezone:a}),(0,j.jsx)("div",{...e,children:(0,j.jsx)(C,{children:(0,j.jsxs)(d.Flex,{justify:"normal",align:"center",gap:"4",children:[(0,j.jsx)(d.FlexItem,{display:"flex",className:"gatherpress-event-date__icon",children:(0,j.jsx)(d.Icon,{icon:"clock"})}),(0,j.jsx)(d.FlexItem,{children:B(t,r,i)}),"string"==typeof(0,m.select)("core/editor")?.getCurrentPostType()&&(0,j.jsx)(o.InspectorControls,{children:(0,j.jsx)(d.PanelBody,{children:(0,j.jsx)(N,{})})})]})})})},save:()=>null})}},n={};function r(e){var s=n[e];if(void 0!==s)return s.exports;var i=n[e]={exports:{}};return t[e](i,i.exports,r),i.exports}r.m=t,e=[],r.O=(t,n,s,i)=>{if(!n){var a=1/0;for(l=0;l=i)&&Object.keys(r.O).every((e=>r.O[e](n[d])))?n.splice(d--,1):(o=!1,i0&&e[l-1][2]>i;l--)e[l]=e[l-1];e[l]=[n,s,i]},r.n=e=>{var t=e&&e.__esModule?()=>e.default:()=>e;return r.d(t,{a:t}),t},r.d=(e,t)=>{for(var n in t)r.o(t,n)&&!r.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:t[n]})},r.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),(()=>{var e={532:0,4:0};r.O.j=t=>0===e[t];var t=(t,n)=>{var s,i,[a,o,d]=n,c=0;if(a.some((t=>0!==e[t]))){for(s in o)r.o(o,s)&&(r.m[s]=o[s]);if(d)var l=d(r)}for(t&&t(n);cr(110)));s=r.O(s)})(); \ No newline at end of file +(()=>{"use strict";var e,t={110:(e,t,n)=>{const r=window.wp.blocks,s=window.moment;var i=n.n(s);const a=window.wp.i18n,o=window.wp.blockEditor,d=window.wp.components,c=window.wp.element,l=(e,t="")=>{for(const[n,r]of Object.entries(e)){let e=n;t&&(e+="_"+String(t));const s=new CustomEvent(e,{detail:r});dispatchEvent(s)}},m=window.wp.data,p=window.wp.apiFetch;var u=n.n(p);function h(){(0,m.dispatch)("core/editor")?.editPost({meta:{_non_existing_meta:!0}})}function f(e){if("object"==typeof GatherPress)return e.split(".").reduce(((e,t)=>e&&e[t]),GatherPress)}function g(e,t){if("object"!=typeof GatherPress)return;const n=e.split("."),r=n.pop();n.reduce(((e,t)=>{var n;return null!==(n=e[t])&&void 0!==n?n:e[t]={}}),GatherPress)[r]=t}function v(){const e=i().tz(f("eventDetails.dateTime.datetime_end"),b());return"gatherpress_event"===(0,m.select)("core/editor")?.getCurrentPostType()&&i().tz(b()).valueOf()>e.valueOf()}function T(){const e="gatherpress_event_past",t=(0,m.dispatch)("core/notices");t.removeNotice(e),v()&&t.createNotice("warning",(0,a.__)("This event has already passed.","gatherpress"),{id:e,isDismissible:!1})}const x=window.wp.date,j=window.ReactJSXRuntime,D="YYYY-MM-DDTHH:mm:ss",_="YYYY-MM-DD HH:mm:ss",w=i().tz(b()).add(1,"day").set("hour",18).set("minute",0).set("second",0).format(D),z=i().tz(w,b()).add(2,"hours").format(D);function S(){return P(f("settings.dateFormat"))+" "+P(f("settings.timeFormat"))}function b(e=f("eventDetails.dateTime.timezone")){return i().tz.zone(e)?e:(0,a.__)("GMT","gatherpress")}function y(e=""){const t=/^([+-])(\d{2}):(00|15|30|45)$/,n=e.replace(t,"$1");return n!==e?"UTC"+n+parseInt(e.replace(t,"$2")).toString()+e.replace(t,"$3").replace("00","").replace("15",".25").replace("30",".5").replace("45",".75"):e}function O(e,t=null){!function(e){const t=i().tz(f("eventDetails.dateTime.datetime_end"),b()).valueOf(),n=i().tz(e,b()).valueOf();n>=t&&E(i().tz(n,b()).add(2,"hours").format(D))}(e),g("eventDetails.dateTime.datetime_start",e),"function"==typeof t&&t(e),h()}function E(e,t=null){!function(e){const t=i().tz(f("eventDetails.dateTime.datetime_start"),b()).valueOf(),n=i().tz(e,b()).valueOf();n<=t&&O(i().tz(n,b()).subtract(2,"hours").format(D))}(e),g("eventDetails.dateTime.datetime_end",e),null!==t&&t(e),h()}function P(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,n,r)=>{const s=r[n-1];return e in t&&"\\"!==s?t[e]:e})).join("")}const k=e=>{const{isSelected:t}=e,n=t?"none":"block";return(0,j.jsxs)("div",{style:{position:"relative"},children:[e.children,(0,j.jsx)("div",{style:{position:"absolute",top:"0",right:"0",bottom:"0",left:"0",display:n}})]})},C=e=>{const{dateTimeStart:t}=e;return i().tz(t,b()).format(S())},M=e=>{const{dateTimeEnd:t}=e;return i().tz(t,b()).format(S())},Y=e=>{const{dateTimeStart:t,setDateTimeStart:n}=e,r=(0,x.getSettings)(),s=/a(?!\\)/i.test(r.formats.time.toLowerCase().replace(/\\\\/g,"").split("").reverse().join(""));return(0,j.jsx)(d.DateTimePicker,{currentDate:t,onChange:e=>O(e,n),is12Hour:s})},F=e=>{const{dateTimeEnd:t,setDateTimeEnd:n}=e,r=(0,x.getSettings)(),s=/a(?!\\)/i.test(r.formats.time.toLowerCase().replace(/\\\\/g,"").split("").reverse().join(""));return(0,j.jsx)(d.DateTimePicker,{currentDate:t,onChange:e=>E(e,n),is12Hour:s})},$=e=>{const{dateTimeStart:t,setDateTimeStart:n}=e;return(0,c.useEffect)((()=>{n(i().tz(function(){let e=f("eventDetails.dateTime.datetime_start");return e=""!==e?i().tz(e,b()).format(D):w,g("eventDetails.dateTime.datetime_start",e),e}(),b()).format(D)),l({setDateTimeStart:t}),T()})),(0,j.jsx)(d.PanelRow,{children:(0,j.jsxs)(d.Flex,{direction:"column",gap:"0",children:[(0,j.jsx)(d.FlexItem,{children:(0,j.jsx)("label",{htmlFor:"gatherpress-datetime-start",children:(0,a.__)("Start","gatherpress")})}),(0,j.jsx)(d.FlexItem,{children:(0,j.jsx)(d.Dropdown,{popoverProps:{placement:"bottom-end"},renderToggle:({isOpen:e,onToggle:n})=>(0,j.jsx)(d.Button,{id:"gatherpress-datetime-start",onClick:n,"aria-expanded":e,isLink:!0,children:(0,j.jsx)(C,{dateTimeStart:t})}),renderContent:()=>(0,j.jsx)(Y,{dateTimeStart:t,setDateTimeStart:n})})})]})})},I=e=>{const{dateTimeEnd:t,setDateTimeEnd:n}=e;return(0,c.useEffect)((()=>{n(i().tz(function(){let e=f("eventDetails.dateTime.datetime_end");return e=""!==e?i().tz(e,b()).format(D):z,g("eventDetails.dateTime.datetime_end",e),e}(),b()).format(D)),l({setDateTimeEnd:t}),T()})),(0,j.jsx)(d.PanelRow,{children:(0,j.jsxs)(d.Flex,{direction:"column",gap:"0",children:[(0,j.jsx)(d.FlexItem,{children:(0,j.jsx)("label",{htmlFor:"gatherpress-datetime-end",children:(0,a.__)("End","gatherpress")})}),(0,j.jsx)(d.FlexItem,{children:(0,j.jsx)(d.Dropdown,{popoverProps:{placement:"bottom-end"},renderToggle:({isOpen:e,onToggle:n})=>(0,j.jsx)(d.Button,{id:"gatherpress-datetime-end",onClick:n,"aria-expanded":e,isLink:!0,children:(0,j.jsx)(M,{dateTimeEnd:t})}),renderContent:()=>(0,j.jsx)(F,{dateTimeEnd:t,setDateTimeEnd:n})})})]})})},H=e=>{const{timezone:t,setTimezone:n}=e,r=f("misc.timezoneChoices");return(0,c.useEffect)((()=>{n(f("eventDetails.dateTime.timezone"))}),[n]),(0,c.useEffect)((()=>{l({setTimezone:f("eventDetails.dateTime.timezone")})})),(0,j.jsx)(d.PanelRow,{children:(0,j.jsx)(d.SelectControl,{label:(0,a.__)("Time Zone","gatherpress"),value:y(t),onChange:e=>{e=function(e=""){const t=/^UTC([+-])(\d+)(.\d+)?$/,n=e.replace(t,"$1");if(n!==e){const r=e.replace(t,"$2").padStart(2,"0");let s=e.replace(t,"$3");return""===s&&(s=":00"),s=s.replace(".25",":15").replace(".5",":30").replace(".75",":45"),n+r+s}return e}(e),n(e),g("eventDetails.dateTime.timezone",e),h()},children:Object.keys(r).map((e=>(0,j.jsx)("optgroup",{label:e,children:Object.keys(r[e]).map((t=>(0,j.jsx)("option",{value:t,children:r[e][t]},t)))},e)))})})},G=()=>{const[e,t]=(0,c.useState)(),[n,r]=(0,c.useState)(),[s,o]=(0,c.useState)();return function(){const e=(0,m.select)("core/editor").isSavingPost(),t=(0,m.select)("core/editor").isAutosavingPost();"gatherpress_event"===(0,m.select)("core/editor")?.getCurrentPostType()&&e&&!t&&u()({path:f("urls.eventRestApi")+"/datetime",method:"POST",data:{post_id:f("eventDetails.postId"),datetime_start:i().tz(f("eventDetails.dateTime.datetime_start"),b()).format(_),datetime_end:i().tz(f("eventDetails.dateTime.datetime_end"),b()).format(_),timezone:f("eventDetails.dateTime.timezone"),_wpnonce:f("misc.nonce")}}).then((()=>{!function(){const e="gatherpress_event_communcation",t=(0,m.dispatch)("core/notices");t.removeNotice(e),"publish"!==(0,m.select)("core/editor").getEditedPostAttribute("status")||v()||t.createNotice("success",(0,a.__)("Send an event update to members via email?","gatherpress"),{id:e,isDismissible:!0,actions:[{onClick:()=>{l({setOpen:!0})},label:(0,a.__)("Compose Message","gatherpress")}]})}()}))}(),(0,j.jsxs)(j.Fragment,{children:[(0,j.jsx)("h3",{children:(0,a.__)("Date & time","gatherpress")}),(0,j.jsx)($,{dateTimeStart:e,setDateTimeStart:t}),(0,j.jsx)(I,{dateTimeEnd:n,setDateTimeEnd:r}),(0,j.jsx)(H,{timezone:s,setTimezone:o})]})},N=(e,t,n)=>{const r=P(f("settings.dateFormat")),s=P(f("settings.timeFormat")),o=f("settings.showTimezone")?"z":"",d=r+" "+s,c=b(n);let l=r+" "+s+" "+o;return i().tz(e,c).format(r)===i().tz(t,c).format(r)&&(l=s+" "+o),(0,a.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,a.__)("%1$s to %2$s %3$s","gatherpress"),i().tz(e,c).format(d),i().tz(t,c).format(l),(m=b(m=c),(0,a.__)("GMT","gatherpress")!==m?"":function(e=""){return e.replace(":","")}(f("eventDetails.dateTime.timezone"))));var m},B=JSON.parse('{"$schema":"https://schemas.wp.org/trunk/block.json","apiVersion":2,"name":"gatherpress/event-date","version":"1.0.1","title":"Event Date","category":"gatherpress","icon":"clock","example":{},"description":"Displays the date and time for an event.","attributes":{"eventEnd":{"type":"string"},"eventStart":{"type":"string"}},"supports":{"html":false},"textdomain":"gatherpress","editorScript":"file:./index.js","style":"file:./style-index.css","render":"file:./render.php"}');(0,r.registerBlockType)(B,{edit:()=>{const e=(0,o.useBlockProps)(),[t,n]=(0,c.useState)(w),[r,s]=(0,c.useState)(z),[i,a]=(0,c.useState)(b());return((e,t="")=>{for(const[n,r]of Object.entries(e)){let e=n;t&&(e+="_"+String(t)),addEventListener(e,(e=>{r(e.detail)}),!1)}})({setDateTimeEnd:s,setDateTimeStart:n,setTimezone:a}),(0,j.jsx)("div",{...e,children:(0,j.jsx)(k,{children:(0,j.jsxs)(d.Flex,{justify:"normal",align:"center",gap:"4",children:[(0,j.jsx)(d.FlexItem,{display:"flex",className:"gatherpress-event-date__icon",children:(0,j.jsx)(d.Icon,{icon:"clock"})}),(0,j.jsx)(d.FlexItem,{children:N(t,r,i)}),"string"==typeof(0,m.select)("core/editor")?.getCurrentPostType()&&(0,j.jsx)(o.InspectorControls,{children:(0,j.jsx)(d.PanelBody,{children:(0,j.jsx)(G,{})})})]})})})},save:()=>null})}},n={};function r(e){var s=n[e];if(void 0!==s)return s.exports;var i=n[e]={exports:{}};return t[e](i,i.exports,r),i.exports}r.m=t,e=[],r.O=(t,n,s,i)=>{if(!n){var a=1/0;for(l=0;l=i)&&Object.keys(r.O).every((e=>r.O[e](n[d])))?n.splice(d--,1):(o=!1,i0&&e[l-1][2]>i;l--)e[l]=e[l-1];e[l]=[n,s,i]},r.n=e=>{var t=e&&e.__esModule?()=>e.default:()=>e;return r.d(t,{a:t}),t},r.d=(e,t)=>{for(var n in t)r.o(t,n)&&!r.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:t[n]})},r.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),(()=>{var e={532:0,4:0};r.O.j=t=>0===e[t];var t=(t,n)=>{var s,i,[a,o,d]=n,c=0;if(a.some((t=>0!==e[t]))){for(s in o)r.o(o,s)&&(r.m[s]=o[s]);if(d)var l=d(r)}for(t&&t(n);cr(110)));s=r.O(s)})(); \ No newline at end of file diff --git a/build/panels.asset.php b/build/panels.asset.php index 7110f9cf5..6357ae25a 100644 --- a/build/panels.asset.php +++ b/build/panels.asset.php @@ -1 +1 @@ - array('moment', 'react-jsx-runtime', 'wp-api-fetch', 'wp-components', 'wp-compose', 'wp-data', 'wp-date', 'wp-edit-post', 'wp-element', 'wp-i18n', 'wp-plugins'), 'version' => '052bad33e07326687357'); + array('moment', 'react-jsx-runtime', 'wp-api-fetch', 'wp-components', 'wp-compose', 'wp-data', 'wp-date', 'wp-edit-post', 'wp-element', 'wp-i18n', 'wp-plugins'), 'version' => 'fd8759db317610523313'); diff --git a/build/panels.js b/build/panels.js index 00efa2d63..8ddc4c9b5 100644 --- a/build/panels.js +++ b/build/panels.js @@ -1,2 +1,2 @@ -(()=>{"use strict";var e={n:t=>{var s=t&&t.__esModule?()=>t.default:()=>t;return e.d(s,{a:s}),s},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]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t)};const t=window.wp.i18n,s=window.wp.data,n=window.wp.components,r=window.wp.plugins,i=window.wp.editPost,a=window.moment;var o=e.n(a);const l=window.wp.apiFetch;var c=e.n(l);const d=window.wp.element;function u(){(0,s.dispatch)("core/editor")?.editPost({meta:{_non_existing_meta:!0}})}function m(e){if("object"==typeof GatherPress)return e.split(".").reduce(((e,t)=>e&&e[t]),GatherPress)}function p(e,t){if("object"!=typeof GatherPress)return;const s=e.split("."),n=s.pop();s.reduce(((e,t)=>{var s;return null!==(s=e[t])&&void 0!==s?s:e[t]={}}),GatherPress)[n]=t}const g=window.wp.date,h=window.ReactJSXRuntime,_="YYYY-MM-DDTHH:mm:ss",v="YYYY-MM-DD HH:mm:ss",x=o().tz(b()).add(1,"day").set("hour",18).set("minute",0).set("second",0).format(_),f=o().tz(x,b()).add(2,"hours").format(_);function j(){return w(m("settings.dateFormat"))+" "+w(m("settings.timeFormat"))}function b(e=m("eventDetails.dateTime.timezone")){return o().tz.zone(e)?e:(0,t.__)("GMT","gatherpress")}function S(e=""){const t=/^([+-])(\d{2}):(00|15|30|45)$/,s=e.replace(t,"$1");return s!==e?"UTC"+s+parseInt(e.replace(t,"$2")).toString()+e.replace(t,"$3").replace("00","").replace("15",".25").replace("30",".5").replace("45",".75"):e}function T(e,t=null){!function(e){const t=o().tz(m("eventDetails.dateTime.datetime_end"),b()).valueOf(),s=o().tz(e,b()).valueOf();s>=t&&P(o().tz(s,b()).add(2,"hours").format(_))}(e),p("eventDetails.dateTime.datetime_start",e),"function"==typeof t&&t(e),u()}function P(e,t=null){!function(e){const t=o().tz(m("eventDetails.dateTime.datetime_start"),b()).valueOf(),s=o().tz(e,b()).valueOf();s<=t&&T(o().tz(s,b()).subtract(2,"hours").format(_))}(e),p("eventDetails.dateTime.datetime_end",e),null!==t&&t(e),u()}function D(){const e=(0,s.select)("core/editor").isSavingPost(),n=(0,s.select)("core/editor").isAutosavingPost();k()&&e&&!n&&c()({path:m("urls.eventRestApi")+"/datetime",method:"POST",data:{post_id:m("eventDetails.postId"),datetime_start:o().tz(m("eventDetails.dateTime.datetime_start"),b()).format(v),datetime_end:o().tz(m("eventDetails.dateTime.datetime_end"),b()).format(v),timezone:m("eventDetails.dateTime.timezone"),_wpnonce:m("misc.nonce")}}).then((()=>{!function(){const e="gatherpress_event_communcation",n=(0,s.dispatch)("core/notices");n.removeNotice(e),"publish"!==(0,s.select)("core/editor").getEditedPostAttribute("status")||z()||n.createNotice("success",(0,t.__)("Send an event update to members via email?","gatherpress"),{id:e,isDismissible:!0,actions:[{onClick:()=>{C({setOpen:!0})},label:(0,t.__)("Compose Message","gatherpress")}]})}()}))}function w(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,s,n)=>{const r=n[s-1];return e in t&&"\\"!==r?t[e]:e})).join("")}const C=(e,t="")=>{for(const[s,n]of Object.entries(e)){let e=s;t&&(e+="_"+String(t));const r=new CustomEvent(e,{detail:n});dispatchEvent(r)}},E=(e,t="")=>{for(const[s,n]of Object.entries(e)){let e=s;t&&(e+="_"+String(t)),addEventListener(e,(e=>{n(e.detail)}),!1)}};function k(){return"gatherpress_event"===(0,s.select)("core/editor")?.getCurrentPostType()}function z(){const e=o().tz(m("eventDetails.dateTime.datetime_end"),b());return"gatherpress_event"===(0,s.select)("core/editor")?.getCurrentPostType()&&o().tz(b()).valueOf()>e.valueOf()}function N(){const e="gatherpress_event_past",n=(0,s.dispatch)("core/notices");n.removeNotice(e),z()&&n.createNotice("warning",(0,t.__)("This event has already passed.","gatherpress"),{id:e,isDismissible:!1})}const y=()=>{const{editPost:e,unlockPostSaving:r}=(0,s.useDispatch)("core/editor"),i=(0,s.useSelect)((e=>e("core/editor").isCleanNewPost()),[]);let a=(0,s.useSelect)((e=>e("core/editor").getEditedPostAttribute("meta").gatherpress_enable_anonymous_rsvp),[]);i&&(a=m("settings.enableAnonymousRsvp"));const[o,l]=(0,d.useState)(a),c=(0,d.useCallback)((t=>{const s={gatherpress_enable_anonymous_rsvp:Number(t)};l(t),e({meta:s}),r()}),[e,r]);return(0,d.useEffect)((()=>{i&&0!==a&&c(a)}),[i,a,c]),(0,h.jsx)(n.CheckboxControl,{label:(0,t.__)("Enable Anonymous RSVP","gatherpress"),checked:o,onChange:e=>{c(e)}})},O=()=>(0,h.jsx)("section",{children:(0,h.jsx)(y,{})}),A=()=>{const{editPost:e,unlockPostSaving:r}=(0,s.useDispatch)("core/editor"),i=(0,s.useSelect)((e=>e("core/editor").isCleanNewPost()),[]);let a=(0,s.useSelect)((e=>e("core/editor").getEditedPostAttribute("meta").gatherpress_enable_initial_decline),[]);i&&(a=m("settings.enableInitialDecline"));const[o,l]=(0,d.useState)(a),c=(0,d.useCallback)((t=>{const s={gatherpress_enable_initial_decline:Number(t)};l(t),e({meta:s}),r()}),[e,r]);return(0,d.useEffect)((()=>{i&&0!==a&&c(a)}),[i,a,c]),(0,h.jsx)(n.CheckboxControl,{label:(0,t.__)('Enable Immediate "Not Attending" Option for Attendees',"gatherpress"),checked:o,onChange:e=>{c(e)}})},M=()=>(0,h.jsx)("section",{children:(0,h.jsx)(A,{})}),F=e=>{const{dateTimeStart:t}=e;return o().tz(t,b()).format(j())},Y=e=>{const{dateTimeEnd:t}=e;return o().tz(t,b()).format(j())},L=e=>{const{dateTimeStart:t,setDateTimeStart:s}=e,r=(0,g.getSettings)(),i=/a(?!\\)/i.test(r.formats.time.toLowerCase().replace(/\\\\/g,"").split("").reverse().join(""));return(0,h.jsx)(n.DateTimePicker,{currentDate:t,onChange:e=>T(e,s),is12Hour:i})},R=e=>{const{dateTimeEnd:t,setDateTimeEnd:s}=e,r=(0,g.getSettings)(),i=/a(?!\\)/i.test(r.formats.time.toLowerCase().replace(/\\\\/g,"").split("").reverse().join(""));return(0,h.jsx)(n.DateTimePicker,{currentDate:t,onChange:e=>P(e,s),is12Hour:i})},I=e=>{const{dateTimeStart:s,setDateTimeStart:r}=e;return(0,d.useEffect)((()=>{r(o().tz(function(){let e=m("eventDetails.dateTime.datetime_start");return e=""!==e?o().tz(e,b()).format(_):x,p("eventDetails.dateTime.datetime_start",e),e}(),b()).format(_)),C({setDateTimeStart:s}),N()})),(0,h.jsx)(n.PanelRow,{children:(0,h.jsxs)(n.Flex,{direction:"column",gap:"0",children:[(0,h.jsx)(n.FlexItem,{children:(0,h.jsx)("label",{htmlFor:"gatherpress-datetime-start",children:(0,t.__)("Start","gatherpress")})}),(0,h.jsx)(n.FlexItem,{children:(0,h.jsx)(n.Dropdown,{popoverProps:{placement:"bottom-end"},renderToggle:({isOpen:e,onToggle:t})=>(0,h.jsx)(n.Button,{id:"gatherpress-datetime-start",onClick:t,"aria-expanded":e,isLink:!0,children:(0,h.jsx)(F,{dateTimeStart:s})}),renderContent:()=>(0,h.jsx)(L,{dateTimeStart:s,setDateTimeStart:r})})})]})})},H=e=>{const{dateTimeEnd:s,setDateTimeEnd:r}=e;return(0,d.useEffect)((()=>{r(o().tz(function(){let e=m("eventDetails.dateTime.datetime_end");return e=""!==e?o().tz(e,b()).format(_):f,p("eventDetails.dateTime.datetime_end",e),e}(),b()).format(_)),C({setDateTimeEnd:s}),N()})),(0,h.jsx)(n.PanelRow,{children:(0,h.jsxs)(n.Flex,{direction:"column",gap:"0",children:[(0,h.jsx)(n.FlexItem,{children:(0,h.jsx)("label",{htmlFor:"gatherpress-datetime-end",children:(0,t.__)("End","gatherpress")})}),(0,h.jsx)(n.FlexItem,{children:(0,h.jsx)(n.Dropdown,{popoverProps:{placement:"bottom-end"},renderToggle:({isOpen:e,onToggle:t})=>(0,h.jsx)(n.Button,{id:"gatherpress-datetime-end",onClick:t,"aria-expanded":e,isLink:!0,children:(0,h.jsx)(Y,{dateTimeEnd:s})}),renderContent:()=>(0,h.jsx)(R,{dateTimeEnd:s,setDateTimeEnd:r})})})]})})},$=e=>{const{timezone:s,setTimezone:r}=e,i=m("misc.timezoneChoices");return(0,d.useEffect)((()=>{r(m("eventDetails.dateTime.timezone"))}),[r]),(0,d.useEffect)((()=>{C({setTimezone:m("eventDetails.dateTime.timezone")})})),(0,h.jsx)(n.PanelRow,{children:(0,h.jsx)(n.SelectControl,{label:(0,t.__)("Time Zone","gatherpress"),value:S(s),onChange:e=>{e=function(e=""){const t=/^UTC([+-])(\d+)(.\d+)?$/,s=e.replace(t,"$1");if(s!==e){const n=e.replace(t,"$2").padStart(2,"0");let r=e.replace(t,"$3");return""===r&&(r=":00"),r=r.replace(".25",":15").replace(".5",":30").replace(".75",":45"),s+n+r}return e}(e),r(e),p("eventDetails.dateTime.timezone",e),u()},children:Object.keys(i).map((e=>(0,h.jsx)("optgroup",{label:e,children:Object.keys(i[e]).map((t=>(0,h.jsx)("option",{value:t,children:i[e][t]},t)))},e)))})})},G=()=>{const[e,n]=(0,d.useState)(),[r,i]=(0,d.useState)(),[a,o]=(0,d.useState)();return(0,s.subscribe)(D),(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)("h3",{children:(0,t.__)("Date & time","gatherpress")}),(0,h.jsx)(I,{dateTimeStart:e,setDateTimeStart:n}),(0,h.jsx)(H,{dateTimeEnd:r,setDateTimeEnd:i}),(0,h.jsx)($,{timezone:a,setTimezone:o})]})},W=()=>(0,h.jsx)("section",{children:(0,h.jsx)(G,{})}),B=()=>{const{editPost:e,unlockPostSaving:r}=(0,s.useDispatch)("core/editor"),i=(0,s.useSelect)((e=>e("core/editor").isCleanNewPost()),[]);let a=(0,s.useSelect)((e=>e("core/editor").getEditedPostAttribute("meta").gatherpress_max_guest_limit),[]);i&&(a=m("settings.maxGuestLimit")),!1===a&&(a=0);const[o,l]=(0,d.useState)(a),c=(0,d.useCallback)((t=>{const s={gatherpress_max_guest_limit:Number(t)};l(t),e({meta:s}),r()}),[e,r]);return(0,d.useEffect)((()=>{i&&0!==a&&c(a)}),[i,a,c]),(0,h.jsx)(n.__experimentalNumberControl,{label:(0,t.__)("Maximum Number of Guests","gatherpress"),value:o,min:0,max:5,onChange:e=>{c(e)}})},V=()=>(0,h.jsx)("section",{children:(0,h.jsx)(B,{})}),J=()=>{const{editPost:e,unlockPostSaving:r}=(0,s.useDispatch)("core/editor"),i=(0,s.useSelect)((e=>e("core/editor").isCleanNewPost()),[]);let a=(0,s.useSelect)((e=>e("core/editor").getEditedPostAttribute("meta").gatherpress_max_attendance_limit),[]);i&&(a=m("settings.maxAttendanceLimit")),!1===a&&(a=0);const[o,l]=(0,d.useState)(a),c=(0,d.useCallback)((t=>{const s={gatherpress_max_attendance_limit:Number(t)};l(t),e({meta:s}),r()}),[e,r]);return(0,d.useEffect)((()=>{i&&0!==a&&c(a)}),[i,a,c]),(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(n.__experimentalNumberControl,{label:(0,t.__)("Maximum Attendance Limit","gatherpress"),value:o,min:0,onChange:e=>{c(e)}}),(0,h.jsx)("p",{className:"description",children:(0,t.__)("A value of 0 indicates no limit.","gatherpress")})]})},U=()=>(0,h.jsx)("section",{children:(0,h.jsx)(J,{})}),X=()=>"publish"===(0,s.select)("core/editor").getEditedPostAttribute("status")&&!z()&&(0,h.jsxs)("section",{children:[(0,h.jsx)("h3",{style:{marginBottom:"0.5rem"},children:(0,t.__)("Send an event update","gatherpress")}),(0,h.jsx)(n.Button,{variant:"secondary",onClick:()=>C({setOpen:!0}),children:(0,t.__)("Compose Message","gatherpress")})]}),Z=()=>{const{editPost:e,unlockPostSaving:r}=(0,s.useDispatch)("core/editor"),i=(0,s.useSelect)((e=>e("core/editor").getEditedPostAttribute("meta").gatherpress_online_event_link)),[a,o]=(0,d.useState)(i);return E({setOnlineEventLink:o},m("eventDetails.postId")),(0,h.jsx)(n.TextControl,{label:(0,t.__)("Online event link","gatherpress"),value:a,placeholder:(0,t.__)("Add link to online event","gatherpress"),onChange:t=>{(t=>{e({meta:{gatherpress_online_event_link:t}}),o(t),C({setOnlineEventLink:t},m("eventDetails.postId")),r()})(t)}})},q=()=>(0,h.jsx)("section",{children:(0,h.jsx)(Z,{})}),K=()=>{const[e,r]=(0,d.useState)(""),[i,a]=(0,d.useState)(""),[o,l]=(0,d.useState)(""),[c,u]=(0,d.useState)(""),[m,p]=(0,d.useState)(!1),[g,_]=(0,d.useState)(""),[v,x]=(0,d.useState)(""),[f,j]=(0,d.useState)(""),b=(0,s.useDispatch)("core/editor").editPost,{unlockPostSaving:S}=(0,s.useDispatch)("core/editor"),T=(0,s.useSelect)((e=>e("core/editor").getEditedPostAttribute("_gatherpress_venue"))),P=(0,s.useSelect)((e=>e("core").getEntityRecord("taxonomy","_gatherpress_venue",T))),D=P?.slug.replace(/^_/,""),[w,E]=(0,d.useState)(""),k=T+":"+w,z=(0,s.useSelect)((e=>e("core").getEntityRecords("postType","gatherpress_venue",{per_page:1,slug:w})));(0,d.useEffect)((()=>{var e,s,n,i,o,c;let d={};if(w&&Array.isArray(z)){var m;const e=null!==(m=z[0]?.meta?.gatherpress_venue_information)&&void 0!==m?m:"{}";var p;e&&(d=JSON.parse(e),d.name=null!==(p=z[0]?.title.rendered)&&void 0!==p?p:"")}const g=null!==(e=d?.name)&&void 0!==e?e:(0,t.__)("No venue selected.","gatherpress"),h=null!==(s=d?.fullAddress)&&void 0!==s?s:"",v=null!==(n=d?.phoneNumber)&&void 0!==n?n:"",f=null!==(i=d?.website)&&void 0!==i?i:"",b=null!==(o=d?.latitude)&&void 0!==o?o:"0",S=null!==(c=d?.longitude)&&void 0!==c?c:"0";D&&E(D),j(k?String(k):""),r(g),a(h),l(v),u(f),_(b),x(S),C({setName:g,setFullAddress:h,setPhoneNumber:v,setWebsite:f,setLatitude:b,setLongitude:S,setIsOnlineEventTerm:"online-event"===w})}),[w,z,D,k]);let N=(0,s.useSelect)((e=>e("core").getEntityRecords("taxonomy","_gatherpress_venue",{per_page:-1,context:"view"})),[]);return N?(N=N.map((e=>({label:e.name,value:e.id+":"+e.slug.replace(/^_/,"")}))),N.unshift({value:":",label:(0,t.__)("Choose a venue","gatherpress")})):N=[],(0,h.jsx)(n.PanelRow,{children:(0,h.jsx)(n.SelectControl,{label:(0,t.__)("Venue Selector","gatherpress"),value:f,onChange:e=>{(e=>{j(e);const t=""!==(e=e.split(":"))[0]?[e[0]]:[];b({_gatherpress_venue:t}),E(e[1]),S()})(e)},options:N})})},Q=()=>(0,h.jsx)("section",{children:(0,h.jsx)(K,{})});(0,r.registerPlugin)("gatherpress-event-settings",{render:()=>k()&&(0,h.jsx)(i.PluginDocumentSettingPanel,{name:"gatherpress-event-settings",title:(0,t.__)("Event settings","gatherpress"),initialOpen:!0,className:"gatherpress-event-settings",children:(0,h.jsxs)(n.__experimentalVStack,{spacing:6,children:[(0,h.jsx)(W,{}),(0,h.jsx)(Q,{}),(0,h.jsx)(q,{}),(0,h.jsx)(V,{}),(0,h.jsx)(U,{}),(0,h.jsx)(O,{}),(0,h.jsx)(M,{}),(0,h.jsx)(X,{})]})})}),(0,s.dispatch)("core/edit-post").toggleEditorPanelOpened("gatherpress-event-settings/gatherpress-event-settings");const ee=window.wp.compose,te=()=>{var e,r,i;const a=(0,s.useDispatch)("core/editor").editPost,o=e=>{const t=JSON.stringify({...l,...e});a({meta:{gatherpress_venue_information:t}})};let l=(0,s.useSelect)((e=>e("core/editor").getEditedPostAttribute("meta").gatherpress_venue_information));l=l?JSON.parse(l):{};const[c,u]=(0,d.useState)(null!==(e=l.fullAddress)&&void 0!==e?e:""),[m,p]=(0,d.useState)(null!==(r=l.phoneNumber)&&void 0!==r?r:""),[g,_]=(0,d.useState)(null!==(i=l.website)&&void 0!==i?i:"");E({setFullAddress:u,setPhoneNumber:p,setWebsite:_});const v=(0,d.useRef)(o),x=(0,d.useCallback)((()=>{let e=null,s=null;fetch(`https://nominatim.openstreetmap.org/search?q=${c}&format=geojson`).then((e=>{if(!e.ok)throw new Error((0,t.sprintf)(/* translators: %s: Error message */ /* translators: %s: Error message */ -(0,t.__)("Network response was not ok %s","gatherpress"),e.statusText));return e.json()})).then((t=>{t.features.length>0&&(e=t.features[0].geometry.coordinates[1],s=t.features[0].geometry.coordinates[0]),v.current({latitude:e,longitude:s})}))}),[c]),f=(0,ee.useDebounce)(x,300);return(0,d.useEffect)((()=>{v.current=o}),[o]),(0,d.useEffect)((()=>{f()}),[c,f]),(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(n.TextControl,{label:(0,t.__)("Full Address","gatherpress"),value:c,onChange:e=>{C({setFullAddress:e}),o({fullAddress:e})}}),(0,h.jsx)(n.TextControl,{label:(0,t.__)("Phone Number","gatherpress"),value:m,onChange:e=>{C({setPhoneNumber:e}),o({phoneNumber:e})}}),(0,h.jsx)(n.TextControl,{label:(0,t.__)("Website","gatherpress"),value:g,type:"url",onChange:e=>{C({setWebsite:e}),o({website:e})}})]})},se=()=>(0,h.jsx)("section",{children:(0,h.jsx)(te,{})});(0,r.registerPlugin)("gatherpress-venue-settings",{render:()=>"gatherpress_venue"===(0,s.select)("core/editor")?.getCurrentPostType()&&(0,h.jsx)(i.PluginDocumentSettingPanel,{name:"gatherpress-venue-settings",title:(0,t.__)("Venue settings","gatherpress"),initialOpen:!0,className:"gatherpress-venue-settings",children:(0,h.jsx)(n.__experimentalVStack,{spacing:6,children:(0,h.jsx)(se,{})})})}),(0,s.dispatch)("core/edit-post").toggleEditorPanelOpened("gatherpress-venue-settings/gatherpress-venue-settings")})(); \ No newline at end of file +(()=>{"use strict";var e={n:t=>{var s=t&&t.__esModule?()=>t.default:()=>t;return e.d(s,{a:s}),s},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]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t)};const t=window.wp.i18n,s=window.wp.data,n=window.wp.components,r=window.wp.plugins,i=window.wp.editPost,a=window.moment;var o=e.n(a);const l=window.wp.apiFetch;var c=e.n(l);const d=window.wp.element;function u(){(0,s.dispatch)("core/editor")?.editPost({meta:{_non_existing_meta:!0}})}function m(e){if("object"==typeof GatherPress)return e.split(".").reduce(((e,t)=>e&&e[t]),GatherPress)}function p(e,t){if("object"!=typeof GatherPress)return;const s=e.split("."),n=s.pop();s.reduce(((e,t)=>{var s;return null!==(s=e[t])&&void 0!==s?s:e[t]={}}),GatherPress)[n]=t}const g=window.wp.date,h=window.ReactJSXRuntime,_="YYYY-MM-DDTHH:mm:ss",v="YYYY-MM-DD HH:mm:ss",x=o().tz(S()).add(1,"day").set("hour",18).set("minute",0).set("second",0).format(_),f=o().tz(x,S()).add(2,"hours").format(_);function j(){return D(m("settings.dateFormat"))+" "+D(m("settings.timeFormat"))}function S(e=m("eventDetails.dateTime.timezone")){return o().tz.zone(e)?e:(0,t.__)("GMT","gatherpress")}function b(e=""){const t=/^([+-])(\d{2}):(00|15|30|45)$/,s=e.replace(t,"$1");return s!==e?"UTC"+s+parseInt(e.replace(t,"$2")).toString()+e.replace(t,"$3").replace("00","").replace("15",".25").replace("30",".5").replace("45",".75"):e}function T(e,t=null){!function(e){const t=o().tz(m("eventDetails.dateTime.datetime_end"),S()).valueOf(),s=o().tz(e,S()).valueOf();s>=t&&P(o().tz(s,S()).add(2,"hours").format(_))}(e),p("eventDetails.dateTime.datetime_start",e),"function"==typeof t&&t(e),u()}function P(e,t=null){!function(e){const t=o().tz(m("eventDetails.dateTime.datetime_start"),S()).valueOf(),s=o().tz(e,S()).valueOf();s<=t&&T(o().tz(s,S()).subtract(2,"hours").format(_))}(e),p("eventDetails.dateTime.datetime_end",e),null!==t&&t(e),u()}function D(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,s,n)=>{const r=n[s-1];return e in t&&"\\"!==r?t[e]:e})).join("")}const w=(e,t="")=>{for(const[s,n]of Object.entries(e)){let e=s;t&&(e+="_"+String(t));const r=new CustomEvent(e,{detail:n});dispatchEvent(r)}},C=(e,t="")=>{for(const[s,n]of Object.entries(e)){let e=s;t&&(e+="_"+String(t)),addEventListener(e,(e=>{n(e.detail)}),!1)}};function E(){return"gatherpress_event"===(0,s.select)("core/editor")?.getCurrentPostType()}function k(){const e=o().tz(m("eventDetails.dateTime.datetime_end"),S());return"gatherpress_event"===(0,s.select)("core/editor")?.getCurrentPostType()&&o().tz(S()).valueOf()>e.valueOf()}function z(){const e="gatherpress_event_past",n=(0,s.dispatch)("core/notices");n.removeNotice(e),k()&&n.createNotice("warning",(0,t.__)("This event has already passed.","gatherpress"),{id:e,isDismissible:!1})}const N=()=>{const{editPost:e,unlockPostSaving:r}=(0,s.useDispatch)("core/editor"),i=(0,s.useSelect)((e=>e("core/editor").isCleanNewPost()),[]);let a=(0,s.useSelect)((e=>e("core/editor").getEditedPostAttribute("meta").gatherpress_enable_anonymous_rsvp),[]);i&&(a=m("settings.enableAnonymousRsvp"));const[o,l]=(0,d.useState)(a),c=(0,d.useCallback)((t=>{const s={gatherpress_enable_anonymous_rsvp:Number(t)};l(t),e({meta:s}),r()}),[e,r]);return(0,d.useEffect)((()=>{i&&0!==a&&c(a)}),[i,a,c]),(0,h.jsx)(n.CheckboxControl,{label:(0,t.__)("Enable Anonymous RSVP","gatherpress"),checked:o,onChange:e=>{c(e)}})},y=()=>(0,h.jsx)("section",{children:(0,h.jsx)(N,{})}),O=()=>{const{editPost:e,unlockPostSaving:r}=(0,s.useDispatch)("core/editor"),i=(0,s.useSelect)((e=>e("core/editor").isCleanNewPost()),[]);let a=(0,s.useSelect)((e=>e("core/editor").getEditedPostAttribute("meta").gatherpress_enable_initial_decline),[]);i&&(a=m("settings.enableInitialDecline"));const[o,l]=(0,d.useState)(a),c=(0,d.useCallback)((t=>{const s={gatherpress_enable_initial_decline:Number(t)};l(t),e({meta:s}),r()}),[e,r]);return(0,d.useEffect)((()=>{i&&0!==a&&c(a)}),[i,a,c]),(0,h.jsx)(n.CheckboxControl,{label:(0,t.__)('Enable Immediate "Not Attending" Option for Attendees',"gatherpress"),checked:o,onChange:e=>{c(e)}})},A=()=>(0,h.jsx)("section",{children:(0,h.jsx)(O,{})}),M=e=>{const{dateTimeStart:t}=e;return o().tz(t,S()).format(j())},F=e=>{const{dateTimeEnd:t}=e;return o().tz(t,S()).format(j())},Y=e=>{const{dateTimeStart:t,setDateTimeStart:s}=e,r=(0,g.getSettings)(),i=/a(?!\\)/i.test(r.formats.time.toLowerCase().replace(/\\\\/g,"").split("").reverse().join(""));return(0,h.jsx)(n.DateTimePicker,{currentDate:t,onChange:e=>T(e,s),is12Hour:i})},L=e=>{const{dateTimeEnd:t,setDateTimeEnd:s}=e,r=(0,g.getSettings)(),i=/a(?!\\)/i.test(r.formats.time.toLowerCase().replace(/\\\\/g,"").split("").reverse().join(""));return(0,h.jsx)(n.DateTimePicker,{currentDate:t,onChange:e=>P(e,s),is12Hour:i})},R=e=>{const{dateTimeStart:s,setDateTimeStart:r}=e;return(0,d.useEffect)((()=>{r(o().tz(function(){let e=m("eventDetails.dateTime.datetime_start");return e=""!==e?o().tz(e,S()).format(_):x,p("eventDetails.dateTime.datetime_start",e),e}(),S()).format(_)),w({setDateTimeStart:s}),z()})),(0,h.jsx)(n.PanelRow,{children:(0,h.jsxs)(n.Flex,{direction:"column",gap:"0",children:[(0,h.jsx)(n.FlexItem,{children:(0,h.jsx)("label",{htmlFor:"gatherpress-datetime-start",children:(0,t.__)("Start","gatherpress")})}),(0,h.jsx)(n.FlexItem,{children:(0,h.jsx)(n.Dropdown,{popoverProps:{placement:"bottom-end"},renderToggle:({isOpen:e,onToggle:t})=>(0,h.jsx)(n.Button,{id:"gatherpress-datetime-start",onClick:t,"aria-expanded":e,isLink:!0,children:(0,h.jsx)(M,{dateTimeStart:s})}),renderContent:()=>(0,h.jsx)(Y,{dateTimeStart:s,setDateTimeStart:r})})})]})})},I=e=>{const{dateTimeEnd:s,setDateTimeEnd:r}=e;return(0,d.useEffect)((()=>{r(o().tz(function(){let e=m("eventDetails.dateTime.datetime_end");return e=""!==e?o().tz(e,S()).format(_):f,p("eventDetails.dateTime.datetime_end",e),e}(),S()).format(_)),w({setDateTimeEnd:s}),z()})),(0,h.jsx)(n.PanelRow,{children:(0,h.jsxs)(n.Flex,{direction:"column",gap:"0",children:[(0,h.jsx)(n.FlexItem,{children:(0,h.jsx)("label",{htmlFor:"gatherpress-datetime-end",children:(0,t.__)("End","gatherpress")})}),(0,h.jsx)(n.FlexItem,{children:(0,h.jsx)(n.Dropdown,{popoverProps:{placement:"bottom-end"},renderToggle:({isOpen:e,onToggle:t})=>(0,h.jsx)(n.Button,{id:"gatherpress-datetime-end",onClick:t,"aria-expanded":e,isLink:!0,children:(0,h.jsx)(F,{dateTimeEnd:s})}),renderContent:()=>(0,h.jsx)(L,{dateTimeEnd:s,setDateTimeEnd:r})})})]})})},H=e=>{const{timezone:s,setTimezone:r}=e,i=m("misc.timezoneChoices");return(0,d.useEffect)((()=>{r(m("eventDetails.dateTime.timezone"))}),[r]),(0,d.useEffect)((()=>{w({setTimezone:m("eventDetails.dateTime.timezone")})})),(0,h.jsx)(n.PanelRow,{children:(0,h.jsx)(n.SelectControl,{label:(0,t.__)("Time Zone","gatherpress"),value:b(s),onChange:e=>{e=function(e=""){const t=/^UTC([+-])(\d+)(.\d+)?$/,s=e.replace(t,"$1");if(s!==e){const n=e.replace(t,"$2").padStart(2,"0");let r=e.replace(t,"$3");return""===r&&(r=":00"),r=r.replace(".25",":15").replace(".5",":30").replace(".75",":45"),s+n+r}return e}(e),r(e),p("eventDetails.dateTime.timezone",e),u()},children:Object.keys(i).map((e=>(0,h.jsx)("optgroup",{label:e,children:Object.keys(i[e]).map((t=>(0,h.jsx)("option",{value:t,children:i[e][t]},t)))},e)))})})},$=()=>{const[e,n]=(0,d.useState)(),[r,i]=(0,d.useState)(),[a,l]=(0,d.useState)();return function(){const e=(0,s.select)("core/editor").isSavingPost(),n=(0,s.select)("core/editor").isAutosavingPost();E()&&e&&!n&&c()({path:m("urls.eventRestApi")+"/datetime",method:"POST",data:{post_id:m("eventDetails.postId"),datetime_start:o().tz(m("eventDetails.dateTime.datetime_start"),S()).format(v),datetime_end:o().tz(m("eventDetails.dateTime.datetime_end"),S()).format(v),timezone:m("eventDetails.dateTime.timezone"),_wpnonce:m("misc.nonce")}}).then((()=>{!function(){const e="gatherpress_event_communcation",n=(0,s.dispatch)("core/notices");n.removeNotice(e),"publish"!==(0,s.select)("core/editor").getEditedPostAttribute("status")||k()||n.createNotice("success",(0,t.__)("Send an event update to members via email?","gatherpress"),{id:e,isDismissible:!0,actions:[{onClick:()=>{w({setOpen:!0})},label:(0,t.__)("Compose Message","gatherpress")}]})}()}))}(),(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)("h3",{children:(0,t.__)("Date & time","gatherpress")}),(0,h.jsx)(R,{dateTimeStart:e,setDateTimeStart:n}),(0,h.jsx)(I,{dateTimeEnd:r,setDateTimeEnd:i}),(0,h.jsx)(H,{timezone:a,setTimezone:l})]})},G=()=>(0,h.jsx)("section",{children:(0,h.jsx)($,{})}),W=()=>{const{editPost:e,unlockPostSaving:r}=(0,s.useDispatch)("core/editor"),i=(0,s.useSelect)((e=>e("core/editor").isCleanNewPost()),[]);let a=(0,s.useSelect)((e=>e("core/editor").getEditedPostAttribute("meta").gatherpress_max_guest_limit),[]);i&&(a=m("settings.maxGuestLimit")),!1===a&&(a=0);const[o,l]=(0,d.useState)(a),c=(0,d.useCallback)((t=>{const s={gatherpress_max_guest_limit:Number(t)};l(t),e({meta:s}),r()}),[e,r]);return(0,d.useEffect)((()=>{i&&0!==a&&c(a)}),[i,a,c]),(0,h.jsx)(n.__experimentalNumberControl,{label:(0,t.__)("Maximum Number of Guests","gatherpress"),value:o,min:0,max:5,onChange:e=>{c(e)}})},B=()=>(0,h.jsx)("section",{children:(0,h.jsx)(W,{})}),V=()=>{const{editPost:e,unlockPostSaving:r}=(0,s.useDispatch)("core/editor"),i=(0,s.useSelect)((e=>e("core/editor").isCleanNewPost()),[]);let a=(0,s.useSelect)((e=>e("core/editor").getEditedPostAttribute("meta").gatherpress_max_attendance_limit),[]);i&&(a=m("settings.maxAttendanceLimit")),!1===a&&(a=0);const[o,l]=(0,d.useState)(a),c=(0,d.useCallback)((t=>{const s={gatherpress_max_attendance_limit:Number(t)};l(t),e({meta:s}),r()}),[e,r]);return(0,d.useEffect)((()=>{i&&0!==a&&c(a)}),[i,a,c]),(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(n.__experimentalNumberControl,{label:(0,t.__)("Maximum Attendance Limit","gatherpress"),value:o,min:0,onChange:e=>{c(e)}}),(0,h.jsx)("p",{className:"description",children:(0,t.__)("A value of 0 indicates no limit.","gatherpress")})]})},J=()=>(0,h.jsx)("section",{children:(0,h.jsx)(V,{})}),U=()=>"publish"===(0,s.select)("core/editor").getEditedPostAttribute("status")&&!k()&&(0,h.jsxs)("section",{children:[(0,h.jsx)("h3",{style:{marginBottom:"0.5rem"},children:(0,t.__)("Send an event update","gatherpress")}),(0,h.jsx)(n.Button,{variant:"secondary",onClick:()=>w({setOpen:!0}),children:(0,t.__)("Compose Message","gatherpress")})]}),X=()=>{const{editPost:e,unlockPostSaving:r}=(0,s.useDispatch)("core/editor"),i=(0,s.useSelect)((e=>e("core/editor").getEditedPostAttribute("meta").gatherpress_online_event_link)),[a,o]=(0,d.useState)(i);return C({setOnlineEventLink:o},m("eventDetails.postId")),(0,h.jsx)(n.TextControl,{label:(0,t.__)("Online event link","gatherpress"),value:a,placeholder:(0,t.__)("Add link to online event","gatherpress"),onChange:t=>{(t=>{e({meta:{gatherpress_online_event_link:t}}),o(t),w({setOnlineEventLink:t},m("eventDetails.postId")),r()})(t)}})},Z=()=>(0,h.jsx)("section",{children:(0,h.jsx)(X,{})}),q=()=>{const[e,r]=(0,d.useState)(""),[i,a]=(0,d.useState)(""),[o,l]=(0,d.useState)(""),[c,u]=(0,d.useState)(""),[m,p]=(0,d.useState)(!1),[g,_]=(0,d.useState)(""),[v,x]=(0,d.useState)(""),[f,j]=(0,d.useState)(""),S=(0,s.useDispatch)("core/editor").editPost,{unlockPostSaving:b}=(0,s.useDispatch)("core/editor"),T=(0,s.useSelect)((e=>e("core/editor").getEditedPostAttribute("_gatherpress_venue"))),P=(0,s.useSelect)((e=>e("core").getEntityRecord("taxonomy","_gatherpress_venue",T))),D=P?.slug.replace(/^_/,""),[C,E]=(0,d.useState)(""),k=T+":"+C,z=(0,s.useSelect)((e=>e("core").getEntityRecords("postType","gatherpress_venue",{per_page:1,slug:C})));(0,d.useEffect)((()=>{var e,s,n,i,o,c;let d={};if(C&&Array.isArray(z)){var m;const e=null!==(m=z[0]?.meta?.gatherpress_venue_information)&&void 0!==m?m:"{}";var p;e&&(d=JSON.parse(e),d.name=null!==(p=z[0]?.title.rendered)&&void 0!==p?p:"")}const g=null!==(e=d?.name)&&void 0!==e?e:(0,t.__)("No venue selected.","gatherpress"),h=null!==(s=d?.fullAddress)&&void 0!==s?s:"",v=null!==(n=d?.phoneNumber)&&void 0!==n?n:"",f=null!==(i=d?.website)&&void 0!==i?i:"",S=null!==(o=d?.latitude)&&void 0!==o?o:"0",b=null!==(c=d?.longitude)&&void 0!==c?c:"0";D&&E(D),j(k?String(k):""),r(g),a(h),l(v),u(f),_(S),x(b),w({setName:g,setFullAddress:h,setPhoneNumber:v,setWebsite:f,setLatitude:S,setLongitude:b,setIsOnlineEventTerm:"online-event"===C})}),[C,z,D,k]);let N=(0,s.useSelect)((e=>e("core").getEntityRecords("taxonomy","_gatherpress_venue",{per_page:-1,context:"view"})),[]);return N?(N=N.map((e=>({label:e.name,value:e.id+":"+e.slug.replace(/^_/,"")}))),N.unshift({value:":",label:(0,t.__)("Choose a venue","gatherpress")})):N=[],(0,h.jsx)(n.PanelRow,{children:(0,h.jsx)(n.SelectControl,{label:(0,t.__)("Venue Selector","gatherpress"),value:f,onChange:e=>{(e=>{j(e);const t=""!==(e=e.split(":"))[0]?[e[0]]:[];S({_gatherpress_venue:t}),E(e[1]),b()})(e)},options:N})})},K=()=>(0,h.jsx)("section",{children:(0,h.jsx)(q,{})});(0,r.registerPlugin)("gatherpress-event-settings",{render:()=>E()&&(0,h.jsx)(i.PluginDocumentSettingPanel,{name:"gatherpress-event-settings",title:(0,t.__)("Event settings","gatherpress"),initialOpen:!0,className:"gatherpress-event-settings",children:(0,h.jsxs)(n.__experimentalVStack,{spacing:6,children:[(0,h.jsx)(G,{}),(0,h.jsx)(K,{}),(0,h.jsx)(Z,{}),(0,h.jsx)(B,{}),(0,h.jsx)(J,{}),(0,h.jsx)(y,{}),(0,h.jsx)(A,{}),(0,h.jsx)(U,{})]})})}),(0,s.dispatch)("core/edit-post").toggleEditorPanelOpened("gatherpress-event-settings/gatherpress-event-settings");const Q=window.wp.compose,ee=()=>{var e,r,i;const a=(0,s.useDispatch)("core/editor").editPost,o=e=>{const t=JSON.stringify({...l,...e});a({meta:{gatherpress_venue_information:t}})};let l=(0,s.useSelect)((e=>e("core/editor").getEditedPostAttribute("meta").gatherpress_venue_information));l=l?JSON.parse(l):{};const[c,u]=(0,d.useState)(null!==(e=l.fullAddress)&&void 0!==e?e:""),[m,p]=(0,d.useState)(null!==(r=l.phoneNumber)&&void 0!==r?r:""),[g,_]=(0,d.useState)(null!==(i=l.website)&&void 0!==i?i:"");C({setFullAddress:u,setPhoneNumber:p,setWebsite:_});const v=(0,d.useRef)(o),x=(0,d.useCallback)((()=>{let e=null,s=null;fetch(`https://nominatim.openstreetmap.org/search?q=${c}&format=geojson`).then((e=>{if(!e.ok)throw new Error((0,t.sprintf)(/* translators: %s: Error message */ /* translators: %s: Error message */ +(0,t.__)("Network response was not ok %s","gatherpress"),e.statusText));return e.json()})).then((t=>{t.features.length>0&&(e=t.features[0].geometry.coordinates[1],s=t.features[0].geometry.coordinates[0]),v.current({latitude:e,longitude:s})}))}),[c]),f=(0,Q.useDebounce)(x,300);return(0,d.useEffect)((()=>{v.current=o}),[o]),(0,d.useEffect)((()=>{f()}),[c,f]),(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(n.TextControl,{label:(0,t.__)("Full Address","gatherpress"),value:c,onChange:e=>{w({setFullAddress:e}),o({fullAddress:e})}}),(0,h.jsx)(n.TextControl,{label:(0,t.__)("Phone Number","gatherpress"),value:m,onChange:e=>{w({setPhoneNumber:e}),o({phoneNumber:e})}}),(0,h.jsx)(n.TextControl,{label:(0,t.__)("Website","gatherpress"),value:g,type:"url",onChange:e=>{w({setWebsite:e}),o({website:e})}})]})},te=()=>(0,h.jsx)("section",{children:(0,h.jsx)(ee,{})});(0,r.registerPlugin)("gatherpress-venue-settings",{render:()=>"gatherpress_venue"===(0,s.select)("core/editor")?.getCurrentPostType()&&(0,h.jsx)(i.PluginDocumentSettingPanel,{name:"gatherpress-venue-settings",title:(0,t.__)("Venue settings","gatherpress"),initialOpen:!0,className:"gatherpress-venue-settings",children:(0,h.jsx)(n.__experimentalVStack,{spacing:6,children:(0,h.jsx)(te,{})})})}),(0,s.dispatch)("core/edit-post").toggleEditorPanelOpened("gatherpress-venue-settings/gatherpress-venue-settings")})(); \ No newline at end of file diff --git a/includes/core/classes/class-event-setup.php b/includes/core/classes/class-event-setup.php index 7a314fbc1..a47d65e6a 100644 --- a/includes/core/classes/class-event-setup.php +++ b/includes/core/classes/class-event-setup.php @@ -157,6 +157,51 @@ public function register_post_type(): void { */ public function register_post_meta(): void { $post_meta = array( + 'gatherpress_datetime_start' => array( + 'auth_callback' => function () { + return current_user_can( 'edit_posts' ); + }, + 'sanitize_callback' => 'sanitize_text_field', + 'show_in_rest' => true, + 'single' => true, + 'type' => 'string', + ), + 'gatherpress_datetime_start_gmt' => array( + 'auth_callback' => function () { + return current_user_can( 'edit_posts' ); + }, + 'sanitize_callback' => 'sanitize_text_field', + 'show_in_rest' => true, + 'single' => true, + 'type' => 'string', + ), + 'gatherpress_datetime_end' => array( + 'auth_callback' => function () { + return current_user_can( 'edit_posts' ); + }, + 'sanitize_callback' => 'sanitize_text_field', + 'show_in_rest' => true, + 'single' => true, + 'type' => 'string', + ), + 'gatherpress_datetime_end_gmt' => array( + 'auth_callback' => function () { + return current_user_can( 'edit_posts' ); + }, + 'sanitize_callback' => 'sanitize_text_field', + 'show_in_rest' => true, + 'single' => true, + 'type' => 'string', + ), + 'gatherpress_timezone' => array( + 'auth_callback' => function () { + return current_user_can( 'edit_posts' ); + }, + 'sanitize_callback' => 'sanitize_text_field', + 'show_in_rest' => true, + 'single' => true, + 'type' => 'string', + ), 'gatherpress_max_guest_limit' => array( 'auth_callback' => function () { return current_user_can( 'edit_posts' ); diff --git a/includes/core/classes/class-event.php b/includes/core/classes/class-event.php index 0de4c76b2..a9345e1d3 100644 --- a/includes/core/classes/class-event.php +++ b/includes/core/classes/class-event.php @@ -685,11 +685,34 @@ function ( $key ) { $fields, array( 'post_id' => $fields['post_id'] ) ); + delete_transient( sprintf( self::DATETIME_CACHE_KEY, $fields['post_id'] ) ); } else { $value = $wpdb->insert( $table, $fields ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery } + foreach ( $fields as $key => $field ) { + if ( 'post_id' === $key ) { + continue; + } + + $meta_key = sprintf( 'gatherpress_%s', sanitize_key( $key ) ); + + if ( ! empty( $exists ) ) { + update_post_meta( + $fields['post_id'], + $meta_key, + sanitize_text_field( $field ) + ); + } else { + add_post_meta( + $fields['post_id'], + $meta_key, + sanitize_text_field( $field ) + ); + } + } + return (bool) $value; } diff --git a/src/components/DateTimeRange.js b/src/components/DateTimeRange.js index e4d67ea8d..be6c0ec12 100644 --- a/src/components/DateTimeRange.js +++ b/src/components/DateTimeRange.js @@ -31,7 +31,7 @@ const DateTimeRange = () => { const [dateTimeEnd, setDateTimeEnd] = useState(); const [timezone, setTimezone] = useState(); - subscribe(saveDateTime); + saveDateTime(); return ( <>