PageSourceSearch

https://buildsaas-s18e.vercel.app/_next/static/chunks/pages/admin/editor/email-65f7ebaa51467333.js

js buildsaas-s18e.vercel.app collected 2026-10-03 06:19:43 UTC 18,034 bytes, 1 lines download raw bytes

1(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[722],{9385:(e,t,a)=>{"use strict";a.r(t),a.d(t,{default:()=>D});var s=a(37876),r=a(14232),l=a(89099),i=a(67768),n=a(67914),c=a(40097),o=a(66848),d=a(75784),u=a(13845),m=a(88875),x=a(5071),h=a(17225),p=a(16789),b=a(18841),f=a(81216),g=a(13216),w=a(51180),j=a(57606),v=a(11898),y=a(36603),N=a(83602),z=a(40865),S=a(41932),A=a(63249),E=a(89848),k=a(15672);let D=()=>{let e=(0,l.useRouter)(),t=(0,i.jE)(),{id:a}=e.query,[D,C]=(0,r.useState)(!1),[P,R]=(0,r.useState)(!1),[T,O]=(0,r.useState)(""),[_,H]=(0,r.useState)(!1),[q,I]=(0,r.useState)(!1);(0,r.useEffect)(()=>{let e=()=>{window.innerWidth>=1024&&(H(!0),I(!0))};return e(),window.addEventListener("resize",e),()=>window.removeEventListener("resize",e)},[]);let[G,L]=(0,r.useState)({subject:"",status:"draft"}),[F,J]=(0,r.useState)(""),[M,K]=(0,r.useState)(!1),[U,W]=(0,r.useState)(""),[X,$]=(0,r.useState)("custom"),[B,Q]=(0,r.useState)(!1),[Z,V]=(0,r.useState)(""),[Y,ee]=(0,r.useState)(!1),[et,ea]=(0,r.useState)(""),[es,er]=(0,r.useState)(""),[el,ei]=(0,r.useState)(!1),{data:en=[],isLoading:ec}=(0,n.I)({queryKey:["emails"],queryFn:()=>(0,N.l3)()}),{data:eo=[]}=(0,n.I)({queryKey:["users"],queryFn:()=>(0,z.C)()}),{data:ed=[]}=(0,n.I)({queryKey:["customers"],queryFn:()=>(0,S.Rf)()}),eu=en.filter(e=>{var t;return null==(t=e.subject)?void 0:t.toLowerCase().includes(T.toLowerCase())}),{data:em,isLoading:ex}=(0,n.I)({queryKey:["email",a],queryFn:async()=>a?await (0,N.x_)(a):null,enabled:!!a});(0,r.useEffect)(()=>{em&&a?(L({subject:em.subject||"",status:em.status||"draft"}),J(em.content||""),W(em.scheduledDate||"")):a||(L({subject:"",status:"draft"}),J(""),W(""))},[em,a]);let eh=(0,c.n)({mutationFn:async e=>a?await (0,N.Ww)(a,e):await (0,N.tp)(e),onSuccess:()=>{t.invalidateQueries({queryKey:["emails"]}),E.oR.success(a?"Email updated successfully!":"Email created successfully!")},onError:e=>{console.error("Error saving email:",e),E.oR.error("Failed to save email. Please try again."),R(!1)}}),ep=async()=>{if(R(!0),!G.subject||!F){E.oR.warning("Subject and content are required"),R(!1);return}eh.mutate({...G,content:F})},eb=()=>"user"===X?eo.map(e=>({value:e.id,label:"".concat(e.name||e.displayName||e.email," (").concat(e.email,")"),data:e})):"customer"===X?ed.map(e=>({value:e.id,label:"".concat(e.name||e.email," (").concat(e.email,")"),data:e})):[],ef=async()=>{if(!G.subject||!F)return void E.oR.warning("Subject and content are required");let e="",t="";if("custom"===X){if(!et.trim())return void E.oR.warning("Please enter an email address");e=et.trim(),t=es.trim()}else{if(!Z)return void E.oR.warning("Please select a recipient");let a=eb().find(e=>e.value===Z);a&&a.data&&(e=a.data.email||"",t=a.data.name||a.data.displayName||a.data.email||"")}if(!e)return void E.oR.warning("Recipient email is missing");if(!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(e))return void E.oR.warning("Please enter a valid email address");ei(!0);try{let a=await fetch("/api/emails/send-single",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({email:e,name:t||void 0,subject:G.subject,content:F})}),s=await a.json();a.ok?(E.oR.success("Email sent successfully!"),V(""),ea(""),er("")):E.oR.error(s.error||"Failed to send email")}catch(e){console.error("Error sending email:",e),E.oR.error("Failed to send email. Please try again.")}finally{ei(!1)}};return ex&&a?(0,s.jsx)("div",{className:"min-h-screen flex items-center justify-center bg-zinc-50",children:(0,s.jsxs)("div",{className:"text-center",children:[(0,s.jsx)("div",{className:"animate-spin rounded-full h-12 w-12 border-b-2 border-zinc-900 mx-auto"}),(0,s.jsx)("p",{className:"mt-4 text-zinc-600",children:"Loading..."})]})}):(0,s.jsxs)("div",{className:"min-h-screen bg-zinc-50 flex flex-col",children:[(0,s.jsx)("header",{className:"bg-white border-b border-zinc-200 sticky top-0 z-40",children:(0,s.jsx)("div",{className:"max-w-[1920px] mx-auto px-2 py-2",children:(0,s.jsxs)("div",{className:"flex items-center justify-between",children:[(0,s.jsxs)("div",{className:"flex items-center gap-3",children:[(0,s.jsxs)(o.P.button,{whileHover:{scale:1.02},whileTap:{scale:.98},onClick:()=>e.push("/admin?path=emails"),className:"flex items-center gap-1.5 px-3 py-1.5 text-sm text-zinc-700 hover:bg-zinc-100 rounded-xl transition-colors",children:[(0,s.jsx)(u.A,{className:"w-3.5 h-3.5"}),"Back"]}),(0,s.jsx)("div",{className:"h-5 w-px bg-zinc-300"}),(0,s.jsxs)("div",{className:"items-center gap-1.5 md:flex hidden",children:[(0,s.jsx)(m.A,{className:"w-4 h-4 text-zinc-700"}),(0,s.jsx)("h1",{className:"text-base font-semibold text-zinc-900",children:a?"Edit Email":"Create New Email"})]})]}),(0,s.jsxs)("div",{className:"flex items-center gap-2",children:[(0,s.jsx)(o.P.button,{whileHover:{scale:1.02},whileTap:{scale:.98},onClick:()=>H(!_),className:"lg:hidden flex items-center gap-1.5 px-3 py-1.5 text-sm text-zinc-700 hover:bg-zinc-100 rounded-xl transition-colors",children:(0,s.jsx)(x.A,{className:"w-4 h-4"})}),(0,s.jsx)(o.P.button,{whileHover:{scale:1.02},whileTap:{scale:.98},onClick:()=>I(!q),className:"lg:hidden flex items-center gap-1.5 px-3 py-1.5 text-sm text-zinc-700 hover:bg-zinc-100 rounded-xl transition-colors",children:(0,s.jsx)(h.A,{className:"w-4 h-4"})}),(0,s.jsxs)(o.P.button,{whileHover:{scale:1.02},whileTap:{scale:.98},onClick:()=>C(!D),className:"flex items-center gap-1.5 px-3 py-1.5 rounded-xl text-xs font-medium transition-colors ".concat(D?"bg-zinc-200 text-zinc-900":"bg-zinc-100 text-zinc-700 hover:bg-zinc-200"),children:[(0,s.jsx)(p.A,{className:"w-3.5 h-3.5"}),(0,s.jsx)("span",{className:"hidden sm:inline",children:D?"Edit":"Preview"})]}),(0,s.jsxs)(o.P.button,{whileHover:{scale:1.02},whileTap:{scale:.98},onClick:ep,disabled:P,className:"flex items-center gap-1.5 px-4 py-1.5 bg-zinc-900 hover:bg-zinc-800 text-white rounded-xl text-xs font-medium transition-colors disabled:opacity-50 disabled:cursor-not-allowed",children:[(0,s.jsx)(b.A,{className:"w-3.5 h-3.5"}),(0,s.jsx)("span",{className:"hidden sm:inline",children:P?"Saving...":a?"Update":"Save"})]})]})]})})}),(0,s.jsxs)("main",{className:"flex-1 w-full flex justify-center h-[calc(100vh-60px)] relative",children:[(0,s.jsx)(d.N,{children:(_||q)&&(0,s.jsx)(o.P.div,{initial:{opacity:0}
1,animate:{opacity:1},exit:{opacity:0},onClick:()=>{H(!1),I(!1)},className:"fixed inset-0 bg-black/50 z-40 lg:hidden"})}),(0,s.jsx)(d.N,{children:(0,s.jsxs)("div",{className:"fixed inset-y-0 lg:top-12 left-0 w-64 bg-white border-r border-zinc-200 flex flex-col z-50 lg:z-auto ".concat(_?"translate-x-0":"-translate-x-full lg:translate-x-0"," transition-transform duration-300 ease-in-out"),children:[(0,s.jsxs)("div",{className:"p-3 border-b border-zinc-200",children:[(0,s.jsxs)("div",{className:"flex items-center justify-between mb-3",children:[(0,s.jsxs)("div",{className:"flex items-center gap-2",children:[(0,s.jsx)(m.A,{className:"w-4 h-4 text-zinc-600"}),(0,s.jsx)("h2",{className:"text-sm font-semibold text-zinc-900",children:"Emails"})]}),(0,s.jsx)("button",{onClick:()=>H(!1),className:"lg:hidden p-1 hover:bg-zinc-100 rounded-xl transition-colors",children:(0,s.jsx)(f.A,{className:"w-4 h-4 text-zinc-600"})})]}),(0,s.jsxs)(o.P.button,{whileHover:{scale:1.02},whileTap:{scale:.98},onClick:()=>{e.push("/admin/editor/email"),H(!1)},className:"w-full flex items-center justify-center gap-1.5 px-3 py-1.5 bg-zinc-100 hover:bg-zinc-200 text-zinc-900 rounded-xl text-xs font-medium transition-colors mb-2",children:[(0,s.jsx)(g.A,{className:"w-3.5 h-3.5"}),"New Email"]}),(0,s.jsxs)("div",{className:"relative",children:[(0,s.jsx)(w.A,{className:"absolute left-2 top-1/2 transform -translate-y-1/2 w-3.5 h-3.5 text-zinc-400"}),(0,s.jsx)("input",{type:"text",placeholder:"Search emails...",value:T,onChange:e=>O(e.target.value),className:"w-full pl-8 pr-3 py-1.5 text-xs border border-zinc-300 rounded-xl focus:ring-2 focus:ring-zinc-500 focus:outline-none"})]})]}),(0,s.jsx)("div",{className:"flex-1 overflow-y-auto",children:ec?(0,s.jsx)("div",{className:"p-3 text-center text-xs text-zinc-500",children:"Loading..."}):0===eu.length?(0,s.jsx)("div",{className:"p-3 text-center text-xs text-zinc-500",children:"No emails found"}):(0,s.jsx)("div",{className:"p-2",children:eu.map(t=>(0,s.jsxs)(o.P.div,{whileHover:{scale:1.02},whileTap:{scale:.98},onClick:()=>{var a;a=t.id,e.push("/admin/editor/email?id=".concat(a)),H(!1)},className:"p-2 rounded-xl cursor-pointer transition-colors mb-1 ".concat(a===t.id?"bg-zinc-100 hover:bg-zinc-200 text-black  hover:text-zinc-900":"hover:bg-zinc-50 text-zinc-900"),children:[(0,s.jsx)("div",{className:"text-xs font-medium truncate mb-1",children:t.subject||"Untitled"}),(0,s.jsxs)("div",{className:"text-xs ".concat(a===t.id?"text-zinc-700":"text-zinc-800"),children:[(e=>{if(!e)return"N/A";try{return((null==e?void 0:e.toDate)?e.toDate():new Date(e)).toLocaleDateString("en-US",{month:"short",day:"numeric",year:"numeric"})}catch(e){return"N/A"}})(t.createdAt)," • ",t.status]})]},t.id))})})]})}),(0,s.jsx)("div",{className:"flex-1 flex justify-center px-4 py-4",children:D?(0,s.jsxs)("div",{className:"w-full max-w-3xl bg-white rounded-xl shadow-sm border border-zinc-200 p-6 overflow-y-auto",children:[(0,s.jsx)("h1",{className:"text-3xl font-bold text-zinc-900 mb-4",children:G.subject||"Email Preview"}),(0,s.jsx)("div",{className:"prose prose-zinc max-w-none prose-sm",children:(0,s.jsx)(k.oz,{children:F||""})})]}):(0,s.jsx)("div",{className:"w-full max-w-3xl bg-white rounded-xl shadow-sm border border-zinc-200 overflow-hidden flex flex-col",children:(0,s.jsx)("div",{className:"flex-1 overflow-hidden flex flex-col",children:(0,s.jsx)(y.A,{placeholder:"Start writing your email... Type / for commands",content:F,onChange:J,minHeight:"100%",maxHeight:"none"})})})}),(0,s.jsx)(d.N,{children:(0,s.jsxs)("div",{className:"fixed inset-y-0 lg:top-12 right-0 w-80 bg-white border-l border-zinc-200 p-4 overflow-y-auto z-50 lg:z-auto ".concat(q?"translate-x-0":"translate-x-full lg:translate-x-0"," transition-transform duration-300 ease-in-out"),children:[(0,s.jsxs)("div",{className:"flex items-center justify-between mb-4",children:[(0,s.jsxs)("h2",{className:"text-sm font-semibold text-zinc-900 flex items-center gap-1.5",children:[(0,s.jsx)(h.A,{className:"w-4 h-4"}),"Settings"]}),(0,s.jsx)("button",{onClick:()=>I(!1),className:"lg:hidden p-1 hover:bg-zinc-100 rounded-xl transition-colors",children:(0,s.jsx)(f.A,{className:"w-4 h-4 text-zinc-600"})})]}),(0,s.jsxs)("div",{className:"space-y-4",children:[(0,s.jsxs)("div",{children:[(0,s.jsx)("label",{className:"block text-xs font-medium text-zinc-700 mb-1.5",children:"Subject *"}),(0,s.jsx)("input",{type:"text",name:"subject",value:G.subject,onChange:e=>{let{name:t,value:a}=e.target;L(e=>({...e,[t]:a}))},className:"w-full px-3 py-1.5 text-sm border border-zinc-300 rounded-xl focus:ring-2 focus:ring-zinc-500 focus:outline-none",placeholder:"Email subject"})]}),(0,s.jsxs)("div",{children:[(0,s.jsx)("label",{className:"block text-xs font-medium text-zinc-700 mb-1.5",children:"Status *"}),(0,s.jsx)(A.A,{isOpen:M,onToggle:()=>K(!M),onSelect:e=>{L(t=>({...t,status:e}))},options:[{value:"draft",label:"Draft",color:"bg-yellow-100 text-yellow-800"},{value:"published",label:"Published",color:"bg-green-100 text-green-800"},{value:"scheduled",label:"Scheduled",color:"bg-blue-100 text-blue-800"}],value:G.status,placeholder:"Select status"}),(0,s.jsx)(d.N,{children:"scheduled"===G.status&&(0,s.jsxs)(o.P.div,{initial:{opacity:0,height:0}
1,animate:{opacity:1,height:"auto"},exit:{opacity:0,height:0},transition:{duration:.2},className:"mt-3",children:[(0,s.jsx)("label",{className:"block text-xs font-medium text-zinc-700 mb-1.5",children:"Schedule Date *"}),(0,s.jsxs)("div",{className:"relative",children:[(0,s.jsx)(j.A,{className:"absolute left-3 top-1/2 transform -translate-y-1/2 w-4 h-4 text-zinc-400"}),(0,s.jsx)("input",{type:"datetime-local",value:U,onChange:e=>W(e.target.value),min:new Date().toISOString().slice(0,16),className:"w-full pl-10 pr-3 py-1.5 text-sm border border-zinc-300 rounded-xl focus:ring-2 focus:ring-zinc-500 focus:outline-none"})]})]})})]}),(0,s.jsxs)("div",{className:"pt-4 border-t border-zinc-200",children:[(0,s.jsx)("label",{className:"block text-xs font-medium text-zinc-700 mb-3",children:"Action"}),(0,s.jsx)("div",{className:"mb-3",children:(0,s.jsx)(A.A,{isOpen:B,onToggle:()=>Q(!B),onSelect:e=>{$(e),V(""),ea(""),er("")},options:[{value:"user",label:"Send to User"},{value:"customer",label:"Send to Customer"},{value:"custom",label:"Send to Custom Email"}],value:X,placeholder:"Select recipient type",buttonClassName:"text-sm"})}),"custom"!==X&&(0,s.jsx)("div",{className:"mb-3",children:(0,s.jsx)(A.A,{isOpen:Y,onToggle:()=>ee(!Y),onSelect:e=>{V(e);let t=eb().find(t=>t.value===e);t&&t.data&&(ea(t.data.email||""),er(t.data.name||t.data.displayName||t.data.email||""))},options:eb(),value:Z,placeholder:"user"===X?"Select user...":"Select customer...",buttonClassName:"text-sm"})}),"custom"===X&&(0,s.jsxs)("div",{className:"space-y-3 mb-3",children:[(0,s.jsxs)("div",{children:[(0,s.jsx)("label",{className:"block text-xs font-medium text-zinc-700 mb-1.5",children:"Email *"}),(0,s.jsx)("input",{type:"email",value:et,onChange:e=>ea(e.target.value),className:"w-full px-3 py-1.5 text-sm border border-zinc-300 rounded-xl focus:ring-2 focus:ring-zinc-500 focus:outline-none",placeholder:"[email protected]"})]}),(0,s.jsxs)("div",{children:[(0,s.jsx)("label",{className:"block text-xs font-medium text-zinc-700 mb-1.5",children:"Name (Optional)"}),(0,s.jsx)("input",{type:"text",value:es,onChange:e=>er(e.target.value),className:"w-full px-3 py-1.5 text-sm border border-zinc-300 rounded-xl focus:ring-2 focus:ring-zinc-500 focus:outline-none",placeholder:"Recipient name"})]})]}),(0,s.jsxs)(o.P.button,{whileHover:{scale:1.02},whileTap:{scale:.98},onClick:ef,disabled:el,className:"w-full flex items-center justify-center gap-2 px-4 py-2 bg-zinc-900 hover:bg-zinc-800 text-white rounded-xl text-sm font-medium transition-colors disabled:opacity-50 disabled:cursor-not-allowed",children:[(0,s.jsx)(v.A,{className:"w-4 h-4"}),el?"Sending...":"Send Email"]})]})]})]})})]})]})}},11898:(e,t,a)=>{"use strict";a.d(t,{A:()=>s});let s=(0,a(22369).A)("Send",[["path",{d:"M14.536 21.686a.5.5 0 0 0 .937-.024l6.5-19a.496.496 0 0 0-.635-.635l-19 6.5a.5.5 0 0 0-.024.937l7.93 3.18a2 2 0 0 1 1.112 1.11z",key:"1ffxy3"}],["path",{d:"m21.854 2.147-10.94 10.939",key:"12cjpa"}]])},33050:(e,t,a)=>{(window.__NEXT_P=window.__NEXT_P||[]).push(["/admin/editor/email",function(){return a(9385)}])},40865:(e,t,a)=>{"use strict";a.d(t,{C:()=>l});var s=a(42009),r=a(54649);let l=async()=>{try{let e=(0,s.rJ)(r.db,"users"),t=(0,s.P)(e,(0,s.My)("createdAt","desc")),a=await (0,s.GG)(t),l=[];return a.forEach(e=>{l.push({id:e.id,...e.data()})}),l}catch(e){throw console.error("Error getting users:",e),e}}},41932:(e,t,a)=>{"use strict";a.d(t,{Rf:()=>n,i$:()=>c});var s=a(42009),r=a(54649);let l="customers",i=async e=>{try{let t=(0,s.P)((0,s.rJ)(r.db,l),(0,s._M)("email","==",e)),a=await (0,s.GG)(t);if(a.empty)return null;let i=a.docs[0];return{id:i.id,...i.data()}}catch(e){throw console.error("Error getting customer by email:",e),e}},n=async()=>{try{let e=(0,s.P)((0,s.rJ)(r.db,l),(0,s.My)("createdAt","desc")),t=await (0,s.GG)(e),a=[];return t.forEach(e=>{a.push({id:e.id,...e.data()})}),a}catch(e){try{let e=(0,s.P)((0,s.rJ)(r.db,l)),t=await (0,s.GG)(e),a=[];return t.forEach(e=>{a.push({id:e.id,...e.data()})}),a.sort((e,t)=>{var a,s;if(!e.createdAt&&!t.createdAt)return 0;if(!e.createdAt)return 1;if(!t.createdAt)return -1;let r=(null==(a=e.createdAt)?void 0:a.toDate)?e.createdAt.toDate():new Date(e.createdAt);return((null==(s=t.createdAt)?void 0:s.toDate)?t.createdAt.toDate():new Date(t.createdAt))-r}),a}catch(e){throw console.error("Error getting customers:",e),e}}},c=async e=>{try{let t=await i(e);if(!t)return{isSubscribed:!1,planName:null,status:null};return{isSubscribed:"active"===t.status,planName:t.planName||null,planId:t.planId||null,customerId:t.customerId||null,status:t.status||null,expiresAt:(e=>{if(!e)return null;if(e.toDate&&"function"==typeof e.toDate)return e.toDate().toISOString();if(e instanceof Date)return e.toISOString();if("string"==typeof e)return e;try{return new Date(e).toISOString()}catch(e){return console.error("Error converting timestamp:",e),null}})(t.expiresAt)}}catch(e){throw console.error("Error getting customer subscription:",e),e}}},83602:(e,t,a)=>{"use strict";a.d(t,{Ww:()=>o,iF:()=>d,l3:()=>i,tp:()=>c,x_:()=>n});var s=a(42009),r=a(54649);let l="emails",i=async()=>{try{let e=(0,s.P)((0,s.rJ)(r.db,l),(0,s.My)("createdAt","desc")),t=await (0,s.GG)(e),a=[];
1return t.forEach(e=>{a.push({id:e.id,...e.data()})}),a}catch(e){throw console.error("Error getting emails:",e),e}},n=async e=>{try{let t=(0,s.H9)(r.db,l,e),a=await (0,s.x7)(t);if(a.exists())return{id:a.id,...a.data()};throw Error("Email not found")}catch(e){throw console.error("Error getting email:",e),e}},c=async e=>{try{let t={...e,status:e.status||"draft",recipients:0,createdAt:(0,s.O5)(),updatedAt:(0,s.O5)()};return e.scheduledDate&&e.scheduledDate instanceof Date&&(t.scheduledDate=s.Dc.fromDate(e.scheduledDate)),(await (0,s.gS)((0,s.rJ)(r.db,l),t)).id}catch(e){throw console.error("Error creating email:",e),e}},o=async(e,t)=>{try{let a={...t,updatedAt:(0,s.O5)()};t.scheduledDate&&t.scheduledDate instanceof Date&&(a.scheduledDate=s.Dc.fromDate(t.scheduledDate));let i=(0,s.H9)(r.db,l,e);await (0,s.mZ)(i,a)}catch(e){throw console.error("Error updating email:",e),e}},d=async e=>{try{let t=(0,s.H9)(r.db,l,e);await (0,s.kd)(t)}catch(e){throw console.error("Error deleting email:",e),e}}},88875:(e,t,a)=>{"use strict";a.d(t,{A:()=>s});let s=(0,a(22369).A)("Mail",[["rect",{width:"20",height:"16",x:"2",y:"4",rx:"2",key:"18n3k1"}],["path",{d:"m22 7-8.97 5.7a1.94 1.94 0 0 1-2.06 0L2 7",key:"1ocrg3"}]])}},e=>{e.O(0,[5352,6361,1452,8023,6227,2252,1487,636,6593,8792],()=>e(e.s=33050)),_N_E=e.O()}]);

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.