Files
server/opt/psa/admin/cp/public/javascript/components/pages/SendMassMailPage.js
2026-01-07 20:52:11 +01:00

11 lines
14 KiB
JavaScript

(globalThis.webpackChunkPlesk=globalThis.webpackChunkPlesk||[]).push([["components/pages/SendMassMailPage"],{2600:(e,n,i)=>{"use strict";i.r(n),i.d(n,{evictMassEmailCache:()=>s});const s=e=>{e.evict({id:e.identify({__typename:"Query"}),fieldName:"massEmail"})}},2601:e=>{var n={kind:"Document",definitions:[{kind:"OperationDefinition",operation:"mutation",name:{kind:"Name",value:"AddMassEmailTemplate"},variableDefinitions:[{kind:"VariableDefinition",variable:{kind:"Variable",name:{kind:"Name",value:"input"}},type:{kind:"NonNullType",type:{kind:"NamedType",name:{kind:"Name",value:"AddMassEmailTemplateInput"}}},directives:[]}],directives:[],selectionSet:{kind:"SelectionSet",selections:[{kind:"Field",name:{kind:"Name",value:"addMassEmailTemplate"},arguments:[{kind:"Argument",name:{kind:"Name",value:"input"},value:{kind:"Variable",name:{kind:"Name",value:"input"}}}],directives:[],selectionSet:{kind:"SelectionSet",selections:[{kind:"Field",name:{kind:"Name",value:"errors"},arguments:[],directives:[]}]}}]}}],loc:{start:0,end:133}};n.loc.source={body:"mutation AddMassEmailTemplate($input: AddMassEmailTemplateInput!) {\n addMassEmailTemplate(input: $input) {\n errors\n }\n}\n",name:"GraphQL request",locationOffset:{line:1,column:1}};function i(e,n){if("FragmentSpread"===e.kind)n.add(e.name.value);else if("VariableDefinition"===e.kind){var s=e.type;"NamedType"===s.kind&&n.add(s.name.value)}e.selectionSet&&e.selectionSet.selections.forEach(function(e){i(e,n)}),e.variableDefinitions&&e.variableDefinitions.forEach(function(e){i(e,n)}),e.definitions&&e.definitions.forEach(function(e){i(e,n)})}var s={};function a(e,n){for(var i=0;i<e.definitions.length;i++){var s=e.definitions[i];if(s.name&&s.name.value==n)return s}}n.definitions.forEach(function(e){if(e.name){var n=new Set;i(e,n),s[e.name.value]=n}}),e.exports=n,e.exports.AddMassEmailTemplate=function(e,n){var i={kind:e.kind,definitions:[a(e,n)]};e.hasOwnProperty("loc")&&(i.loc=e.loc);var t=s[n]||new Set,l=new Set,d=new Set;for(t.forEach(function(e){d.add(e)});d.size>0;){var o=d;d=new Set,o.forEach(function(e){l.has(e)||(l.add(e),(s[e]||new Set).forEach(function(e){d.add(e)}))})}return l.forEach(function(n){var s=a(e,n);s&&i.definitions.push(s)}),i}(n,"AddMassEmailTemplate")},2602:(e,n,i)=>{"use strict";i.r(n),i.d(n,{default:()=>s.default});var s=i(2603)},2603:(e,n,i)=>{"use strict";i.r(n),i.d(n,{default:()=>v});var s=i(297),a=i(1305),t=i(90),l=i(668),d=i.n(l),o=i(296),r=i(683),m=i.n(r),c=i(718),u=i(2604);const p=t.Locale.getSection("components.forms.MassMailForm"),f=({customers:e,resellers:n,loading:i,mutation:t,onSuccess:l,values:d,onChange:r,children:f=null,footer:v=null,errors:k={},submitButtonProps:T={},hideNameField:g=!1,onSubmit:b=e=>e,applyButton:h=!1})=>{const S=(0,o.useMemo)(()=>n.map(({id:e,name:n,email:i})=>{const s=atob(e).split(":")[1];return{id:s,title:`${n} (${i})`,selected:d.resellers?.includes(s)}}),[n,d.resellers]),N=(0,o.useMemo)(()=>e.map(({id:e,name:n,email:i})=>{const s=atob(e).split(":")[1];return{id:s,title:`${n} (${i})`,selected:d.clients?.includes(s)}}),[e,d.clients]);return(0,o.jsxs)(a.default,{state:i?"submit":null,values:d,onFieldChange:r,mutation:t,onSuccess:l,onSubmit:e=>b({...e,sendToResellersMode:e.sendToResellers?e.sendToResellersMode:"all",sendToClientsMode:e.sendToClients?e.sendToClientsMode:"all",resellers:(e.resellers??[]).map(Number),clients:(e.clients??[]).map(Number)}),errors:k,submitButton:{"data-testid":"btn-submit",...T},applyButton:h,cancelButton:{"data-testid":"btn-cancel",component:c.default,to:"/cp/server/mass-mail"},children:[f,!g&&(0,o.jsx)(s.FormFieldText,{required:!0,size:"xl",label:p.lmsg("name"),name:"name"}),(0,o.jsx)(s.FormFieldText,{required:!0,size:"xl",label:p.lmsg("fromEmail"),name:"fromEmail"}),(0,o.jsx)(s.FormFieldCheckbox,{label:p.lmsg("sendToAdmins"),name:"sendToAdmins"}),(0,o.jsx)(s.FormFieldCheckbox,{label:p.lmsg("sendToResellers"),name:"sendToResellers"}),(0,o.jsxs)("div",{className:m()({"mass-mail-form-block-hidden":!d.sendToResellers}),children:[(0,o.jsxs)(s.FormFieldSelect,{size:"lg",name:"sendToResellersMode",label:p.lmsg("sendToResellersMode"),children:[(0,o.jsx)("option",{value:"all",children:p.lmsg("sendToResellersModeAll")}),(0,o.jsx)("option",{value:"select",children:p.lmsg("sendToResellersModeSelect")}),(0,o.jsx)("option",{value:"except",children:p.lmsg("sendToResellersModeExcept")})]}),(0,o.jsx)(s.FormField,{className:m()({"mass-mail-form-block-hidden":"all"===d.sendToResellersMode}),name:"resellers",children:({setValue:e})=>(0,o.jsx)(u.default,{name:"select-reseller",onChange:e,options:S})})]}),(0,o.jsx)(s.FormFieldCheckbox,{label:p.lmsg("sendToClients"),name:"sendToClients"}),(0,o.jsxs)("div",{className:m()({"mass-mail-form-block-hidden":!d.sendToClients}),children:[(0,o.jsxs)(s.FormFieldSelect,{size:"lg",name:"sendToClientsMode",label:p.lmsg("sendToClientsMode"),children:[(0,o.jsx)("option",{value:"all",children:p.lmsg("sendToClientsModeAll")}),(0,o.jsx)("option",{value:"select",children:p.lmsg("sendToClientsModeSelect")}),(0,o.jsx)("option",{value:"except",children:p.lmsg("sendToClientsModeExcept")})]}),(0,o.jsx)(s.FormField,{className:m()({"mass-mail-form-block-hidden":"all"===d.sendToClientsMode}),name:"clients",children:({setValue:e})=>(0,o.jsx)(u.default,{name:"select-client",onChange:e,options:N})})]}),(0,o.jsx)(s.FormFieldText,{required:!0,size:"xl",label:p.lmsg("subject"),name:"subject"}),(0,o.jsx)(s.FormFieldText,{description:p.lmsg("bodyDescription"),required:!0,size:"fill",rows:10,multiline:!0,label:p.lmsg("body"),name:"body"}),v]})};f.propTypes={customers:d().array.isRequired,resellers:d().array.isRequired,loading:d().bool.isRequired,mutation:d().func.isRequired,onSuccess:d().func.isRequired,onSubmit:d().func,values:d().object.isRequired,submitButtonProps:d().object,onChange:d().func.isRequired,children:d().node,footer:d().node,errors:d().object,hideNameField:d().bool,applyButton:d().oneOf([d().object,d().bool])};const v=f},2604:(e,n,i)=>{"use strict";i.r(n),i.d(n,{default:()=>m});var s=i(296),a=i(90),t=i(713),l=i(668),d=i.n(l);const o=a.Locale.getSection("components.elements.double-list-selector"),r=({name:e,options:n,onChange:i=()=>{},...l})=>{const[d,r]=(0,s.useState)(null),m=(0,s.useRef)(n);return(0,s.useEffect)(()=>{const s=new a.EnhancedDoubleListSelector({list:n,applyTo:e,isSearchable:!0,locale:o,name:e,onChange:e=>{const n=Object.keys(e).reduce((n,i)=>e[i]?[...n,i]:n,[]);i(n)},...l});return r(s),()=>{s.remove(),r(null)}},[]),(0,s.useEffect)(()=>{d&&m.current!==n&&n.forEach((e,n)=>{m.current[n].selected!==e.selected&&(d._toggleItemSelection(n,!e.selected),m.current[n].selected=e.selected)})},[d,n]),(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)("div",{id:e}),d&&(0,s.jsx)(t.default,{children:d})]})};r.propTypes={name:d().string.isRequired,options:d().arrayOf(d().shape({selected:d().bool,id:d().any,title:d().string,description:d().string,icons:d().arrayOf(d().shape({src:d().string,title:d().string}))})).isRequired,isSearchable:d().bool,onChange:d().func};const m=r},2605:(e,n,i)=>{"use strict";i.r(n),i.d(n,{default:()=>M});var s=i(696),a=i(459),t=i(620),l=i(583),d=i(297),o=i(546),r=i(90),m=i(296),c=i(599),u=i(426),p=i(2600),f=i(1261),v=i.n(f),k=i(2606),T=i.n(k),g=i(2601),b=i.n(g),h=i(2602);const S=l.gql`
mutation SendMassEmail($input: SendMassEmailInput!) {
sendMassEmail(input: $input) {
errors {
email
error
}
}
}
`,N=r.Locale.getSection("components.pages.SendMassMailPage"),M=()=>{const{data:{viewer:{customers:e,resellers:n},massEmail:{templates:{nodes:i}}}}=(0,t.useQuery)(v()),[l]=(0,c.useSearchParams)(),[r,f]=(0,m.useState)(()=>({sendToClientsMode:"all",sendToResellersMode:"all",sendToAdmins:!1,sendToClients:!1,sendToResellers:!1,selectedTempalteId:l.get("templateId")})),[k,g]=(0,m.useState)({});(0,m.useEffect)(()=>{const e=r.selectedTempalteId;e&&u.default.query({query:T(),variables:{numericId:Number(e),id:btoa(`MassEmailTemplate:${e}`)}}).then(({data:{massEmail:{template:e,templateClients:n,templateResellers:i}}})=>{f(s=>({...s,fromEmail:e.fromEmail,body:e.body,subject:e.subject,sendToClientsMode:e.sendToClientsMode,sendToResellersMode:e.sendToResellersMode,sendToAdmins:e.sendToAdmins,sendToClients:e.sendToClients,sendToResellers:e.sendToResellers,clients:n.contacts.map(({id:e})=>atob(e).split(":")[1]),resellers:i.contacts.map(({id:e})=>atob(e).split(":")[1])}))})},[r.selectedTempalteId]);const M=(0,c.useNavigate)(),[x,{loading:F}]=(0,s.useMutation)(S,{update:p.evictMassEmailCache}),[E,{loading:y}]=(0,s.useMutation)(b());return(0,m.jsx)(h.default,{onSuccess:async()=>{if(r.saveAsTemplate){const{selectedTempalteId:e,saveAsTemplate:n,newTemplateName:i,clients:s=[],resellers:t=[],...l}=r;try{await E({variables:{input:{...l,name:i,clients:s.map(Number),resellers:t.map(Number)}}})}catch(e){if(!(e instanceof Error))throw e;if(!(0,a.isApolloError)(e)||!e.graphQLErrors.length)return void(0,o.addToast)({intent:"danger",message:e.message});const{graphQLErrors:n}=e;if("validate"===n[0].extensions?.category){const e=n[0].extensions.messages;g(e)}else(0,o.addToast)({intent:"danger",message:n[0].extensions?.debugMessage||n[0].message});return}}(0,o.addToast)({intent:"success",message:N.formatMessage("emailSent")}),M("..")},mutation:x,loading:F||y,customers:e,resellers:n,onChange:(e,n)=>{f(i=>(0,d.setIn)(i,e,n))},values:r,hideNameField:!0,onSubmit:e=>{if(e.saveAsTemplate&&!e.newTemplateName)return g({newTemplateName:{required:N.lmsg("fieldIsRequired")}}),null;const{selectedTempalteId:n,saveAsTemplate:i,newTemplateName:s,...a}=e;return a},errors:k,submitButtonProps:{children:N.lmsg("send")},footer:(0,m.jsxs)(m.Fragment,{children:[(0,m.jsx)(d.FormFieldCheckbox,{label:N.lmsg("saveAsTemplate"),name:"saveAsTemplate"}),r.saveAsTemplate&&(0,m.jsx)(d.FormFieldText,{required:!0,size:"xl",label:N.lmsg("newTemplateName"),name:"newTemplateName"})]}),children:!!i.length&&(0,m.jsx)(d.FormFieldSelect,{size:"xl",name:"selectedTempalteId",label:N.lmsg("selectedTemplate"),children:i.map(({templateId:e,name:n})=>(0,m.jsx)("option",{value:e.toString(),children:n},e))})})}},2606:e=>{var n={kind:"Document",definitions:[{kind:"OperationDefinition",operation:"query",name:{kind:"Name",value:"MassMailTemplate"},variableDefinitions:[{kind:"VariableDefinition",variable:{kind:"Variable",name:{kind:"Name",value:"id"}},type:{kind:"NonNullType",type:{kind:"NamedType",name:{kind:"Name",value:"ID"}}},directives:[]},{kind:"VariableDefinition",variable:{kind:"Variable",name:{kind:"Name",value:"numericId"}},type:{kind:"NonNullType",type:{kind:"NamedType",name:{kind:"Name",value:"Int"}}},directives:[]}],directives:[],selectionSet:{kind:"SelectionSet",selections:[{kind:"Field",name:{kind:"Name",value:"massEmail"},arguments:[],directives:[],selectionSet:{kind:"SelectionSet",selections:[{kind:"Field",name:{kind:"Name",value:"template"},arguments:[{kind:"Argument",name:{kind:"Name",value:"id"},value:{kind:"Variable",name:{kind:"Name",value:"id"}}}],directives:[],selectionSet:{kind:"SelectionSet",selections:[{kind:"Field",name:{kind:"Name",value:"name"},arguments:[],directives:[]},{kind:"Field",name:{kind:"Name",value:"fromEmail"},arguments:[],directives:[]},{kind:"Field",name:{kind:"Name",value:"sendToAdmins"},arguments:[],directives:[]},{kind:"Field",name:{kind:"Name",value:"sendToResellers"},arguments:[],directives:[]},{kind:"Field",name:{kind:"Name",value:"sendToResellersMode"},arguments:[],directives:[]},{kind:"Field",name:{kind:"Name",value:"sendToClients"},arguments:[],directives:[]},{kind:"Field",name:{kind:"Name",value:"sendToClientsMode"},arguments:[],directives:[]},{kind:"Field",name:{kind:"Name",value:"subject"},arguments:[],directives:[]},{kind:"Field",name:{kind:"Name",value:"body"},arguments:[],directives:[]}]}},{kind:"Field",name:{kind:"Name",value:"templateResellers"},arguments:[{kind:"Argument",name:{kind:"Name",value:"templateId"},value:{kind:"Variable",name:{kind:"Name",value:"numericId"}}}],directives:[],selectionSet:{kind:"SelectionSet",selections:[{kind:"Field",name:{kind:"Name",value:"contacts"},arguments:[],directives:[],selectionSet:{kind:"SelectionSet",selections:[{kind:"Field",name:{kind:"Name",value:"id"},arguments:[],directives:[]}]}}]}},{kind:"Field",name:{kind:"Name",value:"templateClients"},arguments:[{kind:"Argument",name:{kind:"Name",value:"templateId"},value:{kind:"Variable",name:{kind:"Name",value:"numericId"}}}],directives:[],selectionSet:{kind:"SelectionSet",selections:[{kind:"Field",name:{kind:"Name",value:"contacts"},arguments:[],directives:[],selectionSet:{kind:"SelectionSet",selections:[{kind:"Field",name:{kind:"Name",value:"id"},arguments:[],directives:[]}]}}]}}]}}]}}],loc:{start:0,end:566}};n.loc.source={body:"query MassMailTemplate($id: ID!, $numericId: Int!) {\n massEmail {\n template(id: $id) {\n name\n fromEmail\n sendToAdmins\n sendToResellers\n sendToResellersMode\n sendToClients\n sendToClientsMode\n subject\n body\n }\n templateResellers(templateId: $numericId) {\n contacts {\n id\n }\n }\n templateClients(templateId: $numericId) {\n contacts {\n id\n }\n }\n }\n}\n",name:"GraphQL request",locationOffset:{line:1,column:1}};function i(e,n){if("FragmentSpread"===e.kind)n.add(e.name.value);else if("VariableDefinition"===e.kind){var s=e.type;"NamedType"===s.kind&&n.add(s.name.value)}e.selectionSet&&e.selectionSet.selections.forEach(function(e){i(e,n)}),e.variableDefinitions&&e.variableDefinitions.forEach(function(e){i(e,n)}),e.definitions&&e.definitions.forEach(function(e){i(e,n)})}var s={};function a(e,n){for(var i=0;i<e.definitions.length;i++){var s=e.definitions[i];if(s.name&&s.name.value==n)return s}}n.definitions.forEach(function(e){if(e.name){var n=new Set;i(e,n),s[e.name.value]=n}}),e.exports=n,e.exports.MassMailTemplate=function(e,n){var i={kind:e.kind,definitions:[a(e,n)]};e.hasOwnProperty("loc")&&(i.loc=e.loc);var t=s[n]||new Set,l=new Set,d=new Set;for(t.forEach(function(e){d.add(e)});d.size>0;){var o=d;d=new Set,o.forEach(function(e){l.has(e)||(l.add(e),(s[e]||new Set).forEach(function(e){d.add(e)}))})}return l.forEach(function(n){var s=a(e,n);s&&i.definitions.push(s)}),i}(n,"MassMailTemplate")}}]);
//# sourceMappingURL=SendMassMailPage.js.map?74955efc5a013c59161b