PageSourceSearch

https://crm5w.lovable.app/assets/automations-h8px7Fcf.js

js crm5w.lovable.app collected 2026-10-03 03:21:18 UTC 8,219 bytes, 2 lines download raw bytes

1const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/workflow-canvas-Dqhb5iFZ.js","assets/index-BB_hlVKv.js","assets/value-BTdN53H7.js","assets/sparkles-BGitj5In.js","assets/webhook-CKMqD7Of.js","assets/clock-BaFBnCqZ.js","assets/tag-C9UQMHNl.js","assets/bell-ByR4l_Np.js","assets/mail-CSYyIgbO.js","assets/zap-Zp3ncpIT.js","assets/trash-2-DUWD8wJm.js","assets/workflow-canvas-DLioOiRN.css"])))=>i.map(i=>d[i]);
2import{r as a,j as e,F as Q,a2 as $,B as m,G as ee,a3 as se,a4 as te,L as T,I as F,T as ae,U as le,V as ie,W as ne,X as O,a5 as re,a6 as oe,Y as R,a7 as de,s as l,a8 as ce,t as i}from"./index-BB_hlVKv.js";import{u as me,L as ue}from"./list-pagination-DhZLx0BD.js";import{u as pe}from"./site-scope-CIh7XkdK.js";import{B as h}from"./badge-InD3bTxh.js";import{P as xe}from"./plus-DZ94RjGt.js";import{Z as ge}from"./zap-Zp3ncpIT.js";import{A as he}from"./arrow-right-D8PCoEJ6.js";import{P as fe}from"./pencil-D8YQWc0u.js";import{T as je}from"./trash-2-DUWD8wJm.js";import"./globe-CziqNxFi.js";const ve=a.lazy(()=>ce(()=>import("./workflow-canvas-Dqhb5iFZ.js"),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11]))),Ne=[{value:"contact_form",label:"Contact form submitted"},{value:"newsletter_signup",label:"Newsletter signup"},{value:"pdf_downloaded",label:"PDF downloaded"},{value:"contact_created",label:"Any contact created"},{value:"manual",label:"Manual / enrolled by hand"}],be=[{value:"send_email",label:"Send branded email"},{value:"notify_team",label:"Notify team by email"},{value:"enrich",label:"Enrich"},{value:"add_tag",label:"Add a tag"},{value:"wait",label:"Wait (delay)"},{value:"webhook",label:"Call webhook (POST)"}],ye=[{value:"contact_thanks",label:"Contact thank-you"},{value:"pdf_thanks",label:"PDF download thank-you"},{value:"newsletter_welcome",label:"Newsletter welcome"},{value:"team_alert",label:"Team alert"}];function ze(){const{siteId:r,scopeLabel:q,siteName:B}=pe(),[f,E]=a.useState([]),P=me(f,{defaultSize:25}),[V,W]=a.useState([]),[D,o]=a.useState(!1),[u,I]=a.useState(null),[p,j]=a.useState(""),[v,N]=a.useState(""),[b,y]=a.useState("contact_form"),[d,_]=a.useState("all"),[S,w]=a.useState([{type:"send_email",template:"contact_thanks"}]),[z,x]=a.useState(null),[G,A]=a.useState(0),[K,M]=a.useState({}),C=async()=>{let s=l.from("automations").select("*").order("updated_at",{ascending:!1});r&&(s=s.eq("site_id",r));const[{data:t},{data:c},{data:J}]=await Promise.all([s,l.from("sites").select("id, name").order("name"),l.from("automation_runs").select("automation_id, status").limit(1e3)]);E(t??[]),W(c??[]);const L={};for(const n of J??[]){const k=L[n.automation_id]||={pending:0,completed:0,failed:0};n.status==="pending"||n.status==="running"?k.pending++:n.status==="completed"?k.completed++:(n.status==="failed"||n.status==="cancelled")&&k.failed++}M(L)};a.useEffect(()=>{C()},[r]);const g=()=>{I(null),j(""),N(""),y("contact_form"),_(r??"all"),w([{type:"send_email",template:"contact_thanks"}]),x(null),A(s=>s+1)},Y=()=>{g(),o(!0)},Z=s=>{I(s.id),j(s.name),N(s.description??""),y(s.trigger?.type??"manual"),_(s.site_id??"all"),w(s.steps??[{type:"send_email",template:"contact_thanks"}]),x(null),A(t=>t+1),o(!0)},H=async()=>{if(!p.trim())return i.error("Name required");if(z)return i.error(z);if(u){const{error:s}=await l.from("automations").update({name:p,description:v||null,site_id:d==="all"?null:d,trigger:{type:b},steps:S}).eq("id",u);if(s)return i.error(s.message);i.success("Automation updated")}else{const{error:s}=await l.from("automations").insert({name:p,description:v||null,status:"draft",site_id:d==="all"?null:d,trigger:{type:b},steps:S});if(s)return i.error(s.message);i.success("Automation created")}o(!1),g(),C()},U=async s=>{const t=s.status==="active"?"paused":"active";await l.from("automations").update({status:t}).eq("id",s.id),E(f.map(c=>c.id===s.id?{...c,status:t}:c))},X=async s=>{await l.from("automations").delete().eq("id",s),i.success("Deleted"),C()};return e.jsxs("div",{className:"page-shell editorial-page space-y-8",children:[e.jsxs("div",{className:"flex items-end justify-between",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"font-display text-2xl font-bold",children:"Automations"}),e.jsxs("p",{className:"text-sm text-muted-foreground",children:["Trigger-based workflows that nurture leads on autopilot. ",e.jsxs("span",{className:"text-foreground",children:["Scope: ",q,"."]})]})]}),e.jsxs(Q,{open:D,onOpenChange:s=>{s||g(),o(s)},children:[e.jsx($,{asChild:!0,children:e.jsxs(m,{onClick:Y,children:[e.jsx(xe,{className:"size-4 mr-1.5"})," New automation"]})}),e.jsxs(ee,{className:"max-h-[95vh] max-w-6xl overflow-y-auto",children:[e.jsx(se,{children:e.jsx(te,{children:u?"Edit automation":"New automation"})}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"grid grid-cols-3 gap-3",children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(T,{children:"Name"}),e.jsx(F,{value:p,onChange:s=>j(s.target.value),placeholder:"Welcome new leads"})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(T,{children:"Description"}
2),e.jsx(F,{value:v,onChange:s=>N(s.target.value)})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(T,{children:"For site"}),e.jsxs(ae,{value:d,onValueChange:_,children:[e.jsx(le,{children:e.jsx(ie,{})}),e.jsxs(ne,{children:[e.jsx(O,{value:"all",children:"All sites"}),V.map(s=>e.jsx(O,{value:s.id,children:s.name},s.id))]})]})]})]}),e.jsx(re,{fallback:e.jsx("div",{className:"h-[520px] rounded-lg border border-border"}),children:e.jsx(a.Suspense,{fallback:e.jsx("div",{className:"grid h-[520px] place-items-center rounded-lg border border-border text-sm text-muted-foreground",children:"Loading canvas…"}),children:D&&e.jsx(ve,{trigger:b,steps:S,triggers:Ne,stepTypes:be,templates:ye,onChange:s=>{"error"in s?x(s.error):(x(null),y(s.trigger),w(s.steps))}},G)})})]}),e.jsxs(oe,{children:[e.jsx(m,{variant:"outline",onClick:()=>{o(!1),g()},children:"Cancel"}),e.jsx(m,{onClick:H,children:u?"Save changes":"Create automation"})]})]})]})]}),e.jsx(ue,{...P,label:"automations",sizes:[25,50,100]}),e.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-2 gap-4",children:[P.visible.map(s=>e.jsxs(R,{className:"p-5 group relative",children:[e.jsxs("div",{className:"flex items-start justify-between",children:[e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx("div",{className:"size-10 rounded-lg bg-secondary text-primary grid place-items-center",children:e.jsx(ge,{className:"size-5"})}),e.jsxs("div",{children:[e.jsx("h3",{className:"font-display font-semibold",children:s.name}),e.jsx("p",{className:"text-xs text-muted-foreground mt-0.5",children:s.description})]})]}),e.jsx(de,{checked:s.status==="active",onCheckedChange:()=>U(s)})]}),e.jsxs("div",{className:"flex items-center gap-2 mt-4 flex-wrap",children:[e.jsx(h,{variant:"outline",className:"capitalize",children:s.trigger?.type??"manual"}),e.jsx(he,{className:"size-3 text-muted-foreground"}),e.jsxs(h,{variant:"outline",children:[(s.steps??[]).length," steps"]}),e.jsxs(h,{variant:"outline",children:[s.enrolled_count," enrolled"]}),!r&&e.jsx(h,{variant:"secondary",className:"ml-auto",children:s.site_id?B(s.site_id):"All sites"})]}),(()=>{const t=K[s.id];return!t||t.pending+t.completed+t.failed===0?null:e.jsxs("div",{className:"flex items-center gap-3 mt-3 text-xs text-muted-foreground",children:[e.jsx("span",{children:"Runs:"}),e.jsxs("span",{className:"text-foreground",children:[t.completed," completed"]}),t.pending>0&&e.jsxs("span",{className:"text-amber-600",children:[t.pending," in progress"]}),t.failed>0&&e.jsxs("span",{className:"text-destructive",children:[t.failed," failed"]})]})})(),e.jsxs("div",{className:"flex items-center gap-2 mt-4 pt-3 border-t justify-end",children:[e.jsxs(m,{variant:"ghost",size:"sm",className:"h-8 gap-1",onClick:()=>Z(s),children:[e.jsx(fe,{className:"size-4"})," Edit"]}),e.jsxs(m,{variant:"ghost",size:"sm",className:"h-8 gap-1 text-destructive hover:text-destructive",onClick:()=>X(s.id),children:[e.jsx(je,{className:"size-4"})," Delete"]})]})]},s.id)),f.length===0&&e.jsx(R,{className:"p-8 text-center border-dashed text-sm text-muted-foreground col-span-full",children:"No automations yet."})]})]})}export{ze 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.