PageSourceSearch

https://atzuma.co.il/assets/AdminEmailTemplates-BmvggeWX.js

js atzuma.co.il collected 2026-09-24 21:10:45 UTC 15,233 bytes, 2 lines download raw bytes

1import{j as e}from"./index-BtgGoHYl.js";import{r as l}from"./router-BXL9ASSk.js";import{E as L}from"./Editor-qH2SyrCb.js";import{P as R,X as N}from"./x-DLAfM6LU.js";import{A as B}from"./alert-circle-BgjQ34lX.js";import{C as O}from"./check-circle-BIzd8jdG.js";import{S as V}from"./save-y-r7PvMF.js";import{M as H}from"./mail-CGU6BVZ7.js";import{E as U}from"./eye-mhWqvyfb.js";import{c as q}from"./createLucideIcon-0jETPTlQ.js";import{C as W}from"./copy-3fuCurG8.js";import{T as Y}from"./trash-2-BUYcZ4PG.js";import"./vendor-BNcAc9ko.js";(function(){try{var n=typeof window<"u"?window:typeof global<"u"?global:typeof globalThis<"u"?globalThis:typeof self<"u"?self:{};n.SENTRY_RELEASE={id:"[email protected]"}}catch{}})();try{(function(){var n=typeof window<"u"?window:typeof global<"u"?global:typeof globalThis<"u"?globalThis:typeof self<"u"?self:{},x=new n.Error().stack;x&&(n._sentryDebugIds=n._sentryDebugIds||{},n._sentryDebugIds[x]="9b719dbc-4304-4700-aac7-1370ae85647c",n._sentryDebugIdIdentifier="sentry-dbid-9b719dbc-4304-4700-aac7-1370ae85647c")})()}catch{}const G=q("PenSquare",[["path",{d:"M11 4H4a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2v-7",key:"1qinfi"}],["path",{d:"M18.5 2.5a2.12 2.12 0 0 1 3 3L12 15l-4 1 1-4Z",key:"w2jsv5"}]]),oe=()=>{const[n,x]=l.useState({transactional:[],marketing:[]}),[b,c]=l.useState(null),[_,u]=l.useState(!1),[p,h]=l.useState(!1),[k,f]=l.useState(!1),[y,T]=l.useState({subject:"",content:""}),[C,S]=l.useState({}),[E,o]=l.useState(!0),[v,d]=l.useState(null),[j,m]=l.useState(null),[s,i]=l.useState({name:"",category:"transactional",event_type:"petition_created",subject_template:"",content_template:"",sendgrid_template_id:"",language:"en",is_active:!0}),A={transactional:{petition_created:"Petition Created Confirmation",signature_thanks:"Signature Thank You",petition_update:"Petition Update Notification",victory_celebration:"Victory Celebration",hero_payment_confirmation:"Hero Payment Confirmation",user_registration:"User Registration",password_reset:"Password Reset",admin_alert:"Admin Alert"},marketing:{weekly_digest:"Weekly Digest",petition_promotion:"Petition Promotion",reengagement:"Re-engagement Campaign",category_recommendation:"Category-based Recommendation"}};l.useEffect(()=>{g(),P()},[]);const g=async()=>{try{o(!0);const t=await fetch("/api/v1/admin/email/templates",{headers:{Authorization:`Bearer ${localStorage.getItem("auth_token")}`}});if(!t.ok)throw new Error("Failed to fetch templates");const a=await t.json();x(a.templates||{transactional:[],marketing:[]})}catch(t){d("Failed to load email templates"),console.error(t)}finally{o(!1)}},P=async()=>{try{const t=await fetch("/api/v1/admin/email/variables",{headers:{Authorization:`Bearer ${localStorage.getItem("auth_token")}`}});if(!t.ok)throw new Error("Failed to fetch variables");const a=await t.json();S(a.variables||{})}catch(t){console.error("Failed to load variables:",t)}},I=async()=>{try{o(!0),d(null);const t=p?"/api/v1/admin/email/templates":`/api/v1/admin/email/templates/${b?.id}`,r=await fetch(t,{method:p?"POST":"PUT",headers:{"Content-Type":"application/json",Authorization:`Bearer ${localStorage.getItem("token")}`},body:JSON.stringify(s)});if(!r.ok)throw new Error("Failed to save template");const M=await r.json();m(M.message||"Template saved successfully!"),await g(),u(!1),h(!1),c(null),setTimeout(()=>m(null),3e3)}catch(t){d("Failed to save template"),console.error(t)}finally{o(!1)}},$=async t=>{try{o(!0);const a=await fetch(`/api/v1/admin/email/templates/${t.id}/preview`,{headers:{Authorization:`Bearer ${localStorage.getItem("auth_token")}`}});if(!a.ok)throw new Error("Failed to preview template");const r=await a.json();T(r),f(!0),c(t)}catch(a){d("Failed to preview template"),console.error(a)}finally{o(!1)}},F=async t=>{try{o(!0);const a=await fetch(`/api/v1/admin/email/templates/${t.id}/duplicate`,{method:"POST",headers:{Authorization:`Bearer ${localStorage.getItem("auth_token")}`}});if(!a.ok)throw new Error("Failed to duplicate template");const r=await a.json();m(r.message||"Template duplicated successfully!"),await g(),setTimeout(()=>m(null),3e3)}catch(a){d("Failed to duplicate template"),console.error(a)}finally{o(!1)}},D=async t=>{if(confirm(`Are you sure you want to deactivate "${t.name}"?`))try{o(!0);const a=await fetch(`/api/v1/admin/email/templates/${t.id}`,{method:"DELETE",headers:{Authorization:`Bearer ${localStorage.getItem("auth_token")}`}});if(!a.ok)throw new Error("Failed to deactivate template");const r=await a.json();m(r.message||"Template deactivated successfully!"),await g(),setTimeout(()=>m(null),3e3)}catch(a){d("Failed to deactivate template"),console.error(a)}finally{o(!1)}},z=t=>{const a=s.content_template||"";i({...s,content_template:a+` {{${t}}
1}`})},w=t=>e.jsxs("div",{className:"bg-white rounded-lg shadow-sm border border-gray-200 p-4 hover:shadow-md transition-shadow",children:[e.jsxs("div",{className:"flex justify-between items-start mb-2",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"font-semibold text-gray-900",children:t.name}),e.jsx("p",{className:"text-sm text-gray-500",children:t.event_type})]}),e.jsxs("div",{className:"flex items-center space-x-1",children:[t.is_active?e.jsx("span",{className:"px-2 py-1 text-xs font-medium bg-green-100 text-green-800 rounded-full",children:"Active"}):e.jsx("span",{className:"px-2 py-1 text-xs font-medium bg-gray-100 text-gray-800 rounded-full",children:"Inactive"}),e.jsxs("span",{className:"px-2 py-1 text-xs font-medium bg-blue-100 text-blue-800 rounded-full",children:["v",t.version]})]})]}),e.jsx("p",{className:"text-sm text-gray-600 mb-3 line-clamp-2",children:t.subject_template}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center space-x-2 text-xs text-gray-500",children:[e.jsx(H,{className:"w-4 h-4"}),e.jsxs("span",{children:[t.email_logs_count||0," sent"]})]}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx("button",{onClick:()=>$(t),className:"p-1 text-gray-600 hover:text-blue-600 transition-colors",title:"Preview",children:e.jsx(U,{className:"w-4 h-4"})}),e.jsx("button",{onClick:()=>{c(t),i(t),u(!0)},className:"p-1 text-gray-600 hover:text-green-600 transition-colors",title:"Edit",children:e.jsx(G,{className:"w-4 h-4"})}),e.jsx("button",{onClick:()=>F(t),className:"p-1 text-gray-600 hover:text-purple-600 transition-colors",title:"Duplicate",children:e.jsx(W,{className:"w-4 h-4"})}),e.jsx("button",{onClick:()=>D(t),className:"p-1 text-gray-600 hover:text-red-600 transition-colors",title:"Deactivate",children:e.jsx(Y,{className:"w-4 h-4"})})]})]})]},t.id);return E?e.jsx("div",{className:"flex items-center justify-center min-h-screen",children:e.jsx("div",{className:"animate-spin rounded-full h-12 w-12 border-b-2 border-blue-600"})}):e.jsxs("div",{className:"max-w-7xl mx-auto px-4 py-8",children:[e.jsx("div",{className:"mb-8",children:e.jsxs("div",{className:"flex justify-between items-center",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"text-3xl font-bold text-gray-900",children:"Email Templates"}),e.jsx("p",{className:"mt-2 text-gray-600",children:"Manage your SendGrid email templates with dynamic variables"})]}),e.jsxs("button",{onClick:()=>{h(!0),i({name:"",category:"transactional",event_type:"petition_created",subject_template:"",content_template:"",sendgrid_template_id:"",language:"en",is_active:!0})},className:"flex items-center px-4 py-2 bg-blue-600 text-white rounded-lg hover:bg-blue-700 transition-colors",children:[e.jsx(R,{className:"w-5 h-5 mr-2"}),"Create Template"]})]})}),v&&e.jsxs("div",{className:"mb-4 p-4 bg-red-50 border border-red-200 rounded-lg flex items-center",children:[e.jsx(B,{className:"w-5 h-5 text-red-600 mr-2 flex-shrink-0"}),e.jsx("span",{className:"text-red-800",children:v})]}),j&&e.jsxs("div",{className:"mb-4 p-4 bg-green-50 border border-green-200 rounded-lg flex items-center",children:[e.jsx(O,{className:"w-5 h-5 text-green-600 mr-2 flex-shrink-0"}),e.jsx("span",{className:"text-green-800",children:j})]}),(_||p)&&e.jsx("div",{className:"fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center z-50 p-4",children:e.jsxs("div",{className:"bg-white rounded-lg max-w-4xl w-full max-h-[90vh] overflow-y-auto",children:[e.jsxs("div",{className:"sticky top-0 bg-white border-b border-gray-200 px-6 py-4 flex justify-between items-center",children:[e.jsx("h2",{className:"text-xl font-semibold",children:p?"Create New Template":`Edit: ${b?.name}`}),e.jsx("button",{onClick:()=>{u(!1),h(!1),c(null)},className:"text-gray-500 hover:text-gray-700",children:e.jsx(N,{className:"w-6 h-6"})})]}),e.jsxs("div",{className:"p-6 space-y-6",children:[e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 mb-1",children:"Template Name"}),e.jsx("input",{type:"text",value:s.name||"",onChange:t=>i({...s,name:t.target.value}),className:"w-full px-3 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-transparent",placeholder:"e.g., Welcome Email"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 mb-1",children:"Category"}),e.jsxs("select",{value:s.category||"transactional",onChange:t=>i({...s,category:t.target.value}),className:"w-full px-3 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-transparent",children:[e.jsx("option",{value:"transactional",children:"Transactional"}),e.jsx("option",{value:"marketing",children:"Marketing"})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 mb-1",children:"Event Type"}),e.jsx("select",{value:s.event_type||"",onChange:t=>i({...s,event_type:t.target.value}),className:"w-full px-3 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-transparent",children:Object.entries(A[s.c
1ategory||"transactional"]).map(([t,a])=>e.jsx("option",{value:t,children:a},t))})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 mb-1",children:"Language"}),e.jsxs("select",{value:s.language||"en",onChange:t=>i({...s,language:t.target.value}),className:"w-full px-3 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-transparent",children:[e.jsx("option",{value:"en",children:"English"}),e.jsx("option",{value:"he",children:"Hebrew"}),e.jsx("option",{value:"ar",children:"Arabic"})]})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 mb-1",children:"SendGrid Template ID (Optional)"}),e.jsx("input",{type:"text",value:s.sendgrid_template_id||"",onChange:t=>i({...s,sendgrid_template_id:t.target.value}),className:"w-full px-3 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-transparent",placeholder:"d-xxxxxxxxxxxxx"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 mb-1",children:"Subject Template"}),e.jsx("input",{type:"text",value:s.subject_template||"",onChange:t=>i({...s,subject_template:t.target.value}),className:"w-full px-3 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-transparent",placeholder:"Welcome {{user_name}}! Your petition is live"}),e.jsxs("p",{className:"mt-1 text-xs text-gray-500",children:["Use ","{{variable_name}}"," for dynamic content"]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 mb-2",children:"Available Variables"}),e.jsx("div",{className:"flex flex-wrap gap-2",children:Object.entries(C).map(([t,a])=>e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{className:"text-xs font-medium text-gray-500 uppercase",children:t}),e.jsx("div",{className:"flex flex-wrap gap-1",children:a.map(r=>e.jsx("button",{onClick:()=>z(r.variable_key),className:"px-2 py-1 text-xs bg-gray-100 hover:bg-gray-200 rounded-md transition-colors",title:r.description,children:`{{${r.variable_key}}}`},r.id))})]},t))})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 mb-2",children:"Content Template"}),e.jsx(L,{apiKey:"your-tinymce-api-key",value:s.content_template||"",onEditorChange:t=>i({...s,content_template:t}),init:{height:400,menubar:!1,plugins:["advlist","autolink","lists","link","image","charmap","preview","anchor","searchreplace","visualblocks","code","fullscreen","insertdatetime","media","table","help","wordcount"],toolbar:"undo redo | blocks | bold italic forecolor | alignleft aligncenter alignright al
1ignjustify | bullist numlist outdent indent | removeformat | help",content_style:"body { font-family:Helvetica,Arial,sans-serif; font-size:14px }"}})]}),e.jsxs("div",{className:"flex items-center",children:[e.jsx("input",{type:"checkbox",id:"is_active",checked:s.is_active,onChange:t=>i({...s,is_active:t.target.checked}),className:"h-4 w-4 text-blue-600 focus:ring-blue-500 border-gray-300 rounded"}),e.jsx("label",{htmlFor:"is_active",className:"ml-2 block text-sm text-gray-900",children:"Template is active"})]}),e.jsxs("div",{className:"flex justify-end space-x-3",children:[e.jsx("button",{onClick:()=>{u(!1),h(!1),c(null)},className:"px-4 py-2 text-gray-700 bg-gray-100 rounded-lg hover:bg-gray-200 transition-colors",children:"Cancel"}),e.jsxs("button",{onClick:I,className:"flex items-center px-4 py-2 bg-blue-600 text-white rounded-lg hover:bg-blue-700 transition-colors",children:[e.jsx(V,{className:"w-4 h-4 mr-2"}),"Save Template"]})]})]})]})}),k&&e.jsx("div",{className:"fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center z-50 p-4",children:e.jsxs("div",{className:"bg-white rounded-lg max-w-3xl w-full max-h-[80vh] overflow-y-auto",children:[e.jsxs("div",{className:"sticky top-0 bg-white border-b border-gray-200 px-6 py-4 flex justify-between items-center",children:[e.jsx("h2",{className:"text-xl font-semibold",children:"Template Preview"}),e.jsx("button",{onClick:()=>{f(!1),c(null)},className:"text-gray-500 hover:text-gray-700",children:e.jsx(N,{className:"w-6 h-6"})})]}),e.jsxs("div",{className:"p-6",children:[e.jsxs("div",{className:"mb-4",children:[e.jsx("h3",{className:"text-sm font-medium text-gray-700 mb-2",children:"Subject:"}),e.jsx("p",{className:"p-3 bg-gray-50 rounded-lg",children:y.subject})]}),e.jsxs("div",{children:[e.jsx("h3",{className:"text-sm font-medium text-gray-700 mb-2",children:"Content:"}),e.jsx("div",{className:"p-4 bg-gray-50 rounded-lg prose max-w-none",dangerouslySetInnerHTML:{__html:y.content}})]})]})]})}),e.jsxs("div",{className:"space-y-8",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"text-xl font-semibold text-gray-900 mb-4",children:"Transactional Templates"}),e.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4",children:n.transactional?.map(w)})]}),e.jsxs("div",{children:[e.jsx("h2",{className:"text-xl font-semibold text-gray-900 mb-4",children:"Marketing Templates"}),e.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4",children:n.marketing?.map(w)})]})]})]})};export{oe as default};
2//# sourceMappingURL=AdminEmailTemplates-BmvggeWX.js.map

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.