PageSourceSearch

https://edu.studio/assets/_admin.admin.automations-CuHD9yE4.js

js edu.studio collected 2026-10-08 17:40:25 UTC 5,051 bytes, 1 lines download raw bytes

1import{r as d,j as e,a3 as _,s as b,t as S}from"./index-CXhT4GXx.js";import{u as k}from"./useQuery-Mw9p9XYf.js";import{C as K}from"./card-Csb9BfNR.js";import{u as Q,P as E,c as z,a as F}from"./index-COwGZC4g.js";import{u as P}from"./index-BvKiAz3O.js";import{a as U,u as G,T as O}from"./index-BBN7TFAG.js";import{c as C}from"./utils-BQHNewu7.js";import{I as D}from"./input-n-Eb1aB2.js";import{L as N}from"./label-DZMwV1WK.js";import{B as W}from"./button-DUw1FwI9.js";import"./index-LHNt3CwB.js";var x="Switch",[X]=F(x),[$,J]=X(x),R=d.forwardRef((s,i)=>{const{__scopeSwitch:r,name:c,checked:o,defaultChecked:t,required:n,disabled:a,value:u="on",onCheckedChange:v,form:l,...g}=s,[m,p]=d.useState(null),j=P(i,f=>p(f)),w=d.useRef(!1),y=m?l||!!m.closest("form"):!0,[h,H]=Q({prop:o,defaultProp:t??!1,onChange:v,caller:x});return e.jsxs($,{scope:r,checked:h,disabled:a,children:[e.jsx(E.button,{type:"button",role:"switch","aria-checked":h,"aria-required":n,"data-state":I(h),"data-disabled":a?"":void 0,disabled:a,value:u,...g,ref:j,onClick:z(s.onClick,f=>{H(M=>!M),y&&(w.current=f.isPropagationStopped(),w.current||f.stopPropagation())})}),y&&e.jsx(B,{control:m,bubbles:!w.current,name:c,value:u,checked:h,required:n,disabled:a,form:l,style:{transform:"translateX(-100%)"}})]})});R.displayName=x;var T="SwitchThumb",q=d.forwardRef((s,i)=>{const{__scopeSwitch:r,...c}=s,o=J(T,r);return e.jsx(E.span,{"data-state":I(o.checked),"data-disabled":o.disabled?"":void 0,...c,ref:i})});q.displayName=T;var V="SwitchBubbleInput",B=d.forwardRef(({__scopeSwitch:s,control:i,checked:r,bubbles:c=!0,...o},t)=>{const n=d.useRef(null),a=P(n,t),u=U(r),v=G(i);return d.useEffect(()=>{const l=n.current;if(!l)return;const g=window.HTMLInputElement.prototype,p=Object.getOwnPropertyDescriptor(g,"checked").set;if(u!==r&&p){const j=new Event("click",{bubbles:c});p.call(l,r),l.dispatchEvent(j)}},[u,r,c]),e.jsx("input",{type:"checkbox","aria-hidden":!0,defaultChecked:r,...o,tabIndex:-1,ref:a,style:{...o.style,...v,position:"absolute",pointerEvents:"none",opacity:0,margin:0}})});B.displayName=V;function I(s){return s?"checked":"unchecked"}var A=R,Y=q;const L=d.forwardRef(({className:s,...i},r)=>e.jsx(A,{className:C("peer inline-flex h-5 w-9 shrink-0 cursor-pointer items-center rounded-full border-2 border-transparent shadow-sm transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background disabled:cursor-not-allowed disabled:opacity-50 data-[state=checked]:bg-primary data-[state=unchecked]:bg-input",s),...i,ref:r,children:e.jsx(Y,{className:C("pointer-events-none block h-4 w-4 rounded-full bg-background shadow-lg ring-0 transition-transform data-[state=checked]:translate-x-4 data-[state=unchecked]:translate-x-0")})}));L.displayName=A.displayName;function ue(){const s=_(),{data:i}=k({queryKey:["automations"],queryFn:async()=>{const{data:t}=await b.from("automations").select("*");return t??[]}}),{data:r}=k({queryKey:["templates"],queryFn:async()=>{const{data:t}=await b.from("email_templates").select("*");return t??[]}}),c=async(t,n)=>{await b.from("automations").update({enabled:n}).eq("id",t),s.invalidateQueries({queryKey:["automations"]})},o={waitlist_signup:"Someone joins the waitlist",contact_submission:"Someone uses the contact form"};return e.jsxs("div",{children:[e.jsxs("header",{className:"mb-6",children:[e.jsx("h1",{className:"text-2xl font-semibold tracking-tight",children:"Automations"}),e.jsx("p",{className:"mt-1 text-sm text-muted-foreground",children:"Auto-reply emails triggered by site events."})]}),e.jsx("div",{className:"space-y-4",children:i?.map(t=>{const n=r?.find(a=>a.slug===t.template_slug);return e.jsxs(K,{className:"p-6",children:[e.jsxs("div",{className:"flex items-start justify-between gap-4",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"text-base font-semibold",children:o[t.trigger_event]??t.trigger_event}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:["Sends template:"," ",e.jsx("span",{className:"font-mono",children:t.template_slug})]})]}),e.jsx(L,{checked:t.enabled,onCheckedChange:a=>c(t.id,a)})]}),n&&e.jsx(Z,{template:n})]},t.id)})})]})}function Z({template:s}
1){const i=_(),[r,c]=d.useState(s.subject),[o,t]=d.useState(s.html);d.useEffect(()=>{c(s.subject),t(s.html)},[s.id]);const n=async()=>{const{error:a}=await b.from("email_templates").update({subject:r,html:o}).eq("id",s.id);if(a){S.error(a.message);return}S.success("Template saved"),i.invalidateQueries({queryKey:["templates"]})};return e.jsx("div",{className:"mt-4 border-t border-border pt-4",children:e.jsxs("div",{className:"grid gap-3",children:[e.jsxs("div",{children:[e.jsx(N,{children:"Subject"}),e.jsx(D,{value:r,onChange:a=>c(a.target.value)})]}),e.jsxs("div",{children:[e.jsxs(N,{children:["Body (HTML, use ","{{name}}"," and ","{{school}}",")"]}),e.jsx(O,{rows:6,value:o,onChange:a=>t(a.target.value)})]}),e.jsx("div",{children:e.jsx(W,{size:"sm",onClick:n,children:"Save template"})})]})})}export{ue as component};

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.