Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@planningcenter/connected-events

Package Overview
Dependencies
Maintainers
16
Versions
47
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@planningcenter/connected-events - npm Package Compare versions

Comparing version 1.7.0 to 1.7.1-rc.2

2

dist/connected-events.esm.js

@@ -1,2 +0,2 @@

import e,{useState as t,useEffect as n}from"react";import r from"@planningcenter/url";import{Dropdown as a,Icon as o,Menu as c,StackView as l,Spinner as s,Collapse as i,Button as d,Divider as p,Text as m}from"@planningcenter/tapestry-react";import*as u from"@planningcenter/icons/paths/calendar";import*as g from"@planningcenter/icons/paths/logomark";import*as h from"@planningcenter/icons/paths/general";class E{}E.post=(e,t={})=>E.request(e,"POST",t),E.get=e=>E.request(e,"GET"),E.request=(e,t,n)=>{const a=new URL(e,r(window.railsEnv)("api")),o={credentials:"include",headers:{Accept:"application/json","Content-Type":"application/json","X-PCO-API-VERSION":"2018-08-01","X-CSRF-Token":window?.Rails?.csrfToken()||document.querySelector('meta[name="csrf-token"]')?.getAttribute("content")||null},method:t,redirect:"follow"};return n&&(o.body=JSON.stringify(n)),fetch(a.href,o).then(e=>e.json().then(t=>({json:t,ok:e.ok,response:e})).catch(()=>({json:null,ok:e.ok,response:e})),e=>(console.warn(e),{json:{data:[]},ok:!1,response:null}))};class f{static any(e,t,n){try{return Promise.resolve(this.get(e,t,n,{perPage:1}).then(e=>e.json?.meta?.count>0))}catch(e){return Promise.reject(e)}}static get(e,t,n,r){try{if(!(e&&t&&n))return Promise.resolve();const{filter:a,sort:o,perPage:c,dates:l}=r,s=function(e){if(e)return function(e){return e.sort(function(e,t){return Date.parse(e)-Date.parse(t)})}(e).find(e=>Date.parse(e)>Date.now())}(l),i=new URLSearchParams({id:t.toString(),product:e,type:n});a&&i.append("filter",a),o&&i.append("sort",o),s&&i.append("date",s),c&&i.append("per_page",c.toString());const d=`/calendar/v2/event_connection_links?${i.toString()}`;return Promise.resolve(E.get(d))}catch(e){return Promise.reject(e)}}}const v=({icon:t})=>/*#__PURE__*/e.createElement("path",{d:t}),y=({children:t,handleOpen:n,...r})=>/*#__PURE__*/e.createElement(a,{closeOnSelect:!1,icon:{marginLeft:.5,children:/*#__PURE__*/e.createElement(v,{icon:u.connections})},id:"connected-events-dropdown",onOpen:()=>n(!0),onClose:()=>n(!1),placement:"bottom-end",size:"md",theme:"primary",tooltip:"Connections",variant:"fill",popoverProps:{minWidth:32},...r},t),k=({event:t,...n})=>{const{name:r,product:c,url:l}=t.attributes,s=`${c.charAt(0).toUpperCase()}${c.slice(1)}`;/*#__PURE__*/return e.createElement(a.Link,{marginBottom:.5,paddingHorizontal:2,to:l,...n},/*#__PURE__*/e.createElement(o,{color:c,marginRight:1},/*#__PURE__*/e.createElement(v,{icon:g["check-ins"===c?"checkIns":c]})),r||s)};k.displayName=a.Item.displayName;const w=({connectable:e,filter:n,sort:r})=>{const[a,o]=t(null),[c,l]=t(!1),{dates:s,productName:i,localRecordId:d,localRecordType:p}=e;return{events:a,fetching:c,fetch:()=>(l(!0),f.get(i,d,p,{filter:n,sort:r,dates:s}).then(({json:e})=>{o(e.data),l(!1)}))}},P=({children:t})=>/*#__PURE__*/e.createElement(c.Heading,{color:"grey-6",paddingHorizontal:2,paddingTop:.5,lineHeight:3},t),C=({connectable:t,handleOpen:r,open:a,...o})=>{const{events:c,fetching:l,fetch:s}=w({connectable:t,sort:"starts_at"});return n(()=>{a&&s()},[t.localRecordId,a]),/*#__PURE__*/e.createElement(y,{handleOpen:r,...o},b({allEvents:c,fetchingEvents:l}))},b=({allEvents:t,fetchingEvents:n})=>{const r=[/*#__PURE__*/e.createElement(P,null,"Connections")];return n||!t?r.push(/*#__PURE__*/e.createElement(l,null,/*#__PURE__*/e.createElement(s,{key:"dropdown-contents-for-all",marginHorizontal:2,marginVertical:.5,align:"center"}))):t.forEach(t=>{r.push(/*#__PURE__*/e.createElement(k,{key:`${t.id}`,event:t}))}),r},S=({isExpandable:t=!1,isLoading:n,clickHandler:r,clickHandlerValue:a})=>/*#__PURE__*/e.createElement(d,{"data-pendo":"connected-events-add-to-calendar",disabled:n,theme:"primary",variant:"outline",flex:1,spacing:1,onClick:()=>r(a),value:a},/*#__PURE__*/e.createElement(o,{color:"calendar"},/*#__PURE__*/e.createElement(v,{icon:g.calendar})),"Add to Calendar",t&&/*#__PURE__*/e.createElement(o,{theme:"primary"},/*#__PURE__*/e.createElement(v,{icon:a?h.downCaret:h.upCaret})),n&&/*#__PURE__*/e.createElement(s,{marginVertical:.5,align:"center"})),_=({requestForms:n,requestFormParams:r})=>{const[a,o]=t(!1),[c,s]=t(!1),p=e=>{const t=n.find(t=>t.id===e);s(!0),m(t)},m=e=>{E.post("/accounts/v2/generate_church_center_login_handshake").then(({json:t})=>{const n=new URL(t.data.attributes.exchange_url),a=new URL(e.attributes.church_center_url),o=JSON.stringify(r);a.searchParams.append("prefill",o),n.searchParams.append("return",a.toString()),window.location.assign(n.toString())}).catch(()=>{alert("Something unexpected happened. Please try again."),s(!1)})};return n.length>1?/*#__PURE__*/e.createElement(l,{axis:"vertical",flex:1},/*#__PURE__*/e.createElement(S,{isExpandable:!0,isLoading:c,clickHandler:o,clickHandlerValue:!a}),/*#__PURE__*/e.createElement(i,{open:a},/*#__PURE__*/e.createElement(l,{flex:1,marginHorizontal:-2},n.map(t=>/*#__PURE__*/e.createElement(l,{key:t.id,paddingTop:.5},/*#__PURE__*/e.createElement(d,{justifyContent:"flex-start",onClick:()=>p(t.id),paddingHorizontal:2,radius:0,value:t.id,variant:"naked"},t.attributes.name)))))):/*#__PURE__*/e.createElement(S,{isLoading:c,clickHandler:p,clickHandlerValue:n[0].id})},R=({connectable:r,dates:o=[],handleOpen:c,open:l,requestForms:s,...i})=>{const[d,m]=t(!1),u=r.extra?.requestFormParams,g=u&&Object.keys(u).length>0,h=o.every(e=>new Date(e)<=new Date),E=g&&s.length>0&&!h,{events:f,fetching:v,fetch:k}=w({connectable:r,filter:"upcoming",sort:"starts_at"}),{events:P,fetching:C,fetch:b}=w({connectable:r,filter:"past",sort:"-starts_at"});return n(()=>{l&&(k(),b())},[r.localRecordId,l]),n(()=>{m(!1)},[l]),/*#__PURE__*/e.createElement(y,{handleOpen:c,...i},j({fetchingUpcoming:v,fetchingPast:C,pastEvents:P,setShowingPastEvents:m,showingPastEvents:d,upcomingEvents:f}),E&&[/*#__PURE__*/e.createElement(p,null),/*#__PURE__*/e.createElement(a.Item,{highlightedColor:"transparent"},/*#__PURE__*/e.createElement(_,{requestForms:s,requestFormParams:u}))])},H=({children:t})=>/*#__PURE__*/e.createElement(m,{color:"grey-6",italic:!0,align:"center",marginHorizontal:2,marginBottom:1,size:4},t),j=({fetchingUpcoming:t,fetchingPast:n,pastEvents:r,showingPastEvents:o,setShowingPastEvents:c,upcomingEvents:i})=>{const p=!i||0===i.length,m=[];return m.push(/*#__PURE__*/e.createElement(P,null,o?"Upcoming":"Connections")),t||n?m.push(/*#__PURE__*/e.createElement(l,null,/*#__PURE__*/e.createElement(s,{key:"dropdown-contents-for-upcoming-past",marginHorizontal:2,marginVertical:.5,align:"center"}))):(i?.forEach(t=>{m.push(/*#__PURE__*/e.createElement(k,{key:`${t.id}`,event:t}))}),p&&m.push(/*#__PURE__*/e.createElement(H,{key:"no-upcoming-connections"},"No upcoming connections")),!o&&r?.length>0&&m.push((({setShowingPastEvents:t})=>/*#__PURE__*/e.createElement(a.Link,{key:"show-past",marginBottom:.5,paddingHorizontal:2,onClick:()=>t(!0)},/*#__PURE__*/e.createElement(d,{theme:"primary",variant:"outline"},"Show connections in the past")))({setShowingPastEvents:c})),o&&(m.push(/*#__PURE__*/e.createElement(P,null,"Past")),r?.forEach(t=>{m.push(/*#__PURE__*/e.createElement(k,{key:`${t.id}`,event:t}))}))),m},O=({dates:r,extra:a,productName:o,localRecordId:c,localRecordType:l,...s})=>{const i={dates:r,productName:o,localRecordId:c,localRecordType:l,extra:a},d=(e=>{const[r,a]=t(!1),{productName:o,localRecordId:c,localRecordType:l}=e,s=()=>{f.any(o,c,l).then(e=>{a(e)})};return n(()=>(s(),document.addEventListener("onConnectionChange",s),()=>{document.removeEventListener("onConnectionChange",s)}),[c]),r})(i),p=(e=>{const[r,a]=t([]),{dates:o,productName:c}=e,l=o&&o.length>0&&["groups"].includes(c.toLowerCase());return n(()=>{if(l){const t=["include=form_group_types",`where[form_group_types][group_type_id]=${e.extra.groupTypeId}`,"where[status]=open"].join("&");E.get(`/calendar/v2/forms?${t}`).then(e=>{e.ok&&a(e.json.data)})}},[]),r})(i),m=d||p.length>0,[u,g]=t(!1);return m?"calendar"===o?/*#__PURE__*/e.createElement(C,{handleOpen:g,connectable:i,open:u,...s}):/*#__PURE__*/e.createElement(R,{handleOpen:g,connectable:i,dates:r,open:u,requestForms:p,...s}):null};export{O as ConnectedEventsDropdown};
import e,{useState as t,useEffect as n,useRef as r}from"react";import a from"@planningcenter/url";import{Dropdown as o,Icon as c,Menu as l,StackView as s,Spinner as i,Collapse as d,Button as p,Divider as m,Text as u}from"@planningcenter/tapestry-react";import*as h from"@planningcenter/icons/paths/calendar";import*as g from"@planningcenter/icons/paths/logomark";import*as E from"@planningcenter/icons/paths/general";class f{}f.post=(e,t={})=>f.request(e,"POST",t),f.get=e=>f.request(e,"GET"),f.request=(e,t,n)=>{const r=new URL(e,a(window.railsEnv)("api")),o={credentials:"include",headers:{Accept:"application/json","Content-Type":"application/json","X-PCO-API-VERSION":"2018-08-01","X-CSRF-Token":window?.Rails?.csrfToken()||document.querySelector('meta[name="csrf-token"]')?.getAttribute("content")||null},method:t,redirect:"follow"};return n&&(o.body=JSON.stringify(n)),fetch(r.href,o).then(e=>e.json().then(t=>({json:t,ok:e.ok,response:e})).catch(()=>({json:null,ok:e.ok,response:e})),e=>(console.warn(e),{json:{data:[]},ok:!1,response:null}))};class v{static any(e,t,n){try{return Promise.resolve(this.get(e,t,n,{perPage:1}).then(e=>e.json?.meta?.count>0))}catch(e){return Promise.reject(e)}}static get(e,t,n,r){try{if(!(e&&t&&n))return Promise.resolve();const{filter:a,sort:o,perPage:c,dates:l}=r,s=function(e){if(e)return function(e){return e.sort(function(e,t){return Date.parse(e)-Date.parse(t)})}(e).find(e=>Date.parse(e)>Date.now())}(l),i=new URLSearchParams({id:t.toString(),product:e,type:n});a&&i.append("filter",a),o&&i.append("sort",o),s&&i.append("date",s),c&&i.append("per_page",c.toString());const d=`/calendar/v2/event_connection_links?${i.toString()}`;return Promise.resolve(f.get(d))}catch(e){return Promise.reject(e)}}}const y=({icon:t})=>/*#__PURE__*/e.createElement("path",{d:t}),k=({children:t,handleOpen:n,dropdownRef:r,...a})=>/*#__PURE__*/e.createElement(o,{closeOnSelect:!1,icon:{marginLeft:.5,children:/*#__PURE__*/e.createElement(y,{icon:h.connections})},id:"connected-events-dropdown",onOpen:()=>n(!0),onClose:()=>n(!1),placement:"bottom-end",size:"md",theme:"primary",tooltip:"Connections",variant:"fill",popoverProps:{minWidth:32},ref:e=>{r&&(r.current=e)},...a},t),w=({event:t,...n})=>{const{name:r,product:a,url:l}=t.attributes,s=`${a.charAt(0).toUpperCase()}${a.slice(1)}`;/*#__PURE__*/return e.createElement(o.Link,{marginBottom:.5,paddingHorizontal:2,to:l,...n},/*#__PURE__*/e.createElement(c,{color:a,marginRight:1},/*#__PURE__*/e.createElement(y,{icon:g["check-ins"===a?"checkIns":a]})),r||s)};w.displayName=o.Item.displayName;const P=({connectable:e,filter:n,sort:r})=>{const[a,o]=t(null),[c,l]=t(!1),{dates:s,productName:i,localRecordId:d,localRecordType:p}=e;return{events:a,fetching:c,fetch:()=>(l(!0),v.get(i,d,p,{filter:n,sort:r,dates:s}).then(({json:e})=>{o(e.data),l(!1)}))}},C=({children:t})=>/*#__PURE__*/e.createElement(l.Heading,{color:"grey-6",paddingHorizontal:2,paddingTop:.5,lineHeight:3},t),b=({connectable:t,handleOpen:r,open:a,...o})=>{const{events:c,fetching:l,fetch:s}=P({connectable:t,sort:"starts_at"});return n(()=>{a&&s()},[t.localRecordId,a]),/*#__PURE__*/e.createElement(k,{handleOpen:r,...o},R({allEvents:c,fetchingEvents:l}))},R=({allEvents:t,fetchingEvents:n})=>{const r=[/*#__PURE__*/e.createElement(C,null,"Connections")];return n||!t?r.push(/*#__PURE__*/e.createElement(s,null,/*#__PURE__*/e.createElement(i,{key:"dropdown-contents-for-all",marginHorizontal:2,marginVertical:.5,align:"center"}))):t.forEach(t=>{r.push(/*#__PURE__*/e.createElement(w,{key:`${t.id}`,event:t}))}),r},_=({isExpandable:t=!1,isLoading:n,clickHandler:r,clickHandlerValue:a})=>/*#__PURE__*/e.createElement(p,{"data-pendo":"connected-events-add-to-calendar",disabled:n,theme:"primary",variant:"outline",flex:1,spacing:1,onClick:()=>r(a),value:a},/*#__PURE__*/e.createElement(c,{color:"calendar"},/*#__PURE__*/e.createElement(y,{icon:g.calendar})),"Add to Calendar",t&&/*#__PURE__*/e.createElement(c,{theme:"primary"},/*#__PURE__*/e.createElement(y,{icon:a?E.downCaret:E.upCaret})),n&&/*#__PURE__*/e.createElement(i,{marginVertical:.5,align:"center"})),S=({onClick:n,requestForms:r,requestFormParams:a})=>{const[o,c]=t(!1),[l,i]=t(!1),m=function(e){try{const t=r.find(t=>t.id===e);return i(!0),Promise.resolve(u(t)).then(function(){n()})}catch(e){return Promise.reject(e)}},u=e=>f.post("/accounts/v2/generate_church_center_login_handshake").then(({json:t})=>{const n=new URL(t.data.attributes.exchange_url),r=new URL(e.attributes.church_center_url),o=JSON.stringify(a);r.searchParams.append("prefill",o),n.searchParams.append("return",r.toString()),window.open(n.toString(),"_blank")}).catch(()=>{alert("Something unexpected happened. Please try again."),i(!1)});return r.length>1?/*#__PURE__*/e.createElement(s,{axis:"vertical",flex:1},/*#__PURE__*/e.createElement(_,{isExpandable:!0,isLoading:l,clickHandler:c,clickHandlerValue:!o}),/*#__PURE__*/e.createElement(d,{open:o},/*#__PURE__*/e.createElement(s,{flex:1,marginHorizontal:-2},r.map(t=>/*#__PURE__*/e.createElement(s,{key:t.id,paddingTop:.5},/*#__PURE__*/e.createElement(p,{justifyContent:"flex-start",onClick:()=>m(t.id),paddingHorizontal:2,radius:0,value:t.id,variant:"naked"},t.attributes.name)))))):/*#__PURE__*/e.createElement(_,{isLoading:l,clickHandler:m,clickHandlerValue:r[0].id})},j=({connectable:a,dates:c=[],handleOpen:l,open:s,requestForms:i,...d})=>{const[p,u]=t(!1),h=a.extra?.requestFormParams,g=h&&Object.keys(h).length>0,E=c.every(e=>new Date(e)<=new Date),f=g&&i.length>0&&!E,{events:v,fetching:y,fetch:w}=P({connectable:a,filter:"upcoming",sort:"starts_at"}),{events:C,fetching:b,fetch:R}=P({connectable:a,filter:"past",sort:"-starts_at"});n(()=>{s&&(w(),R())},[a.localRecordId,s]),n(()=>{u(!1)},[s]);const _=r(null);/*#__PURE__*/return e.createElement(k,{dropdownRef:_,handleOpen:l,...d},O({fetchingUpcoming:y,fetchingPast:b,pastEvents:C,setShowingPastEvents:u,showingPastEvents:p,upcomingEvents:v}),f&&[/*#__PURE__*/e.createElement(m,null),/*#__PURE__*/e.createElement(o.Item,{highlightedColor:"transparent"},/*#__PURE__*/e.createElement(S,{onClick:()=>{_.current.closePopover()},requestForms:i,requestFormParams:h}))])},H=({children:t})=>/*#__PURE__*/e.createElement(u,{color:"grey-6",italic:!0,align:"center",marginHorizontal:2,marginBottom:1,size:4},t),O=({fetchingUpcoming:t,fetchingPast:n,pastEvents:r,showingPastEvents:a,setShowingPastEvents:c,upcomingEvents:l})=>{const d=!l||0===l.length,m=[];return m.push(/*#__PURE__*/e.createElement(C,null,a?"Upcoming":"Connections")),t||n?m.push(/*#__PURE__*/e.createElement(s,null,/*#__PURE__*/e.createElement(i,{key:"dropdown-contents-for-upcoming-past",marginHorizontal:2,marginVertical:.5,align:"center"}))):(l?.forEach(t=>{m.push(/*#__PURE__*/e.createElement(w,{key:`${t.id}`,event:t}))}),d&&m.push(/*#__PURE__*/e.createElement(H,{key:"no-upcoming-connections"},"No upcoming connections")),!a&&r?.length>0&&m.push((({setShowingPastEvents:t})=>/*#__PURE__*/e.createElement(o.Link,{key:"show-past",marginBottom:.5,paddingHorizontal:2,onClick:()=>t(!0)},/*#__PURE__*/e.createElement(p,{theme:"primary",variant:"outline"},"Show connections in the past")))({setShowingPastEvents:c})),a&&(m.push(/*#__PURE__*/e.createElement(C,null,"Past")),r?.forEach(t=>{m.push(/*#__PURE__*/e.createElement(w,{key:`${t.id}`,event:t}))}))),m},x=({dates:r,extra:a,productName:o,localRecordId:c,localRecordType:l,...s})=>{const i={dates:r,productName:o,localRecordId:c,localRecordType:l,extra:a},d=(e=>{const[r,a]=t(!1),{productName:o,localRecordId:c,localRecordType:l}=e,s=()=>{v.any(o,c,l).then(e=>{a(e)})};return n(()=>(s(),document.addEventListener("onConnectionChange",s),()=>{document.removeEventListener("onConnectionChange",s)}),[c]),r})(i),p=(e=>{const[r,a]=t([]),{dates:o,productName:c}=e,l=o&&o.length>0&&["groups"].includes(c.toLowerCase());return n(()=>{if(l){const t=["include=form_group_types",`where[form_group_types][group_type_id]=${e.extra.groupTypeId}`,"where[status]=open"].join("&");f.get(`/calendar/v2/forms?${t}`).then(e=>{e.ok&&a(e.json.data)})}},[]),r})(i),m=d||p.length>0,[u,h]=t(!1);return m?"calendar"===o?/*#__PURE__*/e.createElement(b,{handleOpen:h,connectable:i,open:u,...s}):/*#__PURE__*/e.createElement(j,{handleOpen:h,connectable:i,dates:r,open:u,requestForms:p,...s}):null};export{x as ConnectedEventsDropdown};
//# sourceMappingURL=connected-events.esm.js.map

