1 line
No EOL
14 KiB
JavaScript
1 line
No EOL
14 KiB
JavaScript
"use strict";(self.webpackChunk=self.webpackChunk||[]).push([[916],{66705:function(t,e,a){var o={};a.r(o),a.d(o,{deleteAutomation:function(){return Z},duplicateAutomation:function(){return M},loadAutomations:function(){return C},restoreAutomation:function(){return U},trashAutomation:function(){return O}});var i={};a.r(i),a.d(i,{getAutomationCount:function(){return L},getAutomations:function(){return I}});var n=a(70079),s=a(2226),l=a(26952),r=a(44259),u=a(8334),m=a(65317),c=a(56249),d=a(89912),p=a(96854);const h="mailpoet/automation-listing";var _=a(3279),g=a(81433),x=a(710);function f(t,e){switch(e.type){case"SET_AUTOMATIONS":return{...t,automations:e.automations};case"ADD_AUTOMATION":return{...t,automations:[e.automation,...t.automations]};case"UPDATE_AUTOMATION":return{...t,automations:t.automations.map((t=>t.id===e.automation.id?e.automation:t))};case"DELETE_AUTOMATION":return{...t,automations:t.automations.filter((t=>t.id!==e.automation.id))};default:return t}}var j=a(7936),b=a(46824),y=a(26462),v=a(19382),A=a(15312),T=a(69177),w=a(35250);function N(t){let{automation:e,label:a}=t;return(0,w.jsx)(v.ZP,{variant:"link",href:(0,A.f)(T.MailPoet.urls.automationEditor,{id:e.id}),children:a??(0,j.__)("Edit","mailpoet")})}var k=a(48405);function E(t){let{automation:e,previousStatus:a}=t;const{restoreAutomation:o}=(0,k.Z)(h);return(0,w.jsx)(v.ZP,{variant:"link",onClick:()=>o(e,a),children:(0,j.__)("Undo","mailpoet")})}const S=(t,e)=>(0,g.dispatch)(b.store).createSuccessNotice(t,e),P=t=>(0,g.dispatch)(b.store).removeNotice(t);function*C(){return{type:"SET_AUTOMATIONS",automations:(yield(0,x.apiFetch)({path:"/automations"})).data}}function*M(t){const e=yield(0,x.apiFetch)({path:`/automations/${t.id}/duplicate`,method:"POST"});return S((0,j.sprintf)((0,j.__)('Automation "%s" was duplicated.',"mailpoet"),t.name)),{type:"ADD_AUTOMATION",automation:e.data}}function*O(t){const e=yield(0,x.apiFetch)({path:`/automations/${t.id}`,method:"PUT",data:{status:y.b.TRASH}}),a=(0,j.__)("1 automation moved to the Trash.","mailpoet");return S(a,{id:`automation-trashed-${t.id}`,__unstableHTML:(0,w.jsxs)("p",{children:[a," ",(0,w.jsx)(E,{automation:t,previousStatus:t.status})]})}),{type:"UPDATE_AUTOMATION",automation:e.data}}function*U(t,e){const a=yield(0,x.apiFetch)({path:`/automations/${t.id}`,method:"PUT",data:{status:e}});P(`automation-trashed-${t.id}`);const o=(0,j.__)("1 automation restored from the Trash.","mailpoet");return S(o,{__unstableHTML:(0,w.jsxs)("p",{children:[o," ",(0,w.jsx)(N,{automation:t,label:(0,j.__)("Edit automation","mailpoet")})]})}),{type:"UPDATE_AUTOMATION",automation:a.data}}function*Z(t){return yield(0,x.apiFetch)({path:`/automations/${t.id}`,method:"DELETE"}),S((0,j.__)("1 automation and all associated data permanently deleted.","mailpoet")),{type:"DELETE_AUTOMATION",automation:t}}var D=a(34379);function I(t){return t.automations}function L(t){return t.automations?t.automations.length:D.automationCount}var H=a(50483),R=a(35100),F=a(16374),$=a(33493),B=a(52542),q=a(74457),z=a(75871);const Q=t=>{const[e,a]=(0,n.useState)(!1),{deleteAutomation:o}=(0,k.Z)(h);if(t.status===y.b.TRASH)return{key:"delete",control:{title:(0,j.__)("Delete permanently","mailpoet"),icon:null,onClick:()=>a(!0)},slot:(0,w.jsx)(z.Z,{isOpen:e,title:(0,j.__)("Permanently delete automation","mailpoet"),confirmButtonText:(0,j.__)("Yes, permanently delete","mailpoet"),__experimentalHideHeader:!1,onConfirm:()=>o(t),onCancel:()=>a(!1),children:(0,j.sprintf)((0,j.__)('Are you sure you want to permanently delete "%s" and all associated data? This cannot be undone!',"mailpoet"),t.name)})}},V=t=>{const{restoreAutomation:e}=(0,k.Z)(h);if(t.status===y.b.TRASH)return{key:"restore",control:{title:(0,j.__)("Restore","mailpoet"),icon:null,onClick:()=>e(t,y.b.DRAFT)}}},Y=t=>{const[e,a]=(0,n.useState)(!1),{trashAutomation:o}=(0,k.Z)(h);if(t.status!==y.b.TRASH)return{key:"trash",control:{title:(0,j._x)("Trash","verb","mailpoet"),icon:null,onClick:()=>a(!0)},slot:(0,w.jsx)(z.Z,{isOpen:e,title:(0,j.__)("Trash automation","mailpoet"),confirmButtonText:(0,j.__)("Yes, move to trash","mailpoet"),__experimentalHideHeader:!1,onConfirm:()=>o(t),onCancel:()=>a(!1),children:(0,j.sprintf)((0,j.__)('Are you sure you want to move the automation "%s" to the Trash?',"mailpoet"),t.name)})}};function G(t){let{automation:e,label:a}=t;return(0,w.jsx)(v.ZP,{variant:"link",href:(0,A.f)(T.MailPoet.urls.automationAnalytics,{id:e.id}),children:a??(0,j.__)("Analytics","mailpoet")})}function K(t){let{automation:e}=t;const a=[Y(e),V(e),Q(e)].filter((t=>t));return(0,w.jsxs)("div",{className:"mailpoet-automation-listing-cell-actions",children:[(0,w.jsx)(G,{automation:e}),(0,w.jsx)(N,{automation:e}),a.map((t=>{let{control:e,slot:a}=t;return(0,w.jsx)(n.Fragment,{children:a},e.title)})),(0,w.jsx)(B.Z,{className:"mailpoet-automation-listing-more-button",label:(0,j.__)("More","mailpoet"),icon:q.Z,controls:a.map((t=>{let{control:e}=t;return e})),popoverProps:{position:"bottom left"}})]})}function W(t){let{automation:e}=t;return(0,w.jsx)(N,{automation:e,label:e.name})}function J(t){let{automation:e}=t,a="";switch(e.status){case y.b.ACTIVE:a=(0,j.__)("Active","mailpoet");break;case y.b.DEACTIVATING:a=(0,j.__)("Deactivating","mailpoet");break;default:a=(0,j.__)("Draft","mailpoet")}return(0,w.jsx)("div",{className:"mailpoet-automation-listing-cell-status",children:a})}var X=a(12711);function tt(t){let{automation:e}=t;return(0,w.jsx)(X.g,{labelPosition:"after",items:[{key:"entered",label:(0,j._x)("Entered","automation stats","mailpoet"),value:e.stats.totals.entered},{key:"processing",label:(0,j._x)("Processing","automation stats","mailpoet"),value:e.stats.totals.in_progress},{key:"exited",label:(0,j._x)("Exited","automation stats","mailpoet"),value:e.stats.totals.exited}]})}var et=a(2632);const at=[{name:"all",title:(0,j.__)("All","mailpoet"),className:"mailpoet-tab-all"},{name:y.b.ACTIVE,title:(0,j.__)("Active","mailpoet"),className:"mailpoet-tab-active"},{name:y.b.DRAFT,title:(0,j._x)("Draft","noun","mailpoet"),className:"mailpoet-tab-draft"},{name:y.b.TRASH,title:(0,j._x)("Trash","noun","mailpoet"),className:"mailpoet-tab-trash"}],ot=[{key:"name",label:(0,j.__)("Name","mailpoet"),cellClassName:"mailpoet-automation-listing-cell-name"},{key:"subscribers",label:(0,j.__)("Subscribers","mailpoet")},{key:"status",label:(0,j.__)("Status","mailpoet")},{key:"actions"}];function it(){return(0,w.jsx)(et.m,{heading:(0,j.__)("Automations","mailpoet"),children:(0,w.jsx)(v.ZP,{href:T.MailPoet.urls.automationTemplates,icon:$.R,variant:"primary",className:"mailpoet-add-new-button",children:(0,j.__)("New automation","mailpoet")})})}function nt(){const t=(0,F.k6)(),e=(0,F.TH)(),a=(0,n.useMemo)((()=>new URLSearchParams(e.search)),[e]),o=(0,c.Z)((t=>t(h).getAutomations())),{loadAutomations:i}=(0,k.Z)(h),s=a.get("status");(0,n.useEffect)((()=>{i()}),[i]),(0,n.useLayoutEffect)((()=>{s&&document.querySelector(`.mailpoet-tab-${s}`)?.focus()}),[s]);const l=(0,n.useCallback)((e=>{const o=new URLSearchParams({...Object.fromEntries(a.entries()),...e}),i=Object.keys(e);(i.includes("status")||i.includes("per_page")||"1"===o.get("paged"))&&o.delete("paged"),t.push({search:o.toString()})}),[a,t]),r=(0,n.useMemo)((()=>{const t={all:[]};return(o??[]).forEach((e=>{t[e.status]||(t[e.status]=[]),t[e.status].push(e),e.status!==y.b.TRASH&&t.all.push(e)})),t}),[o]),u=(0,n.useMemo)((()=>at.map((t=>{const e=(r[t.name]??[]).length;return{name:t.name,title:(0,w.jsxs)(w.Fragment,{children:[(0,w.jsx)("span",{children:t.title}),e>0&&(0,w.jsx)("span",{className:"count",children:e})]}),className:t.className}}))),[r]),m=(0,n.useCallback)((t=>{const e=r[t.name]??[],i=parseInt(a.get("per_page")??"25",10),n=(parseInt(a.get("paged")??"1",10)-1)*i,s=e.map((t=>function(t){return[{id:t.id,value:t.name,display:(0,w.jsx)(W,{automation:t})},{id:t.id,value:null,display:(0,w.jsx)(tt,{automation:t})},{id:t.id,value:t.status,display:(0,w.jsx)(J,{automation:t})},{id:t.id,value:null,display:(0,w.jsx)(K,{automation:t})}]}(t))).slice(n,n+i);return(0,w.jsx)(H.Z,{className:"mailpoet-automation-listing",title:"",isLoading:!o,headers:ot,rows:s,rowKey:(t,a)=>e[a].id,rowsPerPage:i,onQueryChange:t=>e=>{l({[t]:e})},totalRows:e.length,query:Object.fromEntries(a),showMenu:!1})}),[o,r,a,l]);return(0,w.jsx)(R.Z,{className:"mailpoet-filter-tab-panel",tabs:u,onSelect:t=>{s!==t&&l({status:t})},initialTabName:s??"all",children:m},s)}var st=a(82974),lt=a(9003),rt=a(84209),ut=a(96328);function mt(t){let{controls:e,title:a,onClick:o,variant:i}=t;const[s,l]=(0,n.useState)(!1),r=Object.values(e).filter((t=>t.slot)),u=s?"mailpoet-option-button-opener is-busy":"mailpoet-option-button-opener";return(0,w.jsxs)("div",{className:"mailpoet-option-button",children:[(0,w.jsx)(v.ZP,{isBusy:s,disabled:s,variant:i,className:"mailpoet-option-button-main",onClick:()=>{l(!0),o(l)},children:a}),r.length>0&&r.map((t=>{let{key:e,slot:a}=t;return(0,w.jsx)(a,{},e)})),Object.values(e).length>0&&(0,w.jsx)(B.Z,{className:u,label:(0,j.__)("More","mailpoet"),icon:ut.Z,controls:Object.values(e).map((t=>({...t.control,onClick:()=>{l(!0),t.control.onClick(l)}}))),popoverProps:{position:"bottom left"}})]})}function ct(){const t=rt.Hooks.applyFilters("mailpoet.automation.hero.actions",{});return(0,w.jsx)("section",{className:"mailpoet-automation-section mailpoet-automation-white-background",children:(0,w.jsxs)("div",{className:"mailpoet-automation-section-content mailpoet-automation-section-hero",children:[(0,w.jsxs)("div",{children:[(0,w.jsx)("span",{className:"mailpoet-automation-preheading",children:(0,j.__)("Automations","mailpoet")}),(0,w.jsx)("h1",{children:(0,j.__)("Better engagement begins with automation","mailpoet")}),(0,w.jsx)("p",{children:(0,j.__)("Send emails that inform, reward, and engage your audience through powerful segmenting, scheduling, and design tools.","mailpoet")}),(0,w.jsx)(mt,{variant:"primary",onClick:()=>{window.location.href=T.MailPoet.urls.automationTemplates},title:(0,j.__)("Start with a template","mailpoet"),controls:t})]}),(0,w.jsx)("img",{src:`${T.MailPoet.cdnUrl}automation/sections/hero.png`,alt:(0,j.__)("Welcome","mailpoet")})]})})}var dt=a(38313),pt=a(518);function ht(){const t=dt.U.slice(0,3);return(0,w.jsx)("section",{className:"mailpoet-automation-section",children:(0,w.jsxs)("div",{className:"mailpoet-automation-section-content mailpoet-section-templates",children:[(0,w.jsx)("h2",{children:(0,j.__)("Explore essentials","mailpoet")}),(0,w.jsx)("p",{children:(0,j.__)("Choose from our list of pre-made templates and make it your own.","mailpoet")}),(0,w.jsx)("ul",{className:"mailpoet-section-template-list",children:(0,w.jsx)(pt.p,{templates:t})}),(0,w.jsx)(v.ZP,{variant:"link",href:T.MailPoet.urls.automationTemplates,children:(0,j.__)("Browse all templates →","mailpoet")})]})})}function _t(){const[t,e]=(0,n.useState)("start-with-a-trigger"),a=[{slug:"start-with-a-trigger",title:(0,j.__)("Start with a trigger","mailpoet"),text:(0,j.__)("Deliver relevant messages to your customers based on who they are and how they interact with your business.","mailpoet"),image:`${T.MailPoet.cdnUrl}automation/sections/start-with-a-trigger.png`},{slug:"customize-your-automation",title:(0,j.__)("Customize your automation","mailpoet"),text:(0,j.__)("Choose steps and create a custom journey to best suit your needs.","mailpoet"),image:`${T.MailPoet.cdnUrl}automation/sections/customize-your-automation.png`},{slug:"design-your-email",title:(0,j.__)("Design your email","mailpoet"),text:(0,j.__)("Modify one of our pre-made email templates or create your own design.","mailpoet"),image:`${T.MailPoet.cdnUrl}automation/sections/design-your-email.png`},{slug:"start-engaging",title:(0,j.__)("Start engaging","mailpoet"),text:(0,j.__)("Activate the automation and start engaging with your customers as they interact with your business.","mailpoet"),image:`${T.MailPoet.cdnUrl}automation/sections/start-engaging.png`}],o=a.filter((e=>e.slug===t))[0];return(0,w.jsx)("section",{className:"mailpoet-automation-section mailpoet-automation-white-background",children:(0,w.jsxs)("div",{className:"mailpoet-automation-section-content mailpoet-section-build-your-own",children:[(0,w.jsxs)("div",{children:[(0,w.jsx)("h2",{children:(0,j.__)("Build your own automations","mailpoet")}),(0,w.jsx)("p",{children:(0,j.__)("Create customized email sequences with our new automation editor.","mailpoet")}),(0,w.jsx)("ol",{children:a.map(((a,o)=>(0,w.jsxs)("li",{className:t===a.slug?"open":"",children:[(0,w.jsx)("div",{className:"marker",children:o<10?`0${o+1}`:o+1}),(0,w.jsxs)("div",{children:[(0,w.jsx)("button",{type:"button",onClick:()=>e(a.slug),className:"mailpoet-section-build-list-button",children:a.title}),(0,w.jsx)("p",{children:a.text})]})]},a.slug)))})]}),(0,w.jsx)("img",{src:o.image,alt:o.title})]})})}const gt=()=>{T.MailPoet.trackEvent("Automations > Listing viewed")};function xt(){const[t,e]=(0,n.useState)(!0),a=(0,c.Z)((t=>t(h).getAutomationCount()));(0,n.useEffect)((()=>{t&&0!==a&&(gt(),e(!1))}),[t,a]);const o=a>0?(0,w.jsxs)(w.Fragment,{children:[(0,w.jsx)(it,{}),(0,w.jsx)(nt,{})]}):(0,w.jsx)(ct,{});return(0,n.useEffect)((()=>{const t="mailpoet-automation-is-onboarding",e=document.querySelector("body");0!==a||e.classList.contains(t)||e.classList.add(t),a>0&&e.classList.contains(t)&&e.classList.remove(t)}),[a]),(0,w.jsxs)(w.Fragment,{children:[o,(0,w.jsx)(ht,{}),(0,w.jsx)(_t,{})]})}function ft(){return(0,w.jsxs)(w.Fragment,{children:[(0,w.jsx)(r.Q,{}),(0,w.jsx)(lt.w,{}),(0,w.jsx)(xt,{})]})}function jt(){return(0,w.jsx)(u.zt,{children:(0,w.jsxs)(l.BrowserRouter,{children:[(0,w.jsx)(ft,{}),(0,w.jsx)(m.Z.Slot,{})]})})}window.addEventListener("DOMContentLoaded",(()=>{(()=>{const t=(0,_.Z)(h,{actions:o,controls:x.controls,selectors:i,reducer:f,initialState:{automations:void 0}});(0,g.register)(t)})();const t=document.getElementById("mailpoet_automation");t&&((0,d.registerTranslations)(),(0,st.y)(),(0,p.q)(),(0,s.s)(t).render((0,w.jsx)(jt,{})))}))},65311:function(t){t.exports=jQuery}},function(t){t.O(0,[351],(function(){return 66705,t(t.s=66705)})),t.O()}]); |