PageSourceSearch

https://smartcontractauditor.ai/assets/organizations-C1gpXYMw.js

js smartcontractauditor.ai collected 2026-10-05 12:56:46 UTC 36,766 bytes, 4 lines download raw bytes

1import{aL as pe,u as K,at as ue,r as o,af as V,v as D,j as e,h as T,i as z,S as je,ay as ge,B as h,D as ee,ar as be,b as se,d as te,e as ae,f as ie,an as A,ao as M,aq as W,F as ne,as as X,l as k,a_ as F,z as E,E as j,w as G,x as re,Y as U,G as ce,I as de,J as oe,K as me,N as Q}from"./index-DJZuVyTC.js";import{I as w}from"./input-CmCeL_gc.js";import{T as Ne,a as ve,b as le,c as q,d as we,e as L}from"./table-Drs4LVf9.js";import{a as Se}from"./schema-uUnflNeH.js";import{A as ye}from"./arrow-left-T0E6zDbk.js";import{B as Y}from"./building-2-CShOG1wv.js";import{P as fe}from"./plus-DVBQe1Xd.js";import{D as xe}from"./dollar-sign-Q-qw2plD.js";import{U as Ce}from"./users-CFNFzAWS.js";import{E as Ee}from"./eye-4sB3_9V3.js";import{T as Pe}from"./trash-2-BI1fLPPG.js";import{S as _}from"./send-D_A8EBB5.js";import{S as J}from"./settings-CA3TluAs.js";function Ve(){const{user:s}=pe(),{toast:i}=K(),[,m]=ue(),[c,x]=o.useState(1),[u,S]=o.useState(!1),[p,y]=o.useState(null),[f,g]=o.useState(!1),[r,d]=o.useState("orgs"),{data:n,isLoading:b}=V({queryKey:["/api/admin/organizations",c],enabled:(s==null?void 0:s.role)==="admin"||(s==null?void 0:s.role)==="super_admin",queryFn:async()=>await E("GET",`/api/admin/organizations?page=${c}&limit=50`)}),{data:P,refetch:N}=V({queryKey:["/api/admin/enterprise/leads"],enabled:((s==null?void 0:s.role)==="admin"||(s==null?void 0:s.role)==="super_admin")&&r==="leads",queryFn:async()=>await E("GET","/api/admin/enterprise/leads")}),{data:C,isLoading:a}=V({queryKey:["/api/admin/organizations",p],enabled:!!p&&f,queryFn:async()=>await E("GET",`/api/admin/organizations/${p}`)}),l=D({mutationFn:async t=>await E("POST","/api/admin/organizations",t),onSuccess:()=>{F.invalidateQueries({queryKey:["/api/admin/organizations"]}),S(!1),i({title:"Organization created",description:"Enterprise organization has been created successfully."})},onError:t=>{i({title:"Error creating organization",description:t.message||"Failed to create organization",variant:"destructive"})}}),O=D({mutationFn:async({id:t,data:$})=>await E("PATCH",`/api/admin/organizations/${t}`,$),onSuccess:()=>{F.invalidateQueries({queryKey:["/api/admin/organizations"]}),i({title:"Organization updated",description:"Organization has been updated successfully."})},onError:t=>{i({title:"Error updating organization",description:t.message||"Failed to update organization",variant:"destructive"})}}),v=D({mutationFn:async t=>await E("DELETE",`/api/admin/organizations/${t}`),onSuccess:()=>{F.invalidateQueries({queryKey:["/api/admin/organizations"]}),i({title:"Organization deleted",description:"Organization has been deleted successfully."})},onError:t=>{i({title:"Error deleting organization",description:t.message||"Failed to delete organization",variant:"destructive"})}}),R=D({mutationFn:async t=>await E("POST",`/api/admin/organizations/${t}/subscription`),onSuccess:()=>{F.invalidateQueries({queryKey:["/api/admin/organizations"]}),i({title:"Subscription created",description:"Enterprise subscription has been created successfully."})},onError:t=>{i({title:"Error creating subscription",description:t.message||"Failed to create subscription",variant:"destructive"})}}),B=D({mutationFn:async t=>await E("DELETE",`/api/admin/organizations/${t}/subscription`),onSuccess:()=>{F.invalidateQueries({queryKey:["/api/admin/organizations"]}),i({title:"Subscription cancelled",description:"Subscription will be cancelled at period end."})},onError:t=>{i({title:"Error cancelling subscription",description:t.message||"Failed to cancel subscription",variant:"destructive"})}}),Z=D({mutationFn:async({id:t,seatCount:$})=>await E("PATCH",`/api/admin/organizations/${t}/seats`,{seatCount:$}),onSuccess:()=>{F.invalidateQueries({queryKey:["/api/admin/organizations"]}),i({title:"Seats updated",description:"Organization seat count and Stripe subscription have been updated."})},onError:t=>{i({title:"Error updating seats",description:t.message||"Failed to update seats",variant:"destructive"})}});if((s==null?void 0:s.role)!=="admin"&&(s==null?void 0:s.role)!=="super_admin")return e.jsx("div",{className:"container py-8",children:e.jsx(T,{className:"glass-card border-white/10",children:e.jsx(z,{className:"pt-6",children:e.jsx("p",{className:"text-center text-slate-400",children:"Platform admin access required"})})})});const H=(n==null?void 0:n.organizations)||[],I=(n==null?void 0:n.pagination)||{page:1,total:0,totalPages:0};return e.jsx("div",{className:"min-h-screen bg-[#0a0b14]",children:e.jsxs("div",{className:"container py-8 space-y-6",children:[e.jsxs("div",{className:"flex items-center gap-2 text-sm text-slate-400",children:[e.jsxs("button",{onClick:()=>m("/admin"),className:"flex items-center gap-1 hover:text-white transition-colors","data-testid":"breadcrumb-admin",children:[e.jsx(je,{className:"w-4 h-4"}),"Admin Portal"]}),e.jsx(ge,{className:"w-4 h-4"}),e.jsx("span",{className:"text-white",children:"Organizations"})]}),e.jsxs("div",{className:"flex flex-col sm:flex-row sm:items-center sm:justify-between gap-4",children:[e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsxs(h,{variant:"ghost",size:"sm",onClick:()=>m("/admin"),className:"text-slate-400 hover:text-white hover:bg-white/5","data-testid":"button-back-admin",children:[e.jsx(ye,{className:"w-4 h-4 mr-2"}),"Back"]}),e.jsxs("div",{children:[e.jsxs("h1",{className:"text-3xl font-bold text-white flex items-center gap-3",children:[e.jsx(Y,{className:"h-8 w-8 text-primary"}),"Enterprise Organizations"]}),e.jsx("p",{className:"text-slate-400 mt-2",children:"Manage enterprise accounts, pricing, and team members"})]})]}),e.jsxs(ee,{open:u,onOpenChange:S,children:[e.jsx(be,{asChild:!0,children:e.jsxs(h,{className:"gap-2","data-testid":"button-create-org",children:[e.jsx(fe,{className:"h-4 w-4"}),"Create Organization"]})}),e.jsxs(se,{className:"max-w-2xl glass-card border-white/10",children:[e.jsxs(te,{children:[e.jsx(ae,{className:"text-white",children:"Create Enterprise Organization"}),e.jsx(ie,{className:"text-slate-400",children:"Set up a new enterprise account with custom pricing"})]}),e.jsx(Oe,{onSubmit:t=>l.mutate(t),isLoading:l.isPending})]})]})]}),e.jsxs("div",{className:"grid gap-4 md:grid-cols-3",children:[e.jsxs(T,{className:"glass-card border-white/10",children:[e.jsxs(A,{className:"flex flex-row items-center justify-between space-y-0 pb-2",children:[e.jsx(M,{className:"text-sm font-medium text-slate-300",children:"Total Organizations"}),e.jsx(Y,{className:"h-4 w-4 text-primary"})]}),e.jsx(z,{children:e.jsx("div",{className:"text-2xl font-bold text-white","data-testid":"text-total-orgs",children:I.total})})]}),e.jsxs(T,{className:"glass-card border-white/10",children:[e.jsxs(A,{className:"flex flex-row items-center justify-between space-y-0 pb-2",children:[e.jsx(M,{className:"text-sm font-medium text-slate-300",children:"Active Subscriptions"}),e.jsx(xe,{className:"h-4 w-4 text-green-400"})]}),e.jsx(z,{children:e.jsx("div",{className:"text-2xl font-bold text-white","data-testid":"text-active-subs",children:H.filter(t=>t.subscriptionStatus==="active").length})})]}),e.jsxs(T,{className:"glass-card border-white/10",children:[e.jsxs(A,{className:"flex flex-row items-center justify-between space-y-0 pb-2",children:[e.jsx(M,{className:"text-sm font-medium text-slate-300",children:"Total Seats"}),e.jsx(Ce,{className:"h-4 w-4 text-blue-400"})]}),e.jsx(z,{children:e.jsx("div",{className:"text-2xl font-bold text-white","data-testid":"text-total-seats",children:H.reduce((t,$)=>t+($.totalSeats||0),0)})})]})]}),e.jsx("div",{className:"overflow-x-auto border-b border-white/10",children:e.jsx("div",{className:"flex gap-2 pb-0 min-w-max",children:[["orgs",Y,"Organizations"],["leads",W,"Leads & Messages"],["quote",ne,"Send Quote"]].map(([t,$,he])=>e.jsxs("button",{onClick:()=>d(t),className:`flex items-center gap-2 px-4 py-2.5 text-sm font-medium border-b-2 transition-colors ${r===t?"border-emerald-400 text-emerald-400":"border-transparent text-slate-400 hover:text-white"}`,children:[e.jsx($,{className:"w-4 h-4"}),he]},t))})}),r==="leads"&&e.jsx(Fe,{leads:P||[],onRefetch:N}),r==="quote"&&e.jsx(Te,{}),r==="orgs"&&e.jsxs(T,{className:"glass-card border-white/10",children:[e.jsxs(A,{children:[e.jsx(M,{className:"text-white",children:"Organizations"}),e.jsx(X,{className:"text-slate-400",children:"All enterprise organizations and their status"})]}),e.jsx(z,{children:b?e.jsx("div",{className:"text-center py-8 text-slate-400",children:"Loading organizations..."}):H.length===0?e.jsx("div",{className:"text-center py-8 text-slate-400",children:"No organizations yet"}):e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"overflow-x-auto",children:e.jsxs(Ne,{children:[e.jsx(ve,{children:e.jsxs(le,{className:"border-white/10 hover:bg-white/5",children:[e.jsx(q,{className:"text-slate-300",children:"Organization"}),e.jsx(q,{className:"text-slate-300",children:"Pricing"}),e.jsx(q,{className:"text-slate-300",children:"Seats"}),e.jsx(q,{className:"text-slate-300",children:"Status"}),e.jsx(q,{className:"text-slate-300",children:"Created"}),e.jsx(q,{className:"text-slate-300 text-right",children:"Actions"})]})}),e.jsx(we,{children:H.map(t=>e.jsxs(le,{className:"border-white/10 hover:bg-white/5","data-testid":`row-org-${t.id}`,children:[e.jsx(L,{children:e.jsxs("div",{children:[e.jsx("div",{className:"font-medium text-white",children:t.name}),e.jsxs("div",{className:"text-sm text-slate-400",children:[t.id.slice(0,8),"..."]})]})}),e.jsx(L,{children:e.jsxs("div",{className:"text-sm text-slate-300",children:[e.jsxs("div",{children:["$",t.basePrice," base"]}),e.jsxs("div",{className:"text-slate-400",children:["$",t.perSeatPrice,"/seat"]})]})}),e.jsx(L,{children:e.jsxs("div",{className:"text-sm text-slate-300",children:[t.totalSeats," total",e.jsxs("span",{className:"text-slate-400 ml-1",children:["(",t.includedSeats," inc.)"]})]})}),e.jsx(L,{children:e.jsx(k,{variant:t.subscriptionStatus==="active"?"default":"secondary",className:t.
1subscriptionStatus==="active"?"bg-green-500/20 text-green-300":"",children:t.subscriptionStatus})}),e.jsx(L,{className:"text-slate-400",children:new Date(t.createdAt).toLocaleDateString()}),e.jsx(L,{className:"text-right",children:e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsx(h,{variant:"ghost",size:"sm",onClick:()=>{y(t.id),g(!0)},"data-testid":`button-view-${t.id}`,children:e.jsx(Ee,{className:"h-4 w-4"})}),e.jsx(h,{variant:"ghost",size:"sm",onClick:()=>{confirm("Are you sure you want to delete this organization?")&&v.mutate(t.id)},"data-testid":`button-delete-${t.id}`,children:e.jsx(Pe,{className:"h-4 w-4 text-red-400"})})]})})]},t.id))})]})}),I.totalPages>1&&e.jsxs("div",{className:"flex items-center justify-between mt-4 pt-4 border-t border-white/10",children:[e.jsxs("p",{className:"text-sm text-slate-400",children:["Page ",I.page," of ",I.totalPages]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(h,{variant:"outline",size:"sm",onClick:()=>x(t=>Math.max(1,t-1)),disabled:I.page===1,className:"border-white/10",children:"Previous"}),e.jsx(h,{variant:"outline",size:"sm",onClick:()=>x(t=>t+1),disabled:I.page>=I.totalPages,className:"border-white/10",children:"Next"})]})]})]})})]}),e.jsx(ee,{open:f,onOpenChange:g,children:e.jsxs(se,{className:"max-w-4xl glass-card border-white/10",children:[e.jsxs(te,{children:[e.jsx(ae,{className:"text-white",children:"Organization Details"}),e.jsx(ie,{className:"text-slate-400",children:"View and manage organization settings and members"})]}),a?e.jsx("div",{className:"text-center py-8 text-slate-400",children:"Loading details..."}):C?e.jsx(Ie,{organization:C.organization,members:C.members,onUpdate:t=>O.mutate({id:p,data:t}),isUpdating:O.isPending,onCreateSubscription:()=>R.mutate(p),onCancelSubscription:()=>{confirm("Are you sure you want to cancel this subscription? It will remain active until the end of the billing period.")&&B.mutate(p)},onUpdateSeats:t=>Z.mutate({id:p,seatCount:t}),isCreatingSubscription:R.isPending,isCancellingSubscription:B.isPending,isUpdatingSeats:Z.isPending}):null]})})]})})}function Oe({onSubmit:s,isLoading:i}){const{toast:m}=K(),[c,x]=o.useState({name:"",ownerId:"",basePrice:"300.00",perSeatPrice:"40.00",includedSeats:5,totalSeats:5,billingEmail:"",customDiscount:"",notes:""}),[u,S]=o.useState(""),[p,y]=o.useState(null),[f,g]=o.useState(!1),r=async()=>{if(u.trim()){g(!0),y(null);try{const n=await E("GET",`/api/admin/users/by-email?email=${encodeURIComponent(u.trim())}`);y(n),x(b=>({...b,ownerId:n.id}))}catch(n){m({title:"User not found",description:n.message||"No account with that email",variant:"destructive"})}finally{g(!1)}}},d=n=>{if(n.preventDefault(),!c.ownerId){m({title:"Owner required",description:"Look up the owner by email first",variant:"destructive"});return}s(c)};return e.jsxs("form",{onSubmit:d,className:"space-y-4",children:[e.jsxs("div",{className:"grid gap-4 md:grid-cols-2",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(j,{htmlFor:"name",className:"text-slate-300",children:"Organization Name *"}),e.jsx(w,{id:"name",value:c.name,onChange:n=>x({...c,name:n.target.value}),required:!0,className:"bg-slate-800/50 border-white/10 text-white","data-testid":"input-org-name"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(j,{className:"text-slate-300",children:"Owner Email *"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(w,{type:"email",value:u,onChange:n=>{S(n.target.value),y(null),x(b=>({...b,ownerId:""}))},className:"bg-slate-800/50 border-white/10 text-white",placeholder:"[email protected]","data-testid":"input-owner-email"}),e.jsx(h,{type:"button",variant:"outline",size:"sm",onClick:r,disabled:f||!u.trim(),className:"border-white/10 shrink-0",children:f?e.jsx(G,{className:"w-4 h-4 animate-spin"}):"Find"})]}),p&&e.jsxs("div",{className:"flex items-center gap-2 text-sm text-emerald-400 bg-emerald-500/10 border border-emerald-500/20 rounded-lg px-3 py-2",children:[e.jsx(re,{className:"w-4 h-4 shrink-0"}),e.jsxs("span",{children:[p.name," · ",p.email]})]})]})]}),e.jsxs("div",{className:"grid gap-4 md:grid-cols-3",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(j,{htmlFor:"basePrice",className:"text-slate-300",children:"Base Price ($/month)"}),e.jsx(w,{id:"basePrice",type:"text",value:c.basePrice,onChange:n=>x({...c,basePrice:n.target.value}),className:"bg-slate-800/50 border-white/10 text-white","data-testid":"input-base-price"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(j,{htmlFor:"perSeatPrice",className:"text-slate-300",children:"Per Seat Price ($/month)"}),e.jsx(w,{id:"perSeatPrice",type:"text",value:c.perSeatPrice,onChange:n=>x({...c,perSeatPrice:n.target.value}),className:"bg-slate-800/50 border-white/10 text-white","data-testid":"input-seat-price"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(j,{htmlFor:"includedSeats",className:"text-slate-300",children:"Included Seats"}),e.jsx(w,{id:"includedSeats",type:"number",min:"1",value:c.includedSeats,onChange:n=>x({...c,includedSeats:parseInt(n.target.value)}),className:"bg-slate-800/50 border-white/10 text-white","data-testid":"input-included-seats"})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(j,{htmlFor:"billingEmail",className:"text-slate-300",children:"Billing Email"}),e.jsx(w,{id:"billingEmail",type:"email",value:c.billingEmail,onChange:n=>x({...c,billingEmail:n.target.value}),className:"bg-slate-800/50 border-white/10 text-white","data-testid":"input-billing-email"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(j,{htmlFor:"notes",className:"text-slate-300",children:"Notes"}),e.jsx(U,{id:"notes",value:c.notes,onChange:n=>x({...c,notes:n.target.value}),className:"bg-slate-800/50 border-white/10 text-white resize-none",rows:3,"data-testid":"input-notes"})]}),e.jsx("div",{className:"flex justify-end gap-3 pt-4",children:e.jsx(h,{type:"submit",disabled:i,"data-testid":"button-submit-org",children:i?"Creating...":"Create Organization"})})]})}function Ie({organization:s,members:i,onUpdate:m,isUpdating:c,onCreateSubscription:x,onCancelSubscription:u,onUpdateSeats:S,isCreatingSubscription:p,isCancellingSubscription:y,isUpdatingSeats:f}){const[g,r]=o.useState(!1),[d,n]=o.useState(!1),[b,P]=o.useState(s.totalSeats),[N,C]=o.useState({name:s.name,basePrice:s.basePrice,perSeatPrice:s.perSeatPrice,totalSeats:s.totalSeats,billingEmail:s.billingEmail||"",customDiscount:s.customDiscount||"",notes:s.notes||"",subscriptionStatus:s.subscriptionStatus}),a=()=>{m(N),r(!1)};return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("h3",{className:"text-lg font-semibold text-white",children:"Organization Information"}),e.jsxs(h,{variant:"outline",size:"sm",onClick:()=>r(!g),className:"border-white/10","data-testid":"button-toggle-edit",children:[e.jsx(J,{className:"h-4 w-4 mr-2"}),g?"Cancel":"Edit"]})]}),g?e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"grid gap-3 md:grid-cols-2",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx(j,{className:"text-slate-300 text-sm",children:"Name"}),e.jsx(w,{value:N.name,onChange:l=>C({...N,name:l.target.value}),className:"bg-slate-800/50 border-white/10 text-white"})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(j,{className:"text-slate-300 text-sm",children:"Status"}),e.jsxs(ce,{value:N.subscriptionStatus,onValueChange:l=>C({...N,subscriptionStatus:l}),children:[e.jsx(de,{className:"bg-slate-800/50 border-white/10 text-white",children:e.jsx(oe,{})}),e.jsxs(me,{className:"bg-slate-900 border-white/10",children:[e.jsx(Q,{value:"active",children:"Active"}),e.jsx(Q,{value:"inactive",children:"Inactive"}),e.jsx(Q,{value:"canceled",children:"Canceled"}),e.jsx(Q,{value:"pending",children:"Pending"})]})]})]})]}),e.jsxs("div",{className:"grid gap-3 md:grid-cols-3",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx(j,{className:"text-slate-300 text-sm",children:"Base Price"}),e.jsx(w,{value:N.basePrice,onChange:l=>C({...N,basePrice:l.target.value}),className:"bg-slate-800/50 border-white/10 text-white"})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(j,{className:"text-slate-300 text-sm",children:"Per Seat Price"}),e.jsx(w,{value:N.perSeatPrice,onChange:l=>C({...N,perSeatPrice:l.target.value}),className:"bg-slate-800/50 border-white/10 text-white"})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(j,{className:"text-slate-300 text-sm",children:"Total Seats"}),e.jsx(w,{type:"number",value:N.totalSeats,onChange:l=>C({...N,totalSeats:parseInt(l.target.value)}),className:"bg-slate-800/50 border-white/10 text-white"})]})]}
1),e.jsx(h,{onClick:a,disabled:c,className:"w-full","data-testid":"button-save-org",children:c?"Saving...":"Save Changes"})]}):e.jsxs("div",{className:"grid gap-4 md:grid-cols-2",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-sm text-slate-400",children:"Name"}),e.jsx("p",{className:"text-white font-medium",children:s.name})]}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm text-slate-400",children:"Status"}),e.jsx(k,{variant:s.subscriptionStatus==="active"?"default":"secondary",children:s.subscriptionStatus})]}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm text-slate-400",children:"Base Price"}),e.jsxs("p",{className:"text-white font-medium",children:["$",s.basePrice,"/month"]})]}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm text-slate-400",children:"Per Seat Price"}),e.jsxs("p",{className:"text-white font-medium",children:["$",s.perSeatPrice,"/seat/month"]})]}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm text-slate-400",children:"Seats"}),e.jsxs("p",{className:"text-white font-medium",children:[s.totalSeats," total (",s.includedSeats," included)"]})]}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm text-slate-400",children:"Created"}),e.jsx("p",{className:"text-white font-medium",children:new Date(s.createdAt).toLocaleString()})]})]})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsx("div",{className:"flex items-center justify-between",children:e.jsx("h3",{className:"text-lg font-semibold text-white",children:"Stripe Subscription"})}),e.jsxs("div",{className:"p-4 rounded-lg bg-white/5 border border-white/10 space-y-3",children:[e.jsxs("div",{className:"grid gap-4 md:grid-cols-2",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-sm text-slate-400",children:"Subscription Status"}),e.jsx(k,{variant:s.stripeSubscriptionId?"default":"secondary",className:"mt-1",children:s.stripeSubscriptionId?"Active":"Not Created"})]}),s.stripeCustomerId&&e.jsxs("div",{children:[e.jsx("p",{className:"text-sm text-slate-400",children:"Stripe Customer ID"}),e.jsx("p",{className:"text-white font-mono text-xs mt-1",children:s.stripeCustomerId})]}),s.stripeSubscriptionId&&e.jsxs("div",{className:"md:col-span-2",children:[e.jsx("p",{className:"text-sm text-slate-400",children:"Stripe Subscription ID"}),e.jsx("p",{className:"text-white font-mono text-xs mt-1",children:s.stripeSubscriptionId})]})]}),s.stripeSubscriptionId&&e.jsxs("div",{className:"pt-3 border-t border-white/10 space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium text-white",children:"Seat Management"}),e.jsxs("p",{className:"text-xs text-slate-400",children:["Current: ",s.totalSeats," seats (Base: 5, Additional: ",Math.max(0,s.totalSeats-5),")"]})]}),!d&&e.jsxs(h,{variant:"outline",size:"sm",onClick:()=>{n(!0),P(s.totalSeats)},className:"border-white/20","data-testid":"button-adjust-seats",children:[e.jsx(J,{className:"h-4 w-4 mr-2"}),"Adjust Seats"]})]}),d&&e.jsxs("div",{className:"flex items-end gap-3",children:[e.jsxs("div",{className:"flex-1 space-y-1",children:[e.jsx(j,{className:"text-slate-300 text-sm",children:"New Seat Count"}),e.jsx(w,{type:"number",min:"1",value:b,onChange:l=>P(parseInt(l.target.value)||1),className:"bg-slate-800/50 border-white/10 text-white","data-testid":"input-seat-count"}),e.jsxs("p",{className:"text-xs text-slate-400",children:["$",s.basePrice," base + $",s.perSeatPrice," × ",Math.max(0,b-5)," = $",parseFloat(s.basePrice)+parseFloat(s.perSeatPrice)*Math.max(0,b-5),"/mo"]})]}),e.jsx(h,{onClick:()=>{S(b),n(!1)},disabled:f||b===s.totalSeats,"data-testid":"button-save-seats",children:f?"Updating...":"Update Seats"}),e.jsx(h,{variant:"ghost",onClick:()=>n(!1),disabled:f,children:"Cancel"})]})]}),e.jsx("div",{className:"flex gap-2 pt-2",children:s.stripeSubscriptionId?e.jsx(h,{onClick:u,disabled:y||s.subscriptionStatus==="cancelled",variant:"destructive","data-testid":"button-cancel-subscription",children:y?"Cancelling...":"Cancel Subscription"}):e.jsxs(h,{onClick:x,disabled:p,className:"bg-primary hover:bg-primary/90","data-testid":"button-create-subscription",children:[e.jsx(xe,{className:"h-4 w-4 mr-2"}),p?"Creating...":"Create Stripe Subscription"]})}),!s.stripeSubscriptionId&&e.jsxs("p",{className:"text-xs text-slate-400",children:["Creates a Stripe subscription with $",s.basePrice,"/month base price + $",s.perSeatPrice,"/seat for ",s.totalSeats," seats."]})]})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("h3",{className:"text-lg font-semibold text-white",children:["Team Members (",i.length,")"]}),e.jsx("div",{className:"space-y-2",children:i.map(l=>{var O,v,R,B;return e.jsxs("div",{className:"flex items-center justify-between p-3 rounded-lg bg-white/5 border border-white/10","data-testid":`member-${l.userId}`,children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-white font-medium",children:(O=l.user)!=null&&O.name||l.userId.startsWith("pending_")?((v=l.user)==null?void 0:v.name)||"(pending invite)":((R=l.user)==null?void 0:R.name)||"Unknown"}),e.jsx("p",{className:"text-sm text-slate-400",children:((B=l.user)==null?void 0:B.email)||"—"})]}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(k,{variant:"outline",className:"border-white/20",children:l.role}),e.jsx(k,{className:l.status==="active"?"bg-emerald-500/20 text-emerald-300 border-0":"bg-amber-500/20 text-amber-300 border-0",children:l.status})]})]},l.id)})}),e.jsx(ze,{orgId:s.id,orgName:s.name})]})]})}const $e={new:"bg-blue-500/20 text-blue-300",contacted:"bg-amber-500/20 text-amber-300",quoted:"bg-purple-500/20 text-purple-300",won:"bg-emerald-500/20 text-emerald-300",lost:"bg-red-500/20 text-red-300"};function De(s){const i=s==null?void 0:s.match(/^\[([^\]]+)\]\s*([\s\S]*)$/);return i&&Se.includes(i[1])?{source:"contact",interest:i[1],message:i[2]}:{source:"pricing",message:s||""}}function Fe({leads:s,onRefetch:i}){const{toast:m}
1=K(),[c,x]=o.useState(null),[u,S]=o.useState(""),[p,y]=o.useState(""),[f,g]=o.useState(null),[r,d]=o.useState(""),[n,b]=o.useState(null),P=D({mutationFn:async({id:a,body:l})=>await E("POST",`/api/admin/enterprise/leads/${a}/reply`,{body:l}),onSuccess:(a,{id:l})=>{const O=s.find(v=>v.id===l);g(null),d(""),b(null),i(),m({title:"Reply sent",description:O?`Emailed to ${O.contactEmail}`:void 0})},onError:a=>b(a.message||"Reply failed to send")}),N=a=>{const l=(a.contactName||"").trim().split(/\s+/)[0];g(a.id),d(l?`Hi ${l},
2
3`:""),b(null),x(null)},C=async a=>{try{await E("PATCH",`/api/admin/enterprise/leads/${a}`,{status:u,notes:p||void 0}),x(null),i(),m({title:"Lead updated"})}catch(l){m({title:"Error",description:l.message,variant:"destructive"})}};return e.jsxs(T,{className:"glass-card border-white/10",children:[e.jsxs(A,{children:[e.jsxs(M,{className:"text-white flex items-center gap-2",children:[e.jsx(W,{className:"w-5 h-5 text-emerald-400"}),"Leads & Messages"]}),e.jsx(X,{className:"text-slate-400",children:`From the contact page and the pricing page's Contact Sales form. Replies go out from "Duron Epps"; their answers land in your inbox.`})]}),e.jsx(z,{children:s.length===0?e.jsx("p",{className:"text-center py-8 text-slate-500",children:"No messages yet. They appear here when someone uses the contact page or the Contact Sales form on the pricing page."}):e.jsx("div",{className:"space-y-3",children:s.map(a=>{const l=De(a.useCase),O=a.replies||[];return e.jsxs("div",{className:"bg-slate-800/40 border border-white/10 rounded-xl p-4 space-y-3","data-testid":`lead-${a.id}`,children:[e.jsxs("div",{className:"flex flex-col sm:flex-row sm:items-start justify-between gap-2 sm:gap-4",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"font-semibold text-white break-words",children:a.companyName}),e.jsxs("p",{className:"text-sm text-slate-400 break-all",children:[a.contactName&&`${a.contactName} · `,e.jsx("a",{href:`mailto:${a.contactEmail}`,className:"text-emerald-400 hover:underline",children:a.contactEmail})]}),a.teamSize&&e.jsxs("p",{className:"text-xs text-slate-500 mt-0.5",children:[a.teamSize," person team"]})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2 shrink-0",children:[e.jsx(k,{className:`${l.source==="contact"?"bg-emerald-500/15 text-emerald-300":"bg-slate-500/20 text-slate-300"} border-0 text-xs`,"data-testid":"lead-source",children:l.source==="contact"?`Contact form · ${l.interest}`:"Pricing"}),e.jsx(k,{className:`${$e[a.status]||""} border-0 text-xs`,"data-testid":"lead-status",children:a.status}),e.jsx("span",{className:"text-xs text-slate-600",children:new Date(a.createdAt).toLocaleDateString()})]})]}),l.message&&e.jsx("p",{className:"text-sm text-slate-300 bg-slate-900/50 rounded-lg px-3 py-2 whitespace-pre-wrap break-words","data-testid":"lead-message",children:l.message}),O.length>0&&e.jsx("div",{className:"space-y-2 pl-3 border-l-2 border-emerald-500/30","data-testid":"lead-replies",children:O.map(v=>e.jsxs("div",{children:[e.jsxs("p",{className:"text-xs text-emerald-400/80 mb-0.5",children:["You replied · ",new Date(v.createdAt).toLocaleString()]}),e.jsx("p",{className:"text-sm text-slate-300 whitespace-pre-wrap break-words",children:v.body})]},v.id))}),f===a.id?e.jsxs("div",{className:"space-y-2 pt-1",children:[e.jsxs("p",{className:"text-xs text-slate-500",children:["To ",a.contactEmail,' · from "Duron Epps" · their reply goes to your inbox']}),e.jsx(U,{value:r,onChange:v=>d(v.target.value),rows:6,autoFocus:!0,className:"bg-slate-800 border-white/10 text-white text-sm","data-testid":"reply-textarea"}),n&&e.jsx("p",{className:"text-sm text-red-400",role:"alert",children:n}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(h,{size:"sm",className:"bg-emerald-500 hover:bg-emerald-400 text-white",disabled:P.isPending||!r.trim(),onClick:()=>P.mutate({id:a.id,body:r}),"data-testid":"reply-send",children:P.isPending?e.jsxs(e.Fragment,{children:[e.jsx(G,{className:"w-3 h-3 mr-1 animate-spin"}),"Sending…"]}):e.jsxs(e.Fragment,{children:[e.jsx(_,{className:"w-3 h-3 mr-1"}),"Send reply"]})}),e.jsx(h,{size:"sm",variant:"ghost",disabled:P.isPending,onClick:()=>{g(null),b(null)},children:"Cancel"})]})]}):c===a.id?e.jsxs("div",{className:"space-y-2 pt-1",children:[e.jsx("div",{className:"flex gap-2",children:e.jsxs(ce,{value:u,onValueChange:S,children:[e.jsx(de,{className:"bg-slate-800 border-white/10 text-white h-8 text-sm",children:e.jsx(oe,{})}),e.jsx(me,{children:["new","contacted","quoted","won","lost"].map(v
3=>e.jsx(Q,{value:v,children:v},v))})]})}),e.jsx(U,{value:p,onChange:v=>y(v.target.value),placeholder:"Notes…",rows:2,className:"bg-slate-800 border-white/10 text-white resize-none text-sm"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(h,{size:"sm",onClick:()=>C(a.id),children:"Save"}),e.jsx(h,{size:"sm",variant:"ghost",onClick:()=>x(null),children:"Cancel"})]})]}):e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsxs(h,{size:"sm",className:"bg-emerald-500/15 hover:bg-emerald-500/25 text-emerald-300 h-7 text-xs",onClick:()=>N(a),"data-testid":"reply-open",children:[e.jsx(_,{className:"w-3 h-3 mr-1"}),"Reply"]}),e.jsxs(h,{size:"sm",variant:"ghost",className:"text-slate-400 h-7 text-xs",onClick:()=>{x(a.id),S(a.status),y(a.notes||""),g(null)},children:[e.jsx(J,{className:"w-3 h-3 mr-1"}),"Update status"]})]}),a.notes&&c!==a.id&&e.jsx("p",{className:"text-xs text-slate-500 italic",children:a.notes})]},a.id)})})})]})}function Te(){const{toast:s}=K(),[i,m]=o.useState({companyName:"",contactName:"",contactEmail:"",seats:5,basePrice:300,perSeatPrice:40,discount:0,notes:"",validDays:30}),[c,x]=o.useState(!1),[u,S]=o.useState(!1),p=Math.max(0,i.seats-5),f=(i.basePrice+p*i.perSeatPrice)*(1-i.discount/100),g=async r=>{r.preventDefault(),x(!0);try{await E("POST","/api/admin/organizations/quote",i),S(!0),s({title:"Quote sent",description:`Email sent to ${i.contactEmail}`})}catch(d){s({title:"Error",description:d.message||"Failed to send quote",variant:"destructive"})}finally{x(!1)}};return e.jsxs(T,{className:"glass-card border-white/10",children:[e.jsxs(A,{children:[e.jsxs(M,{className:"text-white flex items-center gap-2",children:[e.jsx(ne,{className:"w-5 h-5 text-emerald-400"}),"Send Enterprise Quote"]}),e.jsx(X,{className:"text-slate-400",children:"Generate a branded pricing proposal and email it to a prospect"})]}),e.jsx(z,{children:u?e.jsxs("div",{className:"text-center py-8",children:[e.jsx(re,{className:"w-12 h-12 text-emerald-400 mx-auto mb-3"}),e.jsxs("p",{className:"text-white font-semibold mb-1",children:["Quote sent to ",i.contactEmail]}),e.jsx("p",{className:"text-slate-400 text-sm mb-4",children:"They'll receive a branded email with the full pricing breakdown."}),e.jsx(h,{variant:"outline",className:"border-white/10",onClick:()=>{S(!1),m(r=>({...r,contactEmail:"",companyName:"",contactName:""}))},children:"Send another quote"})]}):e.jsxs("form",{onSubmit:g,className:"space-y-4 max-w-2xl",children:[e.jsxs("div",{className:"grid gap-4 md:grid-cols-2",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx(j,{className:"text-slate-300 text-sm",children:"Company Name *"}),e.jsx(w,{required:!0,value:i.companyName,onChange:r=>m(d=>({...d,companyName:r.target.value})),className:"bg-slate-800/50 border-white/10 text-white"})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(j,{className:"text-slate-300 text-sm",children:"Contact Name"}),e.jsx(w,{value:i.contactName,onChange:r=>m(d=>({...d,contactName:r.target.value})),className:"bg-slate-800/50 border-white/10 text-white"})]})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(j,{className:"text-slate-300 text-sm",children:"Contact Email *"}),e.jsx(w,{required:!0,type:"email",value:i.contactEmail,onChange:r=>m(d=>({...d,contactEmail:r.target.value})),className:"bg-slate-800/50 border-white/10 text-white"})]}),e.jsxs("div",{className:"grid gap-4 md:grid-cols-4",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx(j,{className:"text-slate-300 text-sm",children:"Seats"}),e.jsx(w,{type:"number",min:"1",value:i.seats,onChange:r=>m(d=>({...d,seats:parseInt(r.target.value)||5})),className:"bg-slate-800/50 border-white/10 text-white"})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(j,{className:"text-slate-300 text-sm",children:"Base Price ($)"}),e.jsx(w,{type:"number",min:"0",value:i.basePrice,onChange:r=>m(d=>({...d,basePrice:parseFloat(r.target.value)||300})),className:"bg-slate-800/50 border-white/10 text-white"})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(j,{className:"text-slate-300 text-sm",children:"Per Seat ($)"}),e.jsx(w,{type:"number",min:"0",value:i.perSeatPrice,onChange:r=>m(d=>({...d,perSeatPrice:parseFloat(r.target.value)||40})),className:"bg-slate-800/50 border-white/10 text-white"})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(j,{className:"text-slate-300 text-sm",children:"Discount %"}),e.jsx(w,{type:"number",min:"0",max:"100",value:i.discount,onChange:r=>m(d=>({...d,discount:parseFloat(r.target.value)||0})),className:"bg-slate-800/50 border-white/10 text-white"})]})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(j,{className:"text-slate-300 text-sm",children:"Notes (optional)"}),e.jsx(U,{value:i.notes,onChange:r=>m(d=>({...d,notes:r.target.value})),rows:2,className:"bg-slate-800/50 border-white/10 text-white resize-none"})]}),e.jsxs("div",{className:"flex items-center justify-between pt-2",children:[e.jsxs("div",{className:"bg-slate-800/60 rounded-xl px-4 py-2.5",children:[e.jsx("p",{className:"text-xs text-slate-400",children:"Monthly total"}),e.jsxs("p",{className:"text-xl font-bold text-emerald-400",children:["$",f.toFixed(2),e.jsx("span",{className:"text-sm font-normal text-slate-400",children:"/mo"})]}),e.jsxs("p",{className:"text-xs text-slate-500",children:[i.seats," seats · unlimited scans"]})]}
3),e.jsxs(h,{type:"submit",disabled:c,className:"gap-2",children:[c?e.jsx(G,{className:"w-4 h-4 animate-spin"}):e.jsx(_,{className:"w-4 h-4"}),c?"Sending…":"Send Quote Email"]})]})]})})]})}function ze({orgId:s,orgName:i}){var g,r,d;const{toast:m}=K(),[c,x]=o.useState(""),[u,S]=o.useState(null),[p,y]=o.useState(!1),f=async()=>{var b,P,N,C;const n=c.split(/[\n,]+/).map(a=>a.trim()).filter(Boolean);if(n.length){y(!0),S(null);try{const a=await E("POST",`/api/admin/organizations/${s}/invite`,{emails:n});S(a),F.invalidateQueries({queryKey:["/api/admin/organizations",s]}),((b=a.added)!=null&&b.length||(P=a.invited)!=null&&P.length)&&(m({title:"Invitations sent",description:`${((N=a.added)==null?void 0:N.length)||0} added, ${((C=a.invited)==null?void 0:C.length)||0} invited`}),x(""))}catch(a){m({title:"Error",description:a.message||"Failed to send invites",variant:"destructive"})}finally{y(!1)}}};return e.jsxs("div",{className:"border border-white/10 rounded-xl p-4 space-y-3",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(W,{className:"w-4 h-4 text-emerald-400"}),e.jsx("h4",{className:"text-sm font-semibold text-white",children:"Invite Members by Email"})]}),e.jsx(U,{value:c,onChange:n=>x(n.target.value),placeholder:`[email protected]
4[email protected]`,rows:3,className:"bg-slate-800/50 border-white/10 text-white resize-none text-sm"}),e.jsx("p",{className:"text-xs text-slate-500",children:"One email per line or comma-separated. Existing users are added immediately; new emails receive an invite link."}),e.jsxs(h,{size:"sm",onClick:f,disabled:p||!c.trim(),className:"gap-2",children:[p?e.jsx(G,{className:"w-3 h-3 animate-spin"}):e.jsx(_,{className:"w-3 h-3"}),p?"Sending…":"Send Invitations"]}),u&&e.jsxs("div",{className:"text-xs space-y-1",children:[((g=u.added)==null?void 0:g.length)>0&&e.jsxs("p",{className:"text-emerald-400",children:["✓ Added: ",u.added.join(", ")]}),((r=u.invited)==null?void 0:r.length)>0&&e.jsxs("p",{className:"text-amber-400",children:["✉ Invited: ",u.invited.join(", ")]}),((d=u.errors)==null?void 0:d.length)>0&&e.jsxs("p",{className:"text-red-400",children:["✗ Errors: ",u.errors.join(", ")]})]})]})}export{Ve 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.