@@ -1,2 +0,2 @@

var e=require("react"),t=require("@planningcenter/url"),n=require("@planningcenter/tapestry-react"),a=require("@planningcenter/icons/paths/calendar"),r=require("@planningcenter/icons/paths/logomark"),o=require("@planningcenter/icons/paths/general");function c(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}function l(e){if(e&&e.__esModule)return e;var t=Object.create(null);return e&&Object.keys(e).forEach(function(n){if("default"!==n){var a=Object.getOwnPropertyDescriptor(e,n);Object.defineProperty(t,n,a.get?a:{enumerable:!0,get:function(){return e[n]}})}}),t.default=e,t}var i=/*#__PURE__*/c(e),s=/*#__PURE__*/c(t),d=/*#__PURE__*/l(a),u=/*#__PURE__*/l(r),p=/*#__PURE__*/l(o);class m{}m.post=(e,t={})=>m.request(e,"POST",t),m.get=e=>m.request(e,"GET"),m.request=(e,t,n)=>{const a=new URL(e,s.default(window.railsEnv)("api")),r={credentials:"include",headers:{Accept:"application/json","Content-Type":"application/json","X-PCO-API-VERSION":"2018-08-01","X-CSRF-Token":window?.Rails?.csrfToken()||document.querySelector('meta[name="csrf-token"]')?.getAttribute("content")||null},method:t,redirect:"follow"};return n&&(r.body=JSON.stringify(n)),fetch(a.href,r).then(e=>e.json().then(t=>({json:t,ok:e.ok,response:e})).catch(()=>({json:null,ok:e.ok,response:e})),e=>(console.warn(e),{json:{data:[]},ok:!1,response:null}))};class f{static any(e,t,n){try{return Promise.resolve(this.get(e,t,n,{perPage:1}).then(e=>e.json?.meta?.count>0))}catch(e){return Promise.reject(e)}}static get(e,t,n,a){try{if(!(e&&t&&n))return Promise.resolve();const{filter:r,sort:o,perPage:c,dates:l}=a,i=function(e){if(e)return function(e){return e.sort(function(e,t){return Date.parse(e)-Date.parse(t)})}(e).find(e=>Date.parse(e)>Date.now())}(l),s=new URLSearchParams({id:t.toString(),product:e,type:n});r&&s.append("filter",r),o&&s.append("sort",o),i&&s.append("date",i),c&&s.append("per_page",c.toString());const d=`/calendar/v2/event_connection_links?${s.toString()}`;return Promise.resolve(m.get(d))}catch(e){return Promise.reject(e)}}}const g=({icon:e})=>/*#__PURE__*/i.default.createElement("path",{d:e}),h=({children:e,handleOpen:t,...a})=>/*#__PURE__*/i.default.createElement(n.Dropdown,{closeOnSelect:!1,icon:{marginLeft:.5,children:/*#__PURE__*/i.default.createElement(g,{icon:d.connections})},id:"connected-events-dropdown",onOpen:()=>t(!0),onClose:()=>t(!1),placement:"bottom-end",size:"md",theme:"primary",tooltip:"Connections",variant:"fill",popoverProps:{minWidth:32},...a},e),E=({event:e,...t})=>{const{name:a,product:r,url:o}=e.attributes,c=`${r.charAt(0).toUpperCase()}${r.slice(1)}`;/*#__PURE__*/return i.default.createElement(n.Dropdown.Link,{marginBottom:.5,paddingHorizontal:2,to:o,...t},/*#__PURE__*/i.default.createElement(n.Icon,{color:r,marginRight:1},/*#__PURE__*/i.default.createElement(g,{icon:u["check-ins"===r?"checkIns":r]})),a||c)};E.displayName=n.Dropdown.Item.displayName;const v=({connectable:t,filter:n,sort:a})=>{const[r,o]=e.useState(null),[c,l]=e.useState(!1),{dates:i,productName:s,localRecordId:d,localRecordType:u}=t;return{events:r,fetching:c,fetch:()=>(l(!0),f.get(s,d,u,{filter:n,sort:a,dates:i}).then(({json:e})=>{o(e.data),l(!1)}))}},y=({children:e})=>/*#__PURE__*/i.default.createElement(n.Menu.Heading,{color:"grey-6",paddingHorizontal:2,paddingTop:.5,lineHeight:3},e),w=({connectable:t,handleOpen:n,open:a,...r})=>{const{events:o,fetching:c,fetch:l}=v({connectable:t,sort:"starts_at"});return e.useEffect(()=>{a&&l()},[t.localRecordId,a]),/*#__PURE__*/i.default.createElement(h,{handleOpen:n,...r},k({allEvents:o,fetchingEvents:c}))},k=({allEvents:e,fetchingEvents:t})=>{const a=[/*#__PURE__*/i.default.createElement(y,null,"Connections")];return t||!e?a.push(/*#__PURE__*/i.default.createElement(n.StackView,null,/*#__PURE__*/i.default.createElement(n.Spinner,{key:"dropdown-contents-for-all",marginHorizontal:2,marginVertical:.5,align:"center"}))):e.forEach(e=>{a.push(/*#__PURE__*/i.default.createElement(E,{key:`${e.id}`,event:e}))}),a},S=({isExpandable:e=!1,isLoading:t,clickHandler:a,clickHandlerValue:r})=>/*#__PURE__*/i.default.createElement(n.Button,{"data-pendo":"connected-events-add-to-calendar",disabled:t,theme:"primary",variant:"outline",flex:1,spacing:1,onClick:()=>a(r),value:r},/*#__PURE__*/i.default.createElement(n.Icon,{color:"calendar"},/*#__PURE__*/i.default.createElement(g,{icon:u.calendar})),"Add to Calendar",e&&/*#__PURE__*/i.default.createElement(n.Icon,{theme:"primary"},/*#__PURE__*/i.default.createElement(g,{icon:r?p.downCaret:p.upCaret})),t&&/*#__PURE__*/i.default.createElement(n.Spinner,{marginVertical:.5,align:"center"})),P=({requestForms:t,requestFormParams:a})=>{const[r,o]=e.useState(!1),[c,l]=e.useState(!1),s=e=>{const n=t.find(t=>t.id===e);l(!0),d(n)},d=e=>{m.post("/accounts/v2/generate_church_center_login_handshake").then(({json:t})=>{const n=new URL(t.data.attributes.exchange_url),r=new URL(e.attributes.church_center_url),o=JSON.stringify(a);r.searchParams.append("prefill",o),n.searchParams.append("return",r.toString()),window.location.assign(n.toString())}).catch(()=>{alert("Something unexpected happened. Please try again."),l(!1)})};return t.length>1?/*#__PURE__*/i.default.createElement(n.StackView,{axis:"vertical",flex:1},/*#__PURE__*/i.default.createElement(S,{isExpandable:!0,isLoading:c,clickHandler:o,clickHandlerValue:!r}),/*#__PURE__*/i.default.createElement(n.Collapse,{open:r},/*#__PURE__*/i.default.createElement(n.StackView,{flex:1,marginHorizontal:-2},t.map(e=>/*#__PURE__*/i.default.createElement(n.StackView,{key:e.id,paddingTop:.5},/*#__PURE__*/i.default.createElement(n.Button,{justifyContent:"flex-start",onClick:()=>s(e.id),paddingHorizontal:2,radius:0,value:e.id,variant:"naked"},e.attributes.name)))))):/*#__PURE__*/i.default.createElement(S,{isLoading:c,clickHandler:s,clickHandlerValue:t[0].id})},b=({connectable:t,dates:a=[],handleOpen:r,open:o,requestForms:c,...l})=>{const[s,d]=e.useState(!1),u=t.extra?.requestFormParams,p=u&&Object.keys(u).length>0,m=a.every(e=>new Date(e)<=new Date),f=p&&c.length>0&&!m,{events:g,fetching:E,fetch:y}=v({connectable:t,filter:"upcoming",sort:"starts_at"}),{events:w,fetching:k,fetch:S}=v({connectable:t,filter:"past",sort:"-starts_at"});return e.useEffect(()=>{o&&(y(),S())},[t.localRecordId,o]),e.useEffect(()=>{d(!1)},[o]),/*#__PURE__*/i.default.createElement(h,{handleOpen:r,...l},_({fetchingUpcoming:E,fetchingPast:k,pastEvents:w,setShowingPastEvents:d,showingPastEvents:s,upcomingEvents:g}),f&&[/*#__PURE__*/i.default.createElement(n.Divider,null),/*#__PURE__*/i.default.createElement(n.Dropdown.Item,{highlightedColor:"transparent"},/*#__PURE__*/i.default.createElement(P,{requestForms:c,requestFormParams:u}))])},C=({children:e})=>/*#__PURE__*/i.default.createElement(n.Text,{color:"grey-6",italic:!0,align:"center",marginHorizontal:2,marginBottom:1,size:4},e),_=({fetchingUpcoming:e,fetchingPast:t,pastEvents:a,showingPastEvents:r,setShowingPastEvents:o,upcomingEvents:c})=>{const l=!c||0===c.length,s=[];return s.push(/*#__PURE__*/i.default.createElement(y,null,r?"Upcoming":"Connections")),e||t?s.push(/*#__PURE__*/i.default.createElement(n.StackView,null,/*#__PURE__*/i.default.createElement(n.Spinner,{key:"dropdown-contents-for-upcoming-past",marginHorizontal:2,marginVertical:.5,align:"center"}))):(c?.forEach(e=>{s.push(/*#__PURE__*/i.default.createElement(E,{key:`${e.id}`,event:e}))}),l&&s.push(/*#__PURE__*/i.default.createElement(C,{key:"no-upcoming-connections"},"No upcoming connections")),!r&&a?.length>0&&s.push((({setShowingPastEvents:e})=>/*#__PURE__*/i.default.createElement(n.Dropdown.Link,{key:"show-past",marginBottom:.5,paddingHorizontal:2,onClick:()=>e(!0)},/*#__PURE__*/i.default.createElement(n.Button,{theme:"primary",variant:"outline"},"Show connections in the past")))({setShowingPastEvents:o})),r&&(s.push(/*#__PURE__*/i.default.createElement(y,null,"Past")),a?.forEach(e=>{s.push(/*#__PURE__*/i.default.createElement(E,{key:`${e.id}`,event:e}))}))),s};exports.ConnectedEventsDropdown=({dates:t,extra:n,productName:a,localRecordId:r,localRecordType:o,...c})=>{const l={dates:t,productName:a,localRecordId:r,localRecordType:o,extra:n},s=(t=>{const[n,a]=e.useState(!1),{productName:r,localRecordId:o,localRecordType:c}=t,l=()=>{f.any(r,o,c).then(e=>{a(e)})};return e.useEffect(()=>(l(),document.addEventListener("onConnectionChange",l),()=>{document.removeEventListener("onConnectionChange",l)}),[o]),n})(l),d=(t=>{const[n,a]=e.useState([]),{dates:r,productName:o}=t,c=r&&r.length>0&&["groups"].includes(o.toLowerCase());return e.useEffect(()=>{if(c){const e=["include=form_group_types",`where[form_group_types][group_type_id]=${t.extra.groupTypeId}`,"where[status]=open"].join("&");m.get(`/calendar/v2/forms?${e}`).then(e=>{e.ok&&a(e.json.data)})}},[]),n})(l),u=s||d.length>0,[p,g]=e.useState(!1);return u?"calendar"===a?/*#__PURE__*/i.default.createElement(w,{handleOpen:g,connectable:l,open:p,...c}):/*#__PURE__*/i.default.createElement(b,{handleOpen:g,connectable:l,dates:t,open:p,requestForms:d,...c}):null};
var e=require("react"),t=require("@planningcenter/url"),n=require("@planningcenter/tapestry-react"),a=require("@planningcenter/icons/paths/calendar"),r=require("@planningcenter/icons/paths/logomark"),o=require("@planningcenter/icons/paths/general");function c(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}function l(e){if(e&&e.__esModule)return e;var t=Object.create(null);return e&&Object.keys(e).forEach(function(n){if("default"!==n){var a=Object.getOwnPropertyDescriptor(e,n);Object.defineProperty(t,n,a.get?a:{enumerable:!0,get:function(){return e[n]}})}}),t.default=e,t}var i=/*#__PURE__*/c(e),s=/*#__PURE__*/c(t),d=/*#__PURE__*/l(a),u=/*#__PURE__*/l(r),p=/*#__PURE__*/l(o);class m{}m.post=(e,t={})=>m.request(e,"POST",t),m.get=e=>m.request(e,"GET"),m.request=(e,t,n)=>{const a=new URL(e,s.default(window.railsEnv)("api")),r={credentials:"include",headers:{Accept:"application/json","Content-Type":"application/json","X-PCO-API-VERSION":"2018-08-01","X-CSRF-Token":window?.Rails?.csrfToken()||document.querySelector('meta[name="csrf-token"]')?.getAttribute("content")||null},method:t,redirect:"follow"};return n&&(r.body=JSON.stringify(n)),fetch(a.href,r).then(e=>e.json().then(t=>({json:t,ok:e.ok,response:e})).catch(()=>({json:null,ok:e.ok,response:e})),e=>(console.warn(e),{json:{data:[]},ok:!1,response:null}))};class f{static any(e,t,n){try{return Promise.resolve(this.get(e,t,n,{perPage:1}).then(e=>e.json?.meta?.count>0))}catch(e){return Promise.reject(e)}}static get(e,t,n,a){try{if(!(e&&t&&n))return Promise.resolve();const{filter:r,sort:o,perPage:c,dates:l}=a,i=function(e){if(e)return function(e){return e.sort(function(e,t){return Date.parse(e)-Date.parse(t)})}(e).find(e=>Date.parse(e)>Date.now())}(l),s=new URLSearchParams({id:t.toString(),product:e,type:n});r&&s.append("filter",r),o&&s.append("sort",o),i&&s.append("date",i),c&&s.append("per_page",c.toString());const d=`/calendar/v2/event_connection_links?${s.toString()}`;return Promise.resolve(m.get(d))}catch(e){return Promise.reject(e)}}}const h=({icon:e})=>/*#__PURE__*/i.default.createElement("path",{d:e}),g=({children:e,handleOpen:t,dropdownRef:a,...r})=>/*#__PURE__*/i.default.createElement(n.Dropdown,{closeOnSelect:!1,icon:{marginLeft:.5,children:/*#__PURE__*/i.default.createElement(h,{icon:d.connections})},id:"connected-events-dropdown",onOpen:()=>t(!0),onClose:()=>t(!1),placement:"bottom-end",size:"md",theme:"primary",tooltip:"Connections",variant:"fill",popoverProps:{minWidth:32},ref:e=>{a&&(a.current=e)},...r},e),E=({event:e,...t})=>{const{name:a,product:r,url:o}=e.attributes,c=`${r.charAt(0).toUpperCase()}${r.slice(1)}`;/*#__PURE__*/return i.default.createElement(n.Dropdown.Link,{marginBottom:.5,paddingHorizontal:2,to:o,...t},/*#__PURE__*/i.default.createElement(n.Icon,{color:r,marginRight:1},/*#__PURE__*/i.default.createElement(h,{icon:u["check-ins"===r?"checkIns":r]})),a||c)};E.displayName=n.Dropdown.Item.displayName;const v=({connectable:t,filter:n,sort:a})=>{const[r,o]=e.useState(null),[c,l]=e.useState(!1),{dates:i,productName:s,localRecordId:d,localRecordType:u}=t;return{events:r,fetching:c,fetch:()=>(l(!0),f.get(s,d,u,{filter:n,sort:a,dates:i}).then(({json:e})=>{o(e.data),l(!1)}))}},k=({children:e})=>/*#__PURE__*/i.default.createElement(n.Menu.Heading,{color:"grey-6",paddingHorizontal:2,paddingTop:.5,lineHeight:3},e),w=({connectable:t,handleOpen:n,open:a,...r})=>{const{events:o,fetching:c,fetch:l}=v({connectable:t,sort:"starts_at"});return e.useEffect(()=>{a&&l()},[t.localRecordId,a]),/*#__PURE__*/i.default.createElement(g,{handleOpen:n,...r},y({allEvents:o,fetchingEvents:c}))},y=({allEvents:e,fetchingEvents:t})=>{const a=[/*#__PURE__*/i.default.createElement(k,null,"Connections")];return t||!e?a.push(/*#__PURE__*/i.default.createElement(n.StackView,null,/*#__PURE__*/i.default.createElement(n.Spinner,{key:"dropdown-contents-for-all",marginHorizontal:2,marginVertical:.5,align:"center"}))):e.forEach(e=>{a.push(/*#__PURE__*/i.default.createElement(E,{key:`${e.id}`,event:e}))}),a},S=({isExpandable:e=!1,isLoading:t,clickHandler:a,clickHandlerValue:r})=>/*#__PURE__*/i.default.createElement(n.Button,{"data-pendo":"connected-events-add-to-calendar",disabled:t,theme:"primary",variant:"outline",flex:1,spacing:1,onClick:()=>a(r),value:r},/*#__PURE__*/i.default.createElement(n.Icon,{color:"calendar"},/*#__PURE__*/i.default.createElement(h,{icon:u.calendar})),"Add to Calendar",e&&/*#__PURE__*/i.default.createElement(n.Icon,{theme:"primary"},/*#__PURE__*/i.default.createElement(h,{icon:r?p.downCaret:p.upCaret})),t&&/*#__PURE__*/i.default.createElement(n.Spinner,{marginVertical:.5,align:"center"})),P=({onClick:t,requestForms:a,requestFormParams:r})=>{const[o,c]=e.useState(!1),[l,s]=e.useState(!1),d=function(e){try{const n=a.find(t=>t.id===e);return s(!0),Promise.resolve(u(n)).then(function(){t()})}catch(e){return Promise.reject(e)}},u=e=>m.post("/accounts/v2/generate_church_center_login_handshake").then(({json:t})=>{const n=new URL(t.data.attributes.exchange_url),a=new URL(e.attributes.church_center_url),o=JSON.stringify(r);a.searchParams.append("prefill",o),n.searchParams.append("return",a.toString()),window.open(n.toString(),"_blank")}).catch(()=>{alert("Something unexpected happened. Please try again."),s(!1)});return a.length>1?/*#__PURE__*/i.default.createElement(n.StackView,{axis:"vertical",flex:1},/*#__PURE__*/i.default.createElement(S,{isExpandable:!0,isLoading:l,clickHandler:c,clickHandlerValue:!o}),/*#__PURE__*/i.default.createElement(n.Collapse,{open:o},/*#__PURE__*/i.default.createElement(n.StackView,{flex:1,marginHorizontal:-2},a.map(e=>/*#__PURE__*/i.default.createElement(n.StackView,{key:e.id,paddingTop:.5},/*#__PURE__*/i.default.createElement(n.Button,{justifyContent:"flex-start",onClick:()=>d(e.id),paddingHorizontal:2,radius:0,value:e.id,variant:"naked"},e.attributes.name)))))):/*#__PURE__*/i.default.createElement(S,{isLoading:l,clickHandler:d,clickHandlerValue:a[0].id})},b=({connectable:t,dates:a=[],handleOpen:r,open:o,requestForms:c,...l})=>{const[s,d]=e.useState(!1),u=t.extra?.requestFormParams,p=u&&Object.keys(u).length>0,m=a.every(e=>new Date(e)<=new Date),f=p&&c.length>0&&!m,{events:h,fetching:E,fetch:k}=v({connectable:t,filter:"upcoming",sort:"starts_at"}),{events:w,fetching:y,fetch:S}=v({connectable:t,filter:"past",sort:"-starts_at"});e.useEffect(()=>{o&&(k(),S())},[t.localRecordId,o]),e.useEffect(()=>{d(!1)},[o]);const b=e.useRef(null);/*#__PURE__*/return i.default.createElement(g,{dropdownRef:b,handleOpen:r,...l},_({fetchingUpcoming:E,fetchingPast:y,pastEvents:w,setShowingPastEvents:d,showingPastEvents:s,upcomingEvents:h}),f&&[/*#__PURE__*/i.default.createElement(n.Divider,null),/*#__PURE__*/i.default.createElement(n.Dropdown.Item,{highlightedColor:"transparent"},/*#__PURE__*/i.default.createElement(P,{onClick:()=>{b.current.closePopover()},requestForms:c,requestFormParams:u}))])},C=({children:e})=>/*#__PURE__*/i.default.createElement(n.Text,{color:"grey-6",italic:!0,align:"center",marginHorizontal:2,marginBottom:1,size:4},e),_=({fetchingUpcoming:e,fetchingPast:t,pastEvents:a,showingPastEvents:r,setShowingPastEvents:o,upcomingEvents:c})=>{const l=!c||0===c.length,s=[];return s.push(/*#__PURE__*/i.default.createElement(k,null,r?"Upcoming":"Connections")),e||t?s.push(/*#__PURE__*/i.default.createElement(n.StackView,null,/*#__PURE__*/i.default.createElement(n.Spinner,{key:"dropdown-contents-for-upcoming-past",marginHorizontal:2,marginVertical:.5,align:"center"}))):(c?.forEach(e=>{s.push(/*#__PURE__*/i.default.createElement(E,{key:`${e.id}`,event:e}))}),l&&s.push(/*#__PURE__*/i.default.createElement(C,{key:"no-upcoming-connections"},"No upcoming connections")),!r&&a?.length>0&&s.push((({setShowingPastEvents:e})=>/*#__PURE__*/i.default.createElement(n.Dropdown.Link,{key:"show-past",marginBottom:.5,paddingHorizontal:2,onClick:()=>e(!0)},/*#__PURE__*/i.default.createElement(n.Button,{theme:"primary",variant:"outline"},"Show connections in the past")))({setShowingPastEvents:o})),r&&(s.push(/*#__PURE__*/i.default.createElement(k,null,"Past")),a?.forEach(e=>{s.push(/*#__PURE__*/i.default.createElement(E,{key:`${e.id}`,event:e}))}))),s};exports.ConnectedEventsDropdown=({dates:t,extra:n,productName:a,localRecordId:r,localRecordType:o,...c})=>{const l={dates:t,productName:a,localRecordId:r,localRecordType:o,extra:n},s=(t=>{const[n,a]=e.useState(!1),{productName:r,localRecordId:o,localRecordType:c}=t,l=()=>{f.any(r,o,c).then(e=>{a(e)})};return e.useEffect(()=>(l(),document.addEventListener("onConnectionChange",l),()=>{document.removeEventListener("onConnectionChange",l)}),[o]),n})(l),d=(t=>{const[n,a]=e.useState([]),{dates:r,productName:o}=t,c=r&&r.length>0&&["groups"].includes(o.toLowerCase());return e.useEffect(()=>{if(c){const e=["include=form_group_types",`where[form_group_types][group_type_id]=${t.extra.groupTypeId}`,"where[status]=open"].join("&");m.get(`/calendar/v2/forms?${e}`).then(e=>{e.ok&&a(e.json.data)})}},[]),n})(l),u=s||d.length>0,[p,h]=e.useState(!1);return u?"calendar"===a?/*#__PURE__*/i.default.createElement(w,{handleOpen:h,connectable:l,open:p,...c}):/*#__PURE__*/i.default.createElement(b,{handleOpen:h,connectable:l,dates:t,open:p,requestForms:d,...c}):null};
//# sourceMappingURL=connected-events.js.map

