← Back
Editing: settings-email-listing.js
"use strict";(globalThis.webpackChunk_wcAdmin_webpackJsonp=globalThis.webpackChunk_wcAdmin_webpackJsonp||[]).push([[7392],{92141:(e,i,t)=>{t.r(i),t.d(i,{ListView:()=>k});var o=t(86087),a=t(47143),l=t(46118),n=t(96900),s=t(56427),c=t(15703),r=t(27723),m=t(25192),d=t(75644),p=t(22701),_=t(38493),u=t(13739),w=t(29984),b=t(39793);const g=[{value:"enabled",label:(0,r.__)("Active","woocommerce"),icon:_.A,description:(0,r.__)("Email would be sent if trigger is met","woocommerce")},{value:"disabled",label:(0,r.__)("Inactive","woocommerce"),icon:u.A,description:(0,r.__)("Email would not be sent","woocommerce")},{value:"manual",label:(0,r.__)("Manually sent","woocommerce"),icon:w.A,description:(0,r.__)("Email can only be sent manually from the order screen","woocommerce")}],h=({slug:e})=>{const i=e?g.find(i=>i.value===e):void 0;return i?(0,b.jsxs)(s.__experimentalHStack,{alignment:"left",spacing:0,className:"woocommerce-email-listing-status",children:[(0,b.jsx)(s.Icon,{icon:i.icon,size:24}),(0,b.jsx)("span",{className:"woocommerce-email-listing-status-label",children:i.label})]}):e},v=({recipients:e})=>{const{to:i,cc:t,bcc:o}={to:e.to?e.to.split(",").filter(Boolean):[],cc:e.cc?e.cc.split(",").filter(Boolean):[],bcc:e.bcc?e.bcc.split(",").filter(Boolean):[]},a=[...t,...o].length;return(0,b.jsxs)("div",{className:"woocommerce-email-listing-recipients",children:[(0,b.jsx)("div",{className:"woocommerce-email-listing-recipients-to",children:i.join(", ")}),a>0&&(0,b.jsx)(s.Tooltip,{className:"woocommerce-email-listing-recipients-tooltip",text:(0,b.jsxs)(b.Fragment,{children:[(0,b.jsxs)("div",{children:[(0,r.__)("To:","woocommerce")," ",i.join(", ")]}),t.length>0&&(0,b.jsxs)("div",{children:[(0,r.__)("CC:","woocommerce")," ",t.join(", ")]}),o.length>0&&(0,b.jsxs)("div",{children:[(0,r.__)("BCC:","woocommerce")," ",o.join(", ")]})]}),children:(0,b.jsxs)(s.Button,{variant:"link",children:[(0,r.__)("+%d more","woocommerce").replace("%d",a.toString())," "]})})]})},f="wc_email_review_drawer",j=({post:e})=>(0,p.G)(e)?(0,b.jsx)(s.Button,{variant:"secondary",onClick:()=>{e.post_id&&(window.location.href=(0,c.getAdminLink)(function(e){if(!Number.isInteger(e)||e<=0)throw new Error(`buildEmailEditorReviewUrl: postId must be a positive integer (got ${String(e)}).`);return`post.php?${new URLSearchParams({post:String(e),action:"edit",[f]:"1"}).toString()}`}(parseInt(e.post_id,10))))},children:(0,r.__)("Review update","woocommerce")}):(0,b.jsx)("span",{"aria-label":(0,r.__)("Up to date","woocommerce"),children:"—"});var x=t(91710);const y=({email:e,onClose:i})=>{const t=parseInt(e.post_id,10),o="publish"===e.postStatus&&Number.isFinite(t)?t:null,{email:a,setEmail:l,isSending:n,notice:s,noticeType:c,sendEmail:r}=(0,x.yx)({endpoint:"editor",postId:o,emailType:e.email_class_name,emailTypeId:e.id},"email_listing");return(0,b.jsx)(x.$E,{email:a,onEmailChange:l,isSending:n,notice:s,noticeType:c,onSend:r,onCancel:i})},k=({emailTypes:e})=>{const[i,t]=(0,o.useState)({type:"table",search:"",fields:["recipients","status","updates"],filters:[],page:1,perPage:20,titleField:"title",showTitle:!0,layout:{}}),{emails:_,total:u,updateEmailEnabledStatus:w,recreateEmailPost:f}=(0,d.S)(e,i),x=(0,o.useMemo)(()=>{const i=Array.from(e.reduce((e,i)=>([...i.recipients.to?i.recipients.to.split(",").map(e=>e.trim()).filter(Boolean):[],...i.recipients.cc?i.recipients.cc.split(",").map(e=>e.trim()).filter(Boolean):[],...i.recipients.bcc?i.recipients.bcc.split(",").map(e=>e.trim()).filter(Boolean):[]].forEach(i=>e.add(i)),e),new Set)).map(e=>({value:e,label:e}));return[{id:"title",label:(0,r.__)("Title","woocommerce"),enableHiding:!1,render:e=>(0,b.jsxs)("div",{className:"woocommerce-email-listing-title",children:[e.item.title,(0,b.jsx)("br",{}),(0,b.jsx)("span",{className:"woocommerce-email-listing-description",children:e.item.description})]})},{id:"recipients",label:(0,r.__)("Recipient(s)","woocommerce"),enableHiding:!0,filterBy:{operators:["isAny"]},elements:i,render:e=>(0,b.jsx)(v,{recipients:e.item.recipients})},{id:"status",label:(0,r.__)("Status","woocommerce"),enableHiding:!0,filterBy:{operators:["isAny"]},render:e=>(0,b.jsx)(h,{slug:e.item.status}),elements:g},{id:"updates",label:(0,r.__)("Updates","woocommerce"),enableHiding:!0,enableSorting:!1,getValue:({item:e})=>(0,p.G)(e)?"available":"none",elements:[{value:"available",label:(0,r.__)("Update available","woocommerce")},{value:"none",label:(0,r.__)("Up to date","woocommerce")}],filterBy:{operators:["is"],isPrimary:!0},render:({item:e})=>(0,b.jsx)(j,{post:e})}]},[e]),k=(0,o.useMemo)(()=>[{id:"edit",label:(0,r.__)("Edit","woocommerce"),icon:(0,b.jsx)(s.Icon,{icon:l.A}),supportsBulk:!1,callback:async e=>{const i=e[0];if(i.post_id)return void(window.location.href=(0,c.getAdminLink)(`post.php?post=${encodeURIComponent(i.post_id)}&action=edit`));if(!i.block_editor_supported)return void(window.location.href=(0,c.getAdminLink)(`admin.php?page=wc-settings&tab=email§ion=${encodeURIComponent(i.email_key)}`));const t=await f(i.id);t?.post_id?window.location.href=(0,c.getAdminLink)(`post.php?post=${encodeURIComponent(t.post_id)}&action=edit`):(0,a.dispatch)("core/notices").createErrorNotice((0,r.__)("Could not prepare the email for editing. Please try again.","woocommerce"))}},{id:"preview",label:(0,r.__)("Preview","woocommerce"),icon:(0,b.jsx)(s.Icon,{icon:n.A}),supportsBulk:!1,callback:e=>{const i=e[0],t=i.post_id&&"publish"===i.postStatus?i.link:i.file_template_preview_url;t&&window.open(t)},isEligible:e=>!!e.post_id&&"publish"===e.postStatus&&!!e.link||!!e.file_template_preview_url,isPrimary:!0},{id:"test",label:(0,r.__)("Send test email","woocommerce"),supportsBulk:!1,modalHeader:(0,r.__)("Send a test email","woocommerce"),RenderModal:({items:e,closeModal:i})=>(0,b.jsx)(y,{email:e[0],onClose:i??(()=>{})})},{id:"change-status",label:e=>"enabled"===e[0].status?(0,r.__)("Deactivate email","woocommerce"):(0,r.__)("Activate email","woocommerce"),supportsBulk:!1,isEligible:e=>"enabled"===e.status||"disabled"===e.status,callback:e=>{w(e[0].id,!e[0].enabled)}}],[w,f]);return(0,b.jsx)(m.Vw,{view:i,form:{type:"panel",fields:["title"]},actions:k,onChangeView:t,fields:x,data:_??[],paginationInfo:{totalItems:u,totalPages:Math.ceil(u/i.perPage)},defaultLayouts:{table:{showMedia:!1}},showLayoutSwitcher:!1,getItemId:e=>`${e.id}_${e?.email_key||""}`})}}}]);
Save File
Cancel