PageSourceSearch

https://msastroacademy.com/assets/email-DZaXe4r9.js

js msastroacademy.com collected 2026-10-02 01:36:47 UTC 7,671 bytes, 1 lines download raw bytes

1import{r as n,j as e}from"./react-vendor-DDlTsOEd.js";import{A as P}from"./AdminLayout-B0DIBAYd.js";import{c as R,d as m,G as u,J as N,K as x}from"./index-BBAL-XO_.js";import{T as S}from"./textarea-H_45bX76.js";import{B as b}from"./badge-D-Efy8A-.js";import"./megaphone-c2Ccoqv-.js";import"./clipboard-check-B-VFQxDc.js";import"./database-CfQ3DoFp.js";import"./tag-finmna5A.js";import"./credit-card-jC5ykv7d.js";function O(){const{toast:i}=R(),[w,k]=n.useState([]),[h,C]=n.useState(""),[c,T]=n.useState(""),[r,_]=n.useState(""),[l,$]=n.useState(""),[g,E]=n.useState(25),[a,j]=n.useState(null),[f,A]=n.useState([]),[o,d]=n.useState(!1),p=()=>m.get("/admin/email/campaigns").then(s=>A(s.campaigns)).catch(()=>{});n.useEffect(()=>{m.get("/admin/email/audiences").then(s=>k(s.audiences)).catch(()=>{}),p()},[]);function B(s){return!s.dry_run&&s.sent_count+s.failed_count<s.recipients_total}async function F(s){d(!0);try{const t=await m.post("/admin/email/send",{audience:s.audience,subject:s.subject,bodyTe:r,bodyEn:l,dryRun:!1,limit:s.recipients_total,resumeCampaignId:s.id});j(t),i({title:`Sent ${t.sent}`,description:`${t.skippedAlreadyDelivered??0} already had it${t.failed?`, ${t.failed} failed`:""}`}),p()}catch(t){i({title:"Could not resume",description:t.message,variant:"destructive"})}finally{d(!1)}}async function y(s){if(!h){i({title:"Choose an audience first",variant:"destructive"});return}if(!c.trim()){i({title:"Subject is required",variant:"destructive"});return}if(!r.trim()&&!l.trim()){i({title:"Write at least one language",variant:"destructive"});return}d(!0);try{const t=await m.post("/admin/email/send",{audience:h,subject:c,bodyTe:r,bodyEn:l,dryRun:s,limit:g});j(t),s||(i({title:`Sent ${t.sent}`,description:t.failed?`${t.failed} failed`:"No failures"}),p())}catch(t){i({title:"Failed",description:t.message,variant:"destructive"})}finally{d(!1)}}async function v(s){if(!c.trim()){i({title:"Subject is required",variant:"destructive"});return}d(!0);try{const t=await m.post("/admin/email/test",{subject:c,bodyTe:r,bodyEn:l,language:s});i({title:t.sent?`Test sent to ${t.to}`:"Test failed to send"})}catch(t){i({title:"Failed",description:t.message,variant:"destructive"})}finally{d(!1)}}return e.jsxs(P,{children:[e.jsxs("div",{className:"mb-6",children:[e.jsx("h1",{className:"text-2xl font-bold text-gray-900",children:"Email"}),e.jsx("p",{className:"text-sm text-gray-900",children:"Contact audiences always exclude anyone without consent, unsubscribed, suppressed, or whose account is blocked or erased."})]}),e.jsxs("div",{className:"grid gap-6 lg:grid-cols-3",children:[e.jsxs("div",{className:"space-y-5 lg:col-span-2",children:[e.jsxs("div",{children:[e.jsx(u,{className:"mb-2 block",children:"Audience"}),e.jsx("div",{className:"grid gap-2 sm:grid-cols-2",children:w.map(s=>e.jsxs("button",{onClick:()=>C(s.key),className:`rounded-lg border p-3 text-left ${h===s.key?"border-blue-500 bg-blue-50":"border-gray-200 bg-white"}`,children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsx("span",{className:"text-sm font-medium text-gray-900",children:s.label}),e.jsx(b,{className:s.kind==="student"?"bg-blue-100 text-blue-700":"bg-emerald-100 text-emerald-700",children:s.count})]}),e.jsx("p",{className:"mt-1 text-xs text-gray-900",children:Object.entries(s.byLanguage).map(([t,L])=>`${L} ${t}`).join(" · ")||"—"})]},s.key))})]}),e.jsxs("div",{children:[e.jsx(u,{htmlFor:"subject",children:"Subject"}),e.jsx(N,{id:"subject",value:c,onChange:s=>T(s.target.value)})]}),e.jsxs("div",{className:"grid gap-4 md:grid-cols-2",children:[e.jsxs("div",{children:[e.jsx(u,{htmlFor:"te",children:"Telugu body"}),e.jsx("p",{className:"mb-1 text-xs text-gray-900",children:"Most recipients read this one."}),e.jsx(S,{id:"te",rows:10,value:r,onChange:s=>_(s.target.value)})]}),e.jsxs("div",{children:[e.jsx(u,{htmlFor:"en",children:"English body"}),e.jsx("p",{className:"mb-1 text-xs text-gray-900",children:"Used for recipients set to English."}),e.jsx(S,{id:"en",rows:10,value:l,onChange:s=>$(s.target.value)})]})]}),e.jsxs("div",{className:"flex flex-wrap items-end gap-3",children:[e.jsxs("div",{children:[e.jsx(u,{htmlFor:"limit",children:"Send at most"}),e.jsx(N,{id:"limit",type:"number",min:1,max:500,value:g,className:"w-28",onCh
1ange:s=>E(Math.max(1,Math.min(500,Number(s.target.value)||1)))})]}),e.jsx(x,{variant:"outline",disabled:o,onClick:()=>v("te"),children:"Test me (Telugu)"}),e.jsx(x,{variant:"outline",disabled:o,onClick:()=>v("en"),children:"Test me (English)"}),e.jsx(x,{variant:"outline",disabled:o,onClick:()=>y(!0),children:"Preview recipients"}),e.jsx(x,{disabled:o||!a||a.dryRun===!1,className:"bg-blue-600 hover:bg-blue-700",onClick:()=>{confirm(`Send to ${a?.selected??0} people. This cannot be undone.`)&&y(!1)},children:"Send for real"})]}),e.jsx("p",{className:"text-xs text-gray-900",children:"Preview first — the send button stays disabled until you have seen who it would reach. This domain has little sending history, so start with a small batch and widen once it lands in inboxes."}),a&&e.jsxs("div",{className:"rounded-xl border border-gray-200 bg-white p-4",children:[e.jsxs("p",{className:"mb-2 text-sm font-semibold text-gray-900",children:[a.dryRun?"Preview":"Sent"," — ",a.audienceLabel]}),e.jsxs("div",{className:"grid grid-cols-2 gap-2 text-sm sm:grid-cols-4",children:[e.jsxs("div",{children:[e.jsx("span",{className:"text-gray-900",children:"Audience"}),e.jsx("p",{className:"font-semibold tabular-nums",children:a.audienceSize})]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-gray-900",children:"Would receive"}),e.jsx("p",{className:"font-semibold tabular-nums",children:a.selected})]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-gray-900",children:"Skipped (no copy)"}),e.jsx("p",{className:"font-semibold tabular-nums",children:a.skippedNoCopy})]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-gray-900",children:"Sent"}),e.jsx("p",{className:"font-semibold tabular-nums",children:a.sent})]})]}),a.skippedNoCopy>0&&e.jsxs("p",{className:"mt-2 text-xs text-amber-700",children:[a.skippedNoCopy," recipients read a language you left blank, so they are skipped rather than sent an empty email."]})]})]}),e.jsxs("div",{children:[e.jsx("h2",{className:"mb-2 text-sm font-semibold text-gray-900",children:"Recent sends"}),e.jsxs("div",{className:"space-y-2",children:[f.length===0&&e.jsx("p",{className:"text-sm text-gray-900",children:"Nothing sent yet."}),f.map(s=>e.jsxs("div",{className:"rounded-lg border border-gray-200 bg-white p-3",children:[e.jsxs("div",{className:"flex items-start justify-between gap-2",children:[e.jsx("p",{className:"text-sm font-medium text-gray-900",children:s.subject}),s.dry_run?e.jsx(b,{className:"bg-gray-100 text-gray-900",children:"preview"}):e.jsxs(b,{className:"bg-green-100 text-green-700",children:[s.sent_count," sent"]})]}),e.jsxs("p",{className:"mt-1 text-xs text-gray-800",children:[s.audience," · ",new Date(s.created_at).toLocaleString("en-IN"),s.failed_count>0&&e.jsxs("span",{className:"text-red-600",children:[" · ",s.failed_count," failed"]})]}),B(s)&&e.jsxs("div",{className:"mt-2 flex items-center gap-2",children:[e.jsxs("p",{className:"text-xs text-amber-700",children:["Stopped after ",s.sent_count+s.failed_count," of ",s.recipients_total,"."]}),e.jsx("button",{onClick:()=>F(s),disabled:o||!r.trim()&&!l.trim(),className:"rounded-md border border-amber-300 bg-amber-50 px-2 py-1 text-xs font-medium text-amber-800 disabled:opacity-40",title:!r.trim()&&!l.trim()?"Put the same body back in the form first":void 0,children:"Send the rest"})]})]},s.id))]})]})]})]})}export{O as default};

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.