@@ -1,2 +0,2 @@

!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("react"),require("@planningcenter/url"),require("@planningcenter/tapestry-react"),require("@planningcenter/icons/paths/calendar"),require("@planningcenter/icons/paths/logomark"),require("@planningcenter/icons/paths/general")):"function"==typeof define&&define.amd?define(["exports","react","@planningcenter/url","@planningcenter/tapestry-react","@planningcenter/icons/paths/calendar","@planningcenter/icons/paths/logomark","@planningcenter/icons/paths/general"],t):t((e||self).connectedEvents={},e.react,e.pcoUrl,e.tapestryReact,e.calendar,e.logomark,e.general)}(this,function(e,t,n,a,r,o,c){function l(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}function i(e){if(e&&e.__esModule)return e;var t=Object.create(null);return e&&Object.keys(e).forEach(function(n){if("default"!==n){var a=Object.getOwnPropertyDescriptor(e,n);Object.defineProperty(t,n,a.get?a:{enumerable:!0,get:function(){return e[n]}})}}),t.default=e,t}var s=/*#__PURE__*/l(t),d=/*#__PURE__*/l(n),u=/*#__PURE__*/i(r),p=/*#__PURE__*/i(o),f=/*#__PURE__*/i(c);class m{}m.post=(e,t={})=>m.request(e,"POST",t),m.get=e=>m.request(e,"GET"),m.request=(e,t,n)=>{const a=new URL(e,d.default(window.railsEnv)("api")),r={credentials:"include",headers:{Accept:"application/json","Content-Type":"application/json","X-PCO-API-VERSION":"2018-08-01","X-CSRF-Token":window?.Rails?.csrfToken()||document.querySelector('meta[name="csrf-token"]')?.getAttribute("content")||null},method:t,redirect:"follow"};return n&&(r.body=JSON.stringify(n)),fetch(a.href,r).then(e=>e.json().then(t=>({json:t,ok:e.ok,response:e})).catch(()=>({json:null,ok:e.ok,response:e})),e=>(console.warn(e),{json:{data:[]},ok:!1,response:null}))};class g{static any(e,t,n){try{return Promise.resolve(this.get(e,t,n,{perPage:1}).then(e=>e.json?.meta?.count>0))}catch(e){return Promise.reject(e)}}static get(e,t,n,a){try{if(!(e&&t&&n))return Promise.resolve();const{filter:r,sort:o,perPage:c,dates:l}=a,i=function(e){if(e)return function(e){return e.sort(function(e,t){return Date.parse(e)-Date.parse(t)})}(e).find(e=>Date.parse(e)>Date.now())}(l),s=new URLSearchParams({id:t.toString(),product:e,type:n});r&&s.append("filter",r),o&&s.append("sort",o),i&&s.append("date",i),c&&s.append("per_page",c.toString());const d=`/calendar/v2/event_connection_links?${s.toString()}`;return Promise.resolve(m.get(d))}catch(e){return Promise.reject(e)}}}const h=({icon:e})=>/*#__PURE__*/s.default.createElement("path",{d:e}),E=({children:e,handleOpen:t,...n})=>/*#__PURE__*/s.default.createElement(a.Dropdown,{closeOnSelect:!1,icon:{marginLeft:.5,children:/*#__PURE__*/s.default.createElement(h,{icon:u.connections})},id:"connected-events-dropdown",onOpen:()=>t(!0),onClose:()=>t(!1),placement:"bottom-end",size:"md",theme:"primary",tooltip:"Connections",variant:"fill",popoverProps:{minWidth:32},...n},e),v=({event:e,...t})=>{const{name:n,product:r,url:o}=e.attributes,c=`${r.charAt(0).toUpperCase()}${r.slice(1)}`;/*#__PURE__*/return s.default.createElement(a.Dropdown.Link,{marginBottom:.5,paddingHorizontal:2,to:o,...t},/*#__PURE__*/s.default.createElement(a.Icon,{color:r,marginRight:1},/*#__PURE__*/s.default.createElement(h,{icon:p["check-ins"===r?"checkIns":r]})),n||c)};v.displayName=a.Dropdown.Item.displayName;const y=({connectable:e,filter:n,sort:a})=>{const[r,o]=t.useState(null),[c,l]=t.useState(!1),{dates:i,productName:s,localRecordId:d,localRecordType:u}=e;return{events:r,fetching:c,fetch:()=>(l(!0),g.get(s,d,u,{filter:n,sort:a,dates:i}).then(({json:e})=>{o(e.data),l(!1)}))}},k=({children:e})=>/*#__PURE__*/s.default.createElement(a.Menu.Heading,{color:"grey-6",paddingHorizontal:2,paddingTop:.5,lineHeight:3},e),w=({connectable:e,handleOpen:n,open:a,...r})=>{const{events:o,fetching:c,fetch:l}=y({connectable:e,sort:"starts_at"});return t.useEffect(()=>{a&&l()},[e.localRecordId,a]),/*#__PURE__*/s.default.createElement(E,{handleOpen:n,...r},S({allEvents:o,fetchingEvents:c}))},S=({allEvents:e,fetchingEvents:t})=>{const n=[/*#__PURE__*/s.default.createElement(k,null,"Connections")];return t||!e?n.push(/*#__PURE__*/s.default.createElement(a.StackView,null,/*#__PURE__*/s.default.createElement(a.Spinner,{key:"dropdown-contents-for-all",marginHorizontal:2,marginVertical:.5,align:"center"}))):e.forEach(e=>{n.push(/*#__PURE__*/s.default.createElement(v,{key:`${e.id}`,event:e}))}),n},P=({isExpandable:e=!1,isLoading:t,clickHandler:n,clickHandlerValue:r})=>/*#__PURE__*/s.default.createElement(a.Button,{"data-pendo":"connected-events-add-to-calendar",disabled:t,theme:"primary",variant:"outline",flex:1,spacing:1,onClick:()=>n(r),value:r},/*#__PURE__*/s.default.createElement(a.Icon,{color:"calendar"},/*#__PURE__*/s.default.createElement(h,{icon:p.calendar})),"Add to Calendar",e&&/*#__PURE__*/s.default.createElement(a.Icon,{theme:"primary"},/*#__PURE__*/s.default.createElement(h,{icon:r?f.downCaret:f.upCaret})),t&&/*#__PURE__*/s.default.createElement(a.Spinner,{marginVertical:.5,align:"center"})),b=({requestForms:e,requestFormParams:n})=>{const[r,o]=t.useState(!1),[c,l]=t.useState(!1),i=t=>{const n=e.find(e=>e.id===t);l(!0),d(n)},d=e=>{m.post("/accounts/v2/generate_church_center_login_handshake").then(({json:t})=>{const a=new URL(t.data.attributes.exchange_url),r=new URL(e.attributes.church_center_url),o=JSON.stringify(n);r.searchParams.append("prefill",o),a.searchParams.append("return",r.toString()),window.location.assign(a.toString())}).catch(()=>{alert("Something unexpected happened. Please try again."),l(!1)})};return e.length>1?/*#__PURE__*/s.default.createElement(a.StackView,{axis:"vertical",flex:1},/*#__PURE__*/s.default.createElement(P,{isExpandable:!0,isLoading:c,clickHandler:o,clickHandlerValue:!r}),/*#__PURE__*/s.default.createElement(a.Collapse,{open:r},/*#__PURE__*/s.default.createElement(a.StackView,{flex:1,marginHorizontal:-2},e.map(e=>/*#__PURE__*/s.default.createElement(a.StackView,{key:e.id,paddingTop:.5},/*#__PURE__*/s.default.createElement(a.Button,{justifyContent:"flex-start",onClick:()=>i(e.id),paddingHorizontal:2,radius:0,value:e.id,variant:"naked"},e.attributes.name)))))):/*#__PURE__*/s.default.createElement(P,{isLoading:c,clickHandler:i,clickHandlerValue:e[0].id})},C=({connectable:e,dates:n=[],handleOpen:r,open:o,requestForms:c,...l})=>{const[i,d]=t.useState(!1),u=e.extra?.requestFormParams,p=u&&Object.keys(u).length>0,f=n.every(e=>new Date(e)<=new Date),m=p&&c.length>0&&!f,{events:g,fetching:h,fetch:v}=y({connectable:e,filter:"upcoming",sort:"starts_at"}),{events:k,fetching:w,fetch:S}=y({connectable:e,filter:"past",sort:"-starts_at"});return t.useEffect(()=>{o&&(v(),S())},[e.localRecordId,o]),t.useEffect(()=>{d(!1)},[o]),/*#__PURE__*/s.default.createElement(E,{handleOpen:r,...l},_({fetchingUpcoming:h,fetchingPast:w,pastEvents:k,setShowingPastEvents:d,showingPastEvents:i,upcomingEvents:g}),m&&[/*#__PURE__*/s.default.createElement(a.Divider,null),/*#__PURE__*/s.default.createElement(a.Dropdown.Item,{highlightedColor:"transparent"},/*#__PURE__*/s.default.createElement(b,{requestForms:c,requestFormParams:u}))])},j=({children:e})=>/*#__PURE__*/s.default.createElement(a.Text,{color:"grey-6",italic:!0,align:"center",marginHorizontal:2,marginBottom:1,size:4},e),_=({fetchingUpcoming:e,fetchingPast:t,pastEvents:n,showingPastEvents:r,setShowingPastEvents:o,upcomingEvents:c})=>{const l=!c||0===c.length,i=[];return i.push(/*#__PURE__*/s.default.createElement(k,null,r?"Upcoming":"Connections")),e||t?i.push(/*#__PURE__*/s.default.createElement(a.StackView,null,/*#__PURE__*/s.default.createElement(a.Spinner,{key:"dropdown-contents-for-upcoming-past",marginHorizontal:2,marginVertical:.5,align:"center"}))):(c?.forEach(e=>{i.push(/*#__PURE__*/s.default.createElement(v,{key:`${e.id}`,event:e}))}),l&&i.push(/*#__PURE__*/s.default.createElement(j,{key:"no-upcoming-connections"},"No upcoming connections")),!r&&n?.length>0&&i.push((({setShowingPastEvents:e})=>/*#__PURE__*/s.default.createElement(a.Dropdown.Link,{key:"show-past",marginBottom:.5,paddingHorizontal:2,onClick:()=>e(!0)},/*#__PURE__*/s.default.createElement(a.Button,{theme:"primary",variant:"outline"},"Show connections in the past")))({setShowingPastEvents:o})),r&&(i.push(/*#__PURE__*/s.default.createElement(k,null,"Past")),n?.forEach(e=>{i.push(/*#__PURE__*/s.default.createElement(v,{key:`${e.id}`,event:e}))}))),i};e.ConnectedEventsDropdown=({dates:e,extra:n,productName:a,localRecordId:r,localRecordType:o,...c})=>{const l={dates:e,productName:a,localRecordId:r,localRecordType:o,extra:n},i=(e=>{const[n,a]=t.useState(!1),{productName:r,localRecordId:o,localRecordType:c}=e,l=()=>{g.any(r,o,c).then(e=>{a(e)})};return t.useEffect(()=>(l(),document.addEventListener("onConnectionChange",l),()=>{document.removeEventListener("onConnectionChange",l)}),[o]),n})(l),d=(e=>{const[n,a]=t.useState([]),{dates:r,productName:o}=e,c=r&&r.length>0&&["groups"].includes(o.toLowerCase());return t.useEffect(()=>{if(c){const t=["include=form_group_types",`where[form_group_types][group_type_id]=${e.extra.groupTypeId}`,"where[status]=open"].join("&");m.get(`/calendar/v2/forms?${t}`).then(e=>{e.ok&&a(e.json.data)})}},[]),n})(l),u=i||d.length>0,[p,f]=t.useState(!1);return u?"calendar"===a?/*#__PURE__*/s.default.createElement(w,{handleOpen:f,connectable:l,open:p,...c}):/*#__PURE__*/s.default.createElement(C,{handleOpen:f,connectable:l,dates:e,open:p,requestForms:d,...c}):null}});
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("react"),require("@planningcenter/url"),require("@planningcenter/tapestry-react"),require("@planningcenter/icons/paths/calendar"),require("@planningcenter/icons/paths/logomark"),require("@planningcenter/icons/paths/general")):"function"==typeof define&&define.amd?define(["exports","react","@planningcenter/url","@planningcenter/tapestry-react","@planningcenter/icons/paths/calendar","@planningcenter/icons/paths/logomark","@planningcenter/icons/paths/general"],t):t((e||self).connectedEvents={},e.react,e.pcoUrl,e.tapestryReact,e.calendar,e.logomark,e.general)}(this,function(e,t,n,a,r,o,c){function l(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}function i(e){if(e&&e.__esModule)return e;var t=Object.create(null);return e&&Object.keys(e).forEach(function(n){if("default"!==n){var a=Object.getOwnPropertyDescriptor(e,n);Object.defineProperty(t,n,a.get?a:{enumerable:!0,get:function(){return e[n]}})}}),t.default=e,t}var s=/*#__PURE__*/l(t),d=/*#__PURE__*/l(n),u=/*#__PURE__*/i(r),p=/*#__PURE__*/i(o),f=/*#__PURE__*/i(c);class m{}m.post=(e,t={})=>m.request(e,"POST",t),m.get=e=>m.request(e,"GET"),m.request=(e,t,n)=>{const a=new URL(e,d.default(window.railsEnv)("api")),r={credentials:"include",headers:{Accept:"application/json","Content-Type":"application/json","X-PCO-API-VERSION":"2018-08-01","X-CSRF-Token":window?.Rails?.csrfToken()||document.querySelector('meta[name="csrf-token"]')?.getAttribute("content")||null},method:t,redirect:"follow"};return n&&(r.body=JSON.stringify(n)),fetch(a.href,r).then(e=>e.json().then(t=>({json:t,ok:e.ok,response:e})).catch(()=>({json:null,ok:e.ok,response:e})),e=>(console.warn(e),{json:{data:[]},ok:!1,response:null}))};class g{static any(e,t,n){try{return Promise.resolve(this.get(e,t,n,{perPage:1}).then(e=>e.json?.meta?.count>0))}catch(e){return Promise.reject(e)}}static get(e,t,n,a){try{if(!(e&&t&&n))return Promise.resolve();const{filter:r,sort:o,perPage:c,dates:l}=a,i=function(e){if(e)return function(e){return e.sort(function(e,t){return Date.parse(e)-Date.parse(t)})}(e).find(e=>Date.parse(e)>Date.now())}(l),s=new URLSearchParams({id:t.toString(),product:e,type:n});r&&s.append("filter",r),o&&s.append("sort",o),i&&s.append("date",i),c&&s.append("per_page",c.toString());const d=`/calendar/v2/event_connection_links?${s.toString()}`;return Promise.resolve(m.get(d))}catch(e){return Promise.reject(e)}}}const h=({icon:e})=>/*#__PURE__*/s.default.createElement("path",{d:e}),E=({children:e,handleOpen:t,dropdownRef:n,...r})=>/*#__PURE__*/s.default.createElement(a.Dropdown,{closeOnSelect:!1,icon:{marginLeft:.5,children:/*#__PURE__*/s.default.createElement(h,{icon:u.connections})},id:"connected-events-dropdown",onOpen:()=>t(!0),onClose:()=>t(!1),placement:"bottom-end",size:"md",theme:"primary",tooltip:"Connections",variant:"fill",popoverProps:{minWidth:32},ref:e=>{n&&(n.current=e)},...r},e),v=({event:e,...t})=>{const{name:n,product:r,url:o}=e.attributes,c=`${r.charAt(0).toUpperCase()}${r.slice(1)}`;/*#__PURE__*/return s.default.createElement(a.Dropdown.Link,{marginBottom:.5,paddingHorizontal:2,to:o,...t},/*#__PURE__*/s.default.createElement(a.Icon,{color:r,marginRight:1},/*#__PURE__*/s.default.createElement(h,{icon:p["check-ins"===r?"checkIns":r]})),n||c)};v.displayName=a.Dropdown.Item.displayName;const y=({connectable:e,filter:n,sort:a})=>{const[r,o]=t.useState(null),[c,l]=t.useState(!1),{dates:i,productName:s,localRecordId:d,localRecordType:u}=e;return{events:r,fetching:c,fetch:()=>(l(!0),g.get(s,d,u,{filter:n,sort:a,dates:i}).then(({json:e})=>{o(e.data),l(!1)}))}},k=({children:e})=>/*#__PURE__*/s.default.createElement(a.Menu.Heading,{color:"grey-6",paddingHorizontal:2,paddingTop:.5,lineHeight:3},e),w=({connectable:e,handleOpen:n,open:a,...r})=>{const{events:o,fetching:c,fetch:l}=y({connectable:e,sort:"starts_at"});return t.useEffect(()=>{a&&l()},[e.localRecordId,a]),/*#__PURE__*/s.default.createElement(E,{handleOpen:n,...r},S({allEvents:o,fetchingEvents:c}))},S=({allEvents:e,fetchingEvents:t})=>{const n=[/*#__PURE__*/s.default.createElement(k,null,"Connections")];return t||!e?n.push(/*#__PURE__*/s.default.createElement(a.StackView,null,/*#__PURE__*/s.default.createElement(a.Spinner,{key:"dropdown-contents-for-all",marginHorizontal:2,marginVertical:.5,align:"center"}))):e.forEach(e=>{n.push(/*#__PURE__*/s.default.createElement(v,{key:`${e.id}`,event:e}))}),n},P=({isExpandable:e=!1,isLoading:t,clickHandler:n,clickHandlerValue:r})=>/*#__PURE__*/s.default.createElement(a.Button,{"data-pendo":"connected-events-add-to-calendar",disabled:t,theme:"primary",variant:"outline",flex:1,spacing:1,onClick:()=>n(r),value:r},/*#__PURE__*/s.default.createElement(a.Icon,{color:"calendar"},/*#__PURE__*/s.default.createElement(h,{icon:p.calendar})),"Add to Calendar",e&&/*#__PURE__*/s.default.createElement(a.Icon,{theme:"primary"},/*#__PURE__*/s.default.createElement(h,{icon:r?f.downCaret:f.upCaret})),t&&/*#__PURE__*/s.default.createElement(a.Spinner,{marginVertical:.5,align:"center"})),b=({onClick:e,requestForms:n,requestFormParams:r})=>{const[o,c]=t.useState(!1),[l,i]=t.useState(!1),d=function(t){try{const a=n.find(e=>e.id===t);return i(!0),Promise.resolve(u(a)).then(function(){e()})}catch(e){return Promise.reject(e)}},u=e=>m.post("/accounts/v2/generate_church_center_login_handshake").then(({json:t})=>{const n=new URL(t.data.attributes.exchange_url),a=new URL(e.attributes.church_center_url),o=JSON.stringify(r);a.searchParams.append("prefill",o),n.searchParams.append("return",a.toString()),window.open(n.toString(),"_blank")}).catch(()=>{alert("Something unexpected happened. Please try again."),i(!1)});return n.length>1?/*#__PURE__*/s.default.createElement(a.StackView,{axis:"vertical",flex:1},/*#__PURE__*/s.default.createElement(P,{isExpandable:!0,isLoading:l,clickHandler:c,clickHandlerValue:!o}),/*#__PURE__*/s.default.createElement(a.Collapse,{open:o},/*#__PURE__*/s.default.createElement(a.StackView,{flex:1,marginHorizontal:-2},n.map(e=>/*#__PURE__*/s.default.createElement(a.StackView,{key:e.id,paddingTop:.5},/*#__PURE__*/s.default.createElement(a.Button,{justifyContent:"flex-start",onClick:()=>d(e.id),paddingHorizontal:2,radius:0,value:e.id,variant:"naked"},e.attributes.name)))))):/*#__PURE__*/s.default.createElement(P,{isLoading:l,clickHandler:d,clickHandlerValue:n[0].id})},C=({connectable:e,dates:n=[],handleOpen:r,open:o,requestForms:c,...l})=>{const[i,d]=t.useState(!1),u=e.extra?.requestFormParams,p=u&&Object.keys(u).length>0,f=n.every(e=>new Date(e)<=new Date),m=p&&c.length>0&&!f,{events:g,fetching:h,fetch:v}=y({connectable:e,filter:"upcoming",sort:"starts_at"}),{events:k,fetching:w,fetch:S}=y({connectable:e,filter:"past",sort:"-starts_at"});t.useEffect(()=>{o&&(v(),S())},[e.localRecordId,o]),t.useEffect(()=>{d(!1)},[o]);const P=t.useRef(null);/*#__PURE__*/return s.default.createElement(E,{dropdownRef:P,handleOpen:r,...l},R({fetchingUpcoming:h,fetchingPast:w,pastEvents:k,setShowingPastEvents:d,showingPastEvents:i,upcomingEvents:g}),m&&[/*#__PURE__*/s.default.createElement(a.Divider,null),/*#__PURE__*/s.default.createElement(a.Dropdown.Item,{highlightedColor:"transparent"},/*#__PURE__*/s.default.createElement(b,{onClick:()=>{P.current.closePopover()},requestForms:c,requestFormParams:u}))])},j=({children:e})=>/*#__PURE__*/s.default.createElement(a.Text,{color:"grey-6",italic:!0,align:"center",marginHorizontal:2,marginBottom:1,size:4},e),R=({fetchingUpcoming:e,fetchingPast:t,pastEvents:n,showingPastEvents:r,setShowingPastEvents:o,upcomingEvents:c})=>{const l=!c||0===c.length,i=[];return i.push(/*#__PURE__*/s.default.createElement(k,null,r?"Upcoming":"Connections")),e||t?i.push(/*#__PURE__*/s.default.createElement(a.StackView,null,/*#__PURE__*/s.default.createElement(a.Spinner,{key:"dropdown-contents-for-upcoming-past",marginHorizontal:2,marginVertical:.5,align:"center"}))):(c?.forEach(e=>{i.push(/*#__PURE__*/s.default.createElement(v,{key:`${e.id}`,event:e}))}),l&&i.push(/*#__PURE__*/s.default.createElement(j,{key:"no-upcoming-connections"},"No upcoming connections")),!r&&n?.length>0&&i.push((({setShowingPastEvents:e})=>/*#__PURE__*/s.default.createElement(a.Dropdown.Link,{key:"show-past",marginBottom:.5,paddingHorizontal:2,onClick:()=>e(!0)},/*#__PURE__*/s.default.createElement(a.Button,{theme:"primary",variant:"outline"},"Show connections in the past")))({setShowingPastEvents:o})),r&&(i.push(/*#__PURE__*/s.default.createElement(k,null,"Past")),n?.forEach(e=>{i.push(/*#__PURE__*/s.default.createElement(v,{key:`${e.id}`,event:e}))}))),i};e.ConnectedEventsDropdown=({dates:e,extra:n,productName:a,localRecordId:r,localRecordType:o,...c})=>{const l={dates:e,productName:a,localRecordId:r,localRecordType:o,extra:n},i=(e=>{const[n,a]=t.useState(!1),{productName:r,localRecordId:o,localRecordType:c}=e,l=()=>{g.any(r,o,c).then(e=>{a(e)})};return t.useEffect(()=>(l(),document.addEventListener("onConnectionChange",l),()=>{document.removeEventListener("onConnectionChange",l)}),[o]),n})(l),d=(e=>{const[n,a]=t.useState([]),{dates:r,productName:o}=e,c=r&&r.length>0&&["groups"].includes(o.toLowerCase());return t.useEffect(()=>{if(c){const t=["include=form_group_types",`where[form_group_types][group_type_id]=${e.extra.groupTypeId}`,"where[status]=open"].join("&");m.get(`/calendar/v2/forms?${t}`).then(e=>{e.ok&&a(e.json.data)})}},[]),n})(l),u=i||d.length>0,[p,f]=t.useState(!1);return u?"calendar"===a?/*#__PURE__*/s.default.createElement(w,{handleOpen:f,connectable:l,open:p,...c}):/*#__PURE__*/s.default.createElement(C,{handleOpen:f,connectable:l,dates:e,open:p,requestForms:d,...c}):null}});
//# sourceMappingURL=connected-events.umd.js.map
/// <reference types="react" />
import { RequestForm, RequestFormParams } from "./types";
declare const AddToCalendar: ({ requestForms, requestFormParams, }: {
declare const AddToCalendar: ({ onClick, requestForms, requestFormParams, }: {
onClick: () => void;
requestForms: RequestForm[];

@@ -5,0 +6,0 @@ requestFormParams: RequestFormParams;

@@ -0,4 +1,6 @@

import React from "react";
import { ReactNode } from "react";
declare const DropdownWrapper: ({ children, handleOpen, ...props }: {
declare const DropdownWrapper: ({ children, handleOpen, dropdownRef, ...props }: {
children: ReactNode;
dropdownRef?: React.MutableRefObject<any>;
handleOpen: (boolean: any) => void;

@@ -5,0 +7,0 @@ }) => JSX.Element;

{
"name": "@planningcenter/connected-events",
"version": "1.7.0",
"version": "1.7.1-rc.2",
"description": "Fetches connected event records",

@@ -41,2 +41,4 @@ "main": "./dist/connected-events.js",

"@emotion/core": "^10.1.1",
"@emotion/react": "^11.10.5",
"@planningcenter/tapestry-react": "^2.6.0",
"@testing-library/jest-dom": "^5.16.5",

@@ -43,0 +45,0 @@ "@testing-library/react": "^14.0.0",

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc