text: (this["webpackJsonpsfa-react"]=this["webpackJsonpsfa-react"]||[]).push([[0],{40:function(e,t,a){e.exports=a(69)},68:function(e,t,a){},69:function(e,t,a){"use strict";a.r(t);var n=a(0),r=a.n(n),l=a(13),s=a.n(l),i=a(6),c=a.n(i),u=function(){return r.a.createElement("nav",null,r.a.createElement("h1",null,"Stinging Fly Subscriber Admin"))},o=a(8),d=a(5),m=a(10),p=a(32),b=a(27),E=(a(49),a(50),function(e){var t=e.activeSubs[e.activeSubs.length-1];return r.a.createElement("section",{id:"admin_panel_header"},r.a.createElement("span",null,"There are ",e.activeSubs.length," current subscribers. "),r.a.createElement("span",null,"The latest subscriber is ",t.first_name," ",t.last_name,"."," "),r.a.createElement("span",null,"There are ",e.expiringSubs.length," subscriptions expiring in the next 30 days."))}),f=a(11);function _(e){var t=e.preGlobalFilteredRows,a=e.globalFilter,n=e.setGlobalFilter,l=t.length;return r.a.createElement("span",null,"Search:"," ",r.a.createElement("input",{value:a||"",onChange:function(e){n(e.target.value||void 0)},placeholder:"".concat(l," records..."),style:{fontSize:"14px",border:"0"}}))}var h=function(e){var t=e.columns,a=e.data,n=Object(f.e)({columns:t,data:a,initialState:{sortBy:[{id:"date_start",desc:!0}],pageSize:10}},f.a,f.b,f.d,f.c),l=n.getTableProps,s=n.getTableBodyProps,i=n.headerGroups,c=n.prepareRow,u=n.state,o=n.flatColumns,d=n.preGlobalFilteredRows,m=n.setGlobalFilter,p=n.page,b=n.canPreviousPage,E=n.canNextPage,h=n.pageOptions,g=n.pageCount,y=n.gotoPage,v=n.nextPage,S=n.previousPage,w=n.setPageSize,N=n.state,F=N.pageIndex,O=N.pageSize;return r.a.createElement(r.a.Fragment,null,r.a.createElement("table",l(),r.a.createElement("thead",null,r.a.createElement("tr",null,r.a.createElement("th",{colSpan:o.length,style:{textAlign:"left"}},r.a.createElement(_,{preGlobalFilteredRows:d,globalFilter:u.globalFilter,setGlobalFilter:m}))),i.map((function(e){return r.a.createElement("tr",e.getHeaderGroupProps(),e.headers.map((function(e){return r.a.createElement("th",e.getHeaderProps(e.getSortByToggleProps()),e.render("Header"),r.a.createElement("span",null,e.isSorted?e.isSortedDesc?" \u25bc":" \u25b2":""),"includes"===e.filter?e.render("Filter"):null)})))}))),r.a.createElement("tbody",s(),p.map((function(e,t){return c(e),r.a.createElement("tr",e.getRowProps(),e.cells.map((function(e){return r.a.createElement("td",e.getCellProps(),e.render("Cell"))})))})))),r.a.createElement("div",{className:"pagination"},r.a.createElement("button",{onClick:function(){return y(0)},disabled:!b},"<<")," ",r.a.createElement("button",{onClick:function(){return S()},disabled:!b},"<")," ",r.a.createElement("button",{onClick:function(){return v()},disabled:!E},">")," ",r.a.createElement("button",{onClick:function(){return y(g-1)},disabled:!E},">>")," ",r.a.createElement("span",null,"Page"," ",r.a.createElement("strong",null,F+1," of ",h.length)," "),r.a.createElement("span",null,"| Go to page:"," ",r.a.createElement("input",{type:"number",defaultValue:F+1,onChange:function(e){var t=e.target.value?Number(e.target.value)-1:0;y(t)},style:{width:"100px"}}))," ",r.a.createElement("select",{value:O,onChange:function(e){w(Number(e.target.value))}},[10,20,30,40,50].map((function(e){return r.a.createElement("option",{key:e,value:e},"Show ",e)})))))},g=a(28),y=a(29),v=a(34),S=a(30),w=a(35),N=function(){return"true"===Object({NODE_ENV:"production",PUBLIC_URL:"/wp-content/themes/stingingfly/template-parts/subs/build"}).LIVE_TEST||"stingingfly.org"===window.location.hostname?"https://enigmatic-basin-09064.herokuapp.com/api/subscribers":"http://localhost:8001/api/subscribers"},F=function(e){var t=function(t){return e.querySelector(t).value||null},a={first_name:t("#first_name"),last_name:t("#last_name"),email:t("#email"),address_line1:t("#address_line1"),address_line2:t("#address_line2"),address_city:t("#address_city"),address_country:t("#address_country"),address_postcode:t("#address_postcode"),issue:t("#start_issue"),final_issue:t("#final_issue"),delivery:t('input[name="delivery"]:checked')};return JSON.stringify(a)},O=function(e){function t(){var e,a;Object(g.a)(this,t);for(var n=arguments.length,r=new Array(n),l=0;l<n;l++)r[l]=arguments[l];return(a=Object(v.a)(this,(e=Object(S.a)(t)).call.apply(e,[this].concat(r)))).handleSubmit=function(e){e.preventDefault();var t=document.getElementById("add-sub-form");fetch(N(),{method:"POST",body:F(t),headers:{Accept:"application/json","Content-Type":"application/json"}}).then((function(e){return e.json()})).then((function(e){switch(e.message){case"subscriber_added":setTimeout((function(){t.reset(),alert("Subscriber Added")}),250);break;case"subscriber_updated":setTimeout((function(){t.reset(),alert("Subscriber Updated")}),250);break;case"customer_exists":setTimeout((function(){alert("Subscriber already exists")}),250);break;default:console.log(e),setTimeout((function(){alert("Failed to Add Subscriber \u2013 Try Again?")}),250)}}))},a}return Object(w.a)(t,e),Object(y.a)(t,[{key:"render",value:function(){return r.a.createElement("form",{id:"add-sub-form",onSubmit:this.handleSubmit},r.a.createElement("fieldset",{id:"sub_contact"},r.a.createElement("legend",null,"Name + Email"),r.a.createElement("div",{className:"fieldset-inputs"},r.a.createElement("label",{htmlFor:"first_name",className:"half-width"},r.a.createElement("span",{className:"label-title"},"First Name"),r.a.createElement("input",{id:"first_name",type:"text",required:!0,placeholder:" ",pattern:".*\\S.*",name:"first_name"}),r.a.createElement("span",{className:"validation"},"This field is required.")),r.a.createElement("label",{htmlFor:"last_name",className:"half-width"},r.a.createElement("span",{className:"label-title"},"Last Name"),r.a.createElement("input",{id:"last_name",type:"text",required:!0,placeholder:" ",pattern:".*\\S.*",name:"last_name"}),r.a.createElement("span",{className:"validation"},"This field is required.")),r.a.createElement("label",{htmlFor:"email",className:"full-width"},r.a.createElement("span",{className:"label-title"},"Email"),r.a.createElement("input",{id:"email",type:"email",required:!0,placeholder:" ",pattern:".*\\S.*",name:"email"}),r.a.createElement("span",{className:"validation"},"This field is invalid.")))),r.a.createElement("fieldset",null,r.a.createElement("legend",null,"Address"),r.a.createElement("div",{className:"fieldset-inputs"},r.a.createElement("label",{htmlFor:"address_line1",className:"full-width"},"Address Line 1",r.a.createElement("input",{id:"address_line1",name:"address_line1",type:"text",required:!0,placeholder:"\xa0",pattern:".*\\S.*"}),r.a.createElement("span",{className:"validation"},"This field is required.")),r.a.createElement("label",{htmlFor:"address_line2",className:"full-width"},"Address Line 2",r.a.createElement("input",{id:"address_line2",name:"address_line2",type:"text",required:!0,placeholder:"\xa0",pattern:".*\\S.*"}),r.a.createElement("span",{className:"validation"},"This field is required.")),r.a.createElement("label",{htmlFor:"address_city",className:"third-width"},"City",r.a.createElement("input",{id:"address_city",name:"address_city",type:"text"})),r.a.createElement("label",{htmlFor:"address_country",className:"third-width"},"Country",r.a.createElement("input",{id:"address_country",name:"address_country",type:"text"})),r.a.createElement("label",{htmlFor:"address_postcode",className:"third-width"},"Postcode",r.a.createElement("input",{id:"address_postcode",name:"address_postcode",type:"text"}))),r.a.createElement("h3",null,"Select your delivery region"),r.a.createElement("input",{type:"radio",name:"delivery",id:"irl",value:"irl",defaultChecked:!0}),r.a.createElement("label",{htmlFor:"irl"},"Ireland and Northern Ireland"),r.a.createElement("input",{type:"radio",name:"delivery",id:"row",value:"row"}),r.a.createElement("label",{htmlFor:"row"},"Rest of the World")),r.a.createElement("fieldset",{id:"sub_start"},r.a.createElement("legend",null,"Issue"),r.a.createElement("input",{type:"number",id:"start_issue",name:"start_issue",min:"41"}),r.a.createElement("label",{htmlFor:"start_issue"},"Starting Issue"),r.a.createElement("input",{type:"number",id:"final_issue",name:"final_issue",min:"42"}),r.a.createElement("label",{htmlFor:"final_issue"},"Final Issue (Optional \u2013 Defaults to One Year)"),r.a.createElement("div",{className:"fieldset-comment"})),r.a.createElement("input",{type:"submit",value:"Submit"}))}}]),t}(r.a.Component),j=a(16),C=a(74),I=function(e){var t=r.a.useState({sub_id:e.sub[0].sub_id,first_name:e.sub[0].first_name,last_name:e.sub[0].last_name,email:e.sub[0].email,address_one:e.sub[0].address_one,address_two:e.sub[0].address_two,city:e.sub[0].city,country:e.sub[0].country,postcode:e.sub[0].postcode,subscribe_until:e.sub[0].subscribe_until,start_issue:e.sub[0].start_issue}),a=Object(d.a)(t,2),n=a[0],l=a[1],s=function(e){var t=Object(j.a)({},n);t[e.target.name]=e.target.value,l(t)};return r.a.createElement("div",{className:"edit-modal"},r.a.createElement("form",{id:"edit-form"},r.a.createElement("label",{htmlFor:"first_name"},"First Name"),r.a.createElement("input",{name:"first_name",id:"first_name",defaultValue:n.first_name,pattern:".*\\S.*",onInput:s}),r.a.createElement("label",{htmlFor:"last_name"},"Last Name"),r.a.createElement("input",{name:"last_name",id:"last_name",defaultValue:n.last_name,pattern:".*\\S.*",onInput:s}),r.a.createElement("label",{htmlFor:"email"},"Email"),r.a.createElement("input",{name:"email",id:"email",defaultValue:n.email,pattern:".*\\S.*",onInput:s}),r.a.createElement("label",{htmlFor:"address_one"},"Address Line 1"),r.a.createElement("input",{name:"address_one",id:"address_one",defaultValue:n.address_one,pattern:".*\\S.*",onInput:s}),r.a.createElement("label",{htmlFor:"address_two"},"Address Line 2"),r.a.createElement("input",{name:"address_two",id:"address_two",defaultValue:n.address_two,pattern:".*\\S.*",onInput:s}),r.a.createElement("label",{htmlFor:"city"},"City"),r.a.createElement("input",{name:"city",id:"city",defaultValue:n.city,pattern:".*\\S.*",onInput:s}),r.a.createElement("label",{htmlFor:"country"},"Country"),r.a.createElement("input",{name:"country",id:"country",defaultValue:n.country,pattern:".*\\S.*",onInput:s}),r.a.createElement("label",{htmlFor:"postcode"},"Postcode"),r.a.createElement("input",{name:"postcode",id:"postcode",defaultValue:n.postcode,pattern:".*\\S.*",onInput:s}),r.a.createElement("label",{htmlFor:"start_issue"},"Starting Issue"),r.a.createElement("input",{type:"number",name:"start_issue",id:"start_issue",defaultValue:n.start_issue,onInput:s}),r.a.createElement("label",{htmlFor:"final_issue"},"Final Issue"),r.a.createElement("input",{type:"number",name:"subscribe_until",id:"final_issue",defaultValue:n.subscribe_until,onInput:s})),r.a.createElement("button",{id:"save-edits",onClick:function(){console.log(n),e.updateSub(n),fetch(N(),{method:"PUT",body:JSON.stringify(n),headers:{Accept:"application/json","Content-Type":"application/json"}}).then((function(e){return e.text()})).then((function(t){console.log(t),e.openState({open:"sub"})}))}},"Save Edits"))},x=function(e){var t=e.sub[0],a=t.sub_id,n=t.first_name,l=t.last_name,s=t.email,i=t.address_one,c=t.address_two,u=t.city,o=t.country,d=t.postcode,m=t.date_start,p=t.next_renewal_date,b=t.gift,E=t.gifter_email,f=t.gifter_first_name,_=t.gifter_last_name,h=t.stripe_subscription_id,g=t.subscribe_until,y=t.start_issue,v=t.wp_user_id,S=function(e){return e?", "+e.trim():" "};return r.a.createElement("div",{className:"sub_in_modal"},r.a.createElement("h2",{className:"modal__name"},n," ",l," ",b?r.a.createElement("span",null,"(Gift)"):""),r.a.createElement("p",{className:"modal__email"},s),r.a.createElement("p",{className:"modal__address"},r.a.createElement("strong",null,"Address:")," ",r.a.createElement("span",null,i.trim()),r.a.createElement("span",null,S(c)),r.a.createElement("span",null,S(u),S(d)),r.a.createElement("span",null,S(o))),r.a.createElement("hr",null),r.a.createElement("p",null,r.a.createElement("strong",null,"Subscribed:")," ",Object(C.a)(new Date(m),"dd/MM/yyyy")),r.a.createElement("p",null,r.a.createElement("strong",null,"Renews: "),b?"No Renewal":Object(C.a)(new Date(p),"dd/MM/yyyy")),r.a.createElement("p",null,r.a.createElement("strong",null,"Started With: "),parseInt(y)),r.a.createElement("p",null,r.a.createElement("strong",null,"Last Issue: "),parseInt(g)),r.a.createElement("hr",null),r.a.createElement("p",null,r.a.createElement("a",{target:"_blank",rel:"noopener noreferrer",href:"https://dashboard.stripe.com/subscriptions/".concat(h)},"View on Stripe")),r.a.createElement("p",null,r.a.createElement("a",{target:"_blank",rel:"noopener noreferrer",href:"https://stingingfly.org/wp-admin/user-edit.php?user_id=".concat(v)},"View on stingingfly.org"),b?r.a.createElement("section",{className:"gift"},r.a.createElement("hr",null),r.a.createElement("p",null,r.a.createElement("strong",null,"Gifted By: "),f," ",_," (",E,")")):""),r.a.createElement("hr",null),r.a.createElement("button",{onClick:function(){return e.openState({open:"edit"})}},"Edit Subscription Details"),r.a.createElement("button",{onClick:function(){return function(e){var t=N();fetch("".concat(t,"?sub_id=").concat(e),{method:"delete"}).then((function(e){return e.json()})).then((function(e){return console.log(e),1===e.affectedRows&&alert("Subscription Cancelled"),e}))}(a)}},"Cancel Subscription"))},k=function(e){var t=r.a.useState(e),a=Object(d.a)(t,2),n=a[0],l=a[1],s=r.a.useState({open:"sub"}),i=Object(d.a)(s,2),c=i[0],u=i[1];return"sub"===c.open?r.a.createElement(x,Object.assign({openState:function(e){return u(e)}},n)):"edit"===c.open?r.a.createElement(I,Object.assign({openState:function(e){return u(e)},updateSub:function(e){return function(e){var t=Object(j.a)({},n),a=t.sub[0];Object(o.a)(Object.keys(e)).forEach((function(t){a[t]&&(a[t]=e[t])})),l(t)}(e)}},n)):void 0},P=a(75),T=a(71),A=a(72),V=a(73),G=function(e){var t=r.a.useState({}),a=Object(d.a)(t,2),n=a[0],l=a[1],s=r.a.useState(!1),i=Object(d.a)(s,2),c=i[0],u=i[1],f=function(){return u(!1)},_=r.a.useCallback((function(t){t.preventDefault();var a=parseInt(t.target.dataset.sub_id),n=e.data.filter((function(e){return e.sub_id===a}));l(n),u(!0)}),[e.data]);function g(e){var t=e.column,a=t.filterValue,n=t.setFilter,l=t.preFilteredRows,s=t.id,i=r.a.useMemo((function(){var e=new Set;return l.forEach((function(t){e.add(t.values[s])})),Object(o.a)(e.values()).sort()}),[s,l]);return r.a.createElement("select",{value:a,onChange:function(e){n(e.target.value||void 0)},onClick:function(e){return e.stopPropagation()}},r.a.createElement("option",{value:""},"All"),i.map((function(e,t){return r.a.createElement("option",{key:t,value:e},e)})))}var y=r.a.useMemo((function(){return[{Header:"First Name",accessor:"first_name"},{Header:"Last Name",accessor:"last_name"},{Header:"Email",accessor:"email"},{Header:"Subscribed",accessor:"date_start",Cell:function(e){var t=e.cell.value;return Object(C.a)(new Date(t),"dd/MM/yyyy")}},{Header:"Final Issue",accessor:"subscribe_until",Filter:g,filter:"includes",Cell:function(e){var t=e.cell.value;return parseInt(t)}},{Header:"Gift",accessor:"gift",Cell:function(e){return e.cell.value?"Gift":""}},{id:"Expand",accessor:"sub_id",Cell:function(e){var t=e.cell.value;return r.a.createElement("button",{onClick:_,"data-sub_id":t},"More")}}]}),[_]),v=e.data,S=new Date,w=Object(P.a)(S,{months:1}),N=v.filter((function(e){return Object(T.a)(Object(A.a)(e.next_renewal_date),w)&&Object(V.a)(Object(A.a)(e.next_renewal_date),S)})),F=v.filter((function(e){return"active"===e.sub_status}));function j(e){var t=e.isSelected,a=e.children;return r.a.createElement(m.a,Object.assign({},e,{style:{textDecoration:t?"underline":"none"}}),a)}return r.a.createElement("div",{id:"admin_panel"},r.a.createElement(p.a,{"aria-label":"sub-dialog",isOpen:c,onDismiss:f},r.a.createElement("button",{className:"close-button",onClick:f},r.a.createElement(b.a,null,"Close"),r.a.createElement("span",{"aria-hidden":!0},"\xd7")),r.a.createElement(k,{sub:n})),r.a.createElement(E,{activeSubs:F,expiringSubs:N}),r.a.createElement(m.e,null,r.a.createElement(m.b,null,r.a.createElement(j,null,"List Subscribers"),r.a.createElement(j,null,"Add New Subscriber"),r.a.createElement(j,null,"List Patrons"),r.a.createElement(j,null,"Add New Patron")),r.a.createElement(m.d,null,r.a.createElement(m.c,null,r.a.createElement(h,{columns:y,data:F})),r.a.createElement(m.c,null,r.a.createElement(O,null)))))},L=a(33),D=a(31),R=a.n(D),q=(a(68),function(e){var t;return c.a.async((function(a){for(;;)switch(a.prev=a.next){case 0:return a.prev=0,a.next=3,c.a.awrap(R.a.get(e));case 3:return t=a.sent,a.abrupt("return",t.data);case 7:a.prev=7,a.t0=a.catch(0),console.error(a.t0);case 10:case"end":return a.stop()}}),null,null,[[0,7]])});var H=function(){var e=Object(L.a)(N(),q,{refreshInterval:12e4}),t=e.data;return e.error?r.a.createElement("div",null,"failed to load"):t?r.a.createElement("div",{className:"App"},r.a.createElement("header",null,r.a.createElement(u,null)),r.a.createElement(G,{data:t})):r.a.createElement("div",null,"loading...")};s.a.render(r.a.createElement(H,null),document.getElementById("root"))}},[[40,1,2]]]);
  //# sourceMappingURL=main.419bb8a4.chunk.js.map