PageSourceSearch

https://zentrix-insights.lovable.app/assets/CompanyOverviewPage-B-9Af6fK.js

js zentrix-insights.lovable.app collected 2026-10-03 03:48:35 UTC 14,605 bytes, 12 lines download raw bytes

1import{k as P,dE as E,dM as W,r as C,bI as R,s as j,aU as V,j as e,B as Z,aE as ee,cu as se,a8 as te,_ as re,$ as ae,a0 as k,a1 as z,a2 as ie,a3 as _,d as U,x as y,ax as q,ao as le,ap as ne,aq as oe,ar as de,as as ce,d6 as ue,d7 as me,d8 as xe,d9 as fe,C as he,cX as _e,U as B,ay as ge,dN as je,q as pe,az as be,bm as ve,a5 as Ne}from"./index-CY3T9Sg9.js";import{u as we,S as Ce}from"./useSuperAdminAccess-DlMhr8qY.js";import{A as De,a as Se}from"./arrow-up-BKCp-AO1.js";import{A as ye}from"./arrow-up-down-Bzvhig6r.js";import{f as L}from"./formatDistanceToNow-CNysxgw1.js";import"./heart-pulse-B0t0y9r-.js";import"./endOfDay-Ca83mizS.js";/**
2 * @license lucide-react v0.462.0 - ISC
3 *
4 * This source code is licensed under the ISC license.
5 * See the LICENSE file in the root directory of this source tree.
6 */const Me=P("Megaphone",[["path",{d:"m3 11 18-5v12L3 14v-3z",key:"n962bs"}],["path",{d:"M11.6 16.8a3 3 0 1 1-5.8-1.6",key:"1yl0tm"}]]);/**
7 * @license lucide-react v0.462.0 - ISC
8 *
9 * This source code is licensed under the ISC license.
10 * See the LICENSE file in the root directory of this source tree.
11 */const Te=P("Tag",[["path",{d:"M12.586 2.586A2 2 0 0 0 11.172 2H4a2 2 0 0 0-2 2v7.172a2 2 0 0 0 .586 1.414l8.704 8.704a2.426 2.426 0 0 0 3.42 0l6.58-6.58a2.426 2.426 0 0 0 0-3.42z",key:"vktsd0"}],["circle",{cx:"7.5",cy:"7.5",r:".5",fill:"currentColor",key:"kqv944"}]]);function Ae(s,t){const a=E(s),d=E(t),m=H(a,d),n=Math.abs(W(a,d));a.setDate(a.getDate()-m*n);const b=+(H(a,d)===-m),o=m*(n-b);return o===0?0:o}function H(s,t){const a=s.getFullYear()-t.getFullYear()||s.getMonth()-t.getMonth()||s.getDate()-t.getDate()||s.getHours()-t.getHours()||s.getMinutes()-t.getMinutes()||s.getSeconds()-t.getSeconds()||s.getMilliseconds()-t.getMilliseconds();return a<0?-1:a>0?1:a}function G(s){return+E(s)<Date.now()}const ke=()=>{const[s,t]=C.useState(""),a=async()=>{try{const{data:o,error:h}=await j.from("companies").select("*").order("created_at",{ascending:!1});if(h)throw h;const{data:c,error:v}=await j.from("user_company_associations").select("company_id, user_id, role, is_active, profiles(full_name, email)");if(v)throw v;const{data:f,error:N}=await j.from("session_tracking").select("user_id, session_start").order("session_start",{ascending:!1});if(N)throw N;const{data:i,error:u}=await j.from("survey_submissions").select("company_id").not("company_id","is",null);if(u)throw u;const{data:x,error:K}=await j.from("cognitive_submissions").select("company_id").not("company_id","is",null);if(K)throw K;const{data:M,error:$}=await j.from("user_attributions").select("user_id, utm_source, utm_medium, utm_campaign, utm_content, gclid, fbclid, li_fat_id");if($)throw $;const T=new Map;M==null||M.forEach(l=>{T.set(l.user_id,l)});const A=new Map;return f==null||f.forEach(l=>{l.user_id&&!A.has(l.user_id)&&A.set(l.user_id,l.session_start)}),o.map(l=>{const D=(c==null?void 0:c.filter(r=>r.company_id===l.id&&r.is_active))||[],Y=(i==null?void 0:i.filter(r=>r.company_id===l.id))||[],J=(x==null?void 0:x.filter(r=>r.company_id===l.id))||[],Q=D.map(r=>{var O,F;return{user_id:r.user_id,full_name:((O=r.profiles)==null?void 0:O.full_name)||null,email:((F=r.profiles)==null?void 0:F.email)||"",role:r.role,is_active:r.is_active,last_login:A.get(r.user_id)||null}}),S=D.find(r=>r.role==="owner")||D[0];let g="Organic";if(S){const r=T.get(S.user_id);r&&(r.gclid?g="Google Ads":r.fbclid?g="Meta Ads":r.li_fat_id?g="LinkedIn Ads":r.utm_source&&r.utm_source!=="direct"&&(g=r.utm_source,r.utm_medium&&r.utm_medium!=="none"&&(g+=` / ${r.utm_medium}`)))}return{id:l.id,name:l.name,slug:l.slug,domain:l.domain,logo_url:l.logo_url,active:l.active,subscription_tier:l.subscription_tier,stripe_subscription_id:l.stripe_subscription_id,stripe_customer_id:l.stripe_customer_id,trial_ends_at:l.trial_ends_at,has_access:l.has_access,created_at:l.created_at,billing_email:l.billing_email,total_members:D.length,behavioral_count:Y.length,cognitive_count:J.length,members:Q,ad_source:g,utms:S?(()=>{const r=T.get(S.user_id);return r?{utm_source:r.utm_source,utm_medium:r.utm_medium,utm_campaign:r.utm_campaign??null,utm_content:r.utm_content??null,gclid:r.gclid,fbclid:r.fbclid,li_fat_id:r.li_fat_id}:null})():null}})}catch(o){throw console.error("[CompanyOverview] Error:",o),V.error("Failed to load company data"),o}},{data:d=[],isLoading:m,refetch:n}=R({queryKey:["company-overview"],queryFn:a,staleTime:2*60*1e3,refetchOnWindowFocus:!1});return{companies:d.filter(o=>{var c;if(!s)return!0;const h=s.toLowerCase();return o.name.toLowerCase().includes(h)||o.slug.toLowerCase().includes(h)||((c=o.domain)==null?void 0:c.toLowerCase().includes(h))}),isLoading:m,searchTerm:s,setSearchTerm:t,refetch:n}},X=s=>{if(s.stripe_subscription_id)return{label:"Paid",variant:"default",detail:"Subscription active"};if(s.subscription_tier==="trial"||s.trial_ends_at){if(s.trial_ends_at){const t=new Date(s.tri
11al_ends_at);if(G(t))return{label:"Trial Expired",variant:"destructive",detail:`Expired ${L(t)} ago`};const a=Ae(t,new Date);return{label:"Trial",variant:"secondary",detail:`${a} day${a!==1?"s":""} remaining`}}return{label:"Trial",variant:"secondary",detail:"No end date set"}}return{label:"Free",variant:"outline",detail:"Free plan"}},I=s=>s.stripe_subscription_id?3:s.subscription_tier==="trial"||s.trial_ends_at?s.trial_ends_at&&G(new Date(s.trial_ends_at))?0:2:1,w=({label:s,sortKey:t,currentKey:a,currentDir:d,onSort:m})=>{const n=a===t;return e.jsx(z,{className:"cursor-pointer select-none hover:text-foreground transition-colors",onClick:()=>m(t),children:e.jsxs("div",{className:"flex items-center gap-1.5",children:[s,n?d==="asc"?e.jsx(De,{className:"w-3.5 h-3.5"}):e.jsx(Se,{className:"w-3.5 h-3.5"}):e.jsx(ye,{className:"w-3.5 h-3.5 opacity-40"})]})})},Ee=()=>{const{companies:s,isLoading:t,searchTerm:a,setSearchTerm:d,refetch:m}=ke(),[n,b]=C.useState(null),[o,h]=C.useState("created_at"),[c,v]=C.useState("desc"),f=i=>{o===i?v(u=>u==="asc"?"desc":"asc"):(h(i),v(i==="name"?"asc":"desc"))},N=C.useMemo(()=>[...s].sort((i,u)=>{let x=0;switch(o){case"name":x=i.name.localeCompare(u.name);break;case"plan":x=I(i)-I(u);break;case"total_members":x=i.total_members-u.total_members;break;case"created_at":x=new Date(i.created_at).getTime()-new Date(u.created_at).getTime();break;case"ad_source":x=i.ad_source.localeCompare(u.ad_source);break}return c==="asc"?x:-x}),[s,o,c]);return e.jsxs("div",{className:"p-6 space-y-6",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"text-2xl font-bold text-foreground",children:"Company Overview"}),e.jsxs("p",{className:"text-muted-foreground text-sm",children:[s.length," companies"]})]}),e.jsxs(Z,{variant:"outline",size:"sm",onClick:()=>m(),children:[e.jsx(ee,{className:"w-4 h-4 mr-2"}),"Refresh"]})]}),e.jsxs("div",{className:"relative max-w-sm",children:[e.jsx(se,{className:"absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-muted-foreground"}),e.jsx(te,{placeholder:"Search companies...",value:a,onChange:i=>d(i.target.value),className:"pl-9"})]}),t?e.jsx("div",{className:"flex items-center justify-center py-12",children:e.jsx("div",{className:"text-muted-foreground",children:"Loading companies..."})}):e.jsxs(re,{children:[e.jsx(ae,{children:e.jsxs(k,{children:[e.jsx(w,{label:"Company",sortKey:"name",currentKey:o,currentDir:c,onSort:f}),e.jsx(w,{label:"Plan",sortKey:"plan",currentKey:o,currentDir:c,onSort:f}),e.jsx(w,{label:"Members",sortKey:"total_members",currentKey:o,currentDir:c,onSort:f}),e.jsx(w,{label:"Created",sortKey:"created_at",currentKey:o,currentDir:c,onSort:f}),e.jsx(w,{label:"Ad Source",sortKey:"ad_source",currentKey:o,currentDir:c,onSort:f}),e.jsx(z,{className:"text-muted-foreground",children:"UTMs"})]})}),e.jsxs(ie,{children:[N.map(i=>{const u=X(i);return e.jsxs(k,{className:"cursor-pointer",onClick:()=>b(i),children:[e.jsx(_,{children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"w-8 h-8 rounded-md bg-muted flex items-center justify-center",children:i.logo_url?e.jsx("img",{src:i.logo_url,alt:"",className:"w-6 h-6 rounded"}):e.jsx(U,{className:"w-4 h-4 text-muted-foreground"})}),e.jsxs("div",{children:[e.jsx("div",{className:"font-medium text-foreground",children:i.name}),e.jsx("div",{className:"text-xs text-muted-foreground",children:i.slug})]})]})}),e.jsx(_,{children:e.jsxs("div",{className:"space-y-1",children:[e.jsx(y,{variant:u.variant,children:u.label}),e.jsx("div",{className:"text-xs text-muted-foreground",children:u.detail})]})}),e.jsx(_,{className:"text-muted-foreground",children:i.total_members}),e.jsx(_,{className:"text-muted-foreground",children:q(new Date(i.created_at),"MMM d, yyyy")}),e.jsx(_,{children:i.ad_source==="Organic"?e.jsx("span",{className:"text-muted-foreground",children:"—"}):e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx(Me,{className:"w-3.5 h-3.5 text-primary"}),e.jsx("span",{className:"text-foreground font-medium",children:i.ad_source})]})}),e.jsx(_,{children:e.jsx(Le,{utms:i.utms})})]},i.id)}),N.length===0&&e.jsx(k,{children:e.jsx(_,{colSpan:6,className:"text-center text-muted-foreground py-8",children:"No companies found."})})]})]}),e.jsx(le,{open:!!n,onOpenChange:()=>b(null),children:e.jsxs(ne,{className:"max-w-2xl max-h-[85vh] overflow-y-auto",children:[e.jsx(oe,{children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"w-10 h-10 rounded-lg bg-muted flex items-center justify-center",children:n!=null&&n.logo_url?e.jsx("img",{src:n.logo_url,alt:"",className:"w-8 h-8 rounded-md"}):e.jsx(U,{className:"w-5 h-5 text-muted-foreground"})}),e.jsxs("div",{children:[e.jsx(de,{className:"text-xl",children:n==null?void 0:n.name}),e.jsx(ce,{className:"text-sm",children:n==null?void 0:n.slug})]})]})}),n&&e.jsx(Ke,{company:n})]})})]})},Le=({utms:s}
11)=>{if(!s)return e.jsx("span",{className:"text-muted-foreground",children:"—"});const t=[];if(s.utm_source&&t.push(`source: ${s.utm_source}`),s.utm_medium&&t.push(`medium: ${s.utm_medium}`),s.utm_campaign&&t.push(`campaign: ${s.utm_campaign}`),s.utm_content&&t.push(`content: ${s.utm_content}`),s.gclid&&t.push(`gclid: ${s.gclid.slice(0,8)}…`),s.fbclid&&t.push(`fbclid: ${s.fbclid.slice(0,8)}…`),s.li_fat_id&&t.push(`li_fat_id: ${s.li_fat_id.slice(0,8)}…`),t.length===0)return e.jsx("span",{className:"text-muted-foreground",children:"—"});const a=s.utm_source||(s.gclid?"gclid":s.fbclid?"fbclid":"li_fat_id");return e.jsx(ue,{children:e.jsxs(me,{children:[e.jsx(xe,{asChild:!0,children:e.jsxs("div",{className:"flex items-center gap-1.5 cursor-default",children:[e.jsx(Te,{className:"w-3.5 h-3.5 text-muted-foreground"}),e.jsx("span",{className:"text-xs text-foreground truncate max-w-[120px]",children:a})]})}),e.jsx(fe,{side:"left",className:"max-w-xs",children:e.jsx("div",{className:"space-y-1 text-xs",children:t.map((d,m)=>e.jsx("div",{className:"font-mono",children:d},m))})})]})})},p=({icon:s,label:t,value:a,subtext:d})=>e.jsxs("div",{className:"rounded-lg border border-border bg-background p-4 space-y-1",children:[e.jsxs("div",{className:"flex items-center gap-2 text-muted-foreground",children:[e.jsx(s,{className:"w-4 h-4"}),e.jsx("span",{className:"text-xs font-medium",children:t})]}),e.jsx("div",{className:"text-lg font-semibold text-foreground",children:a}),d&&e.jsx("div",{className:"text-xs text-muted-foreground",children:d})]}),Ke=({company:s})=>{const t=X(s);return e.jsxs("div",{className:"space-y-6 pt-2",children:[e.jsxs("div",{className:"grid grid-cols-3 gap-3",children:[e.jsx(p,{icon:s.active?he:_e,label:"Status",value:e.jsx(y,{variant:s.active?"default":"destructive",children:s.active?"Active":"Inactive"})}),e.jsx(p,{icon:B,label:"Members",value:s.total_members}),e.jsx(p,{icon:ge,label:"Created",value:L(new Date(s.created_at),{addSuffix:!0}),subtext:q(new Date(s.created_at),"MMM d, yyyy")}),e.jsx(p,{icon:je,label:"Behavioral",value:s.behavioral_count,subtext:"assessments"}),e.jsx(p,{icon:pe,label:"Cognitive",value:s.cognitive_count,subtext:"assessments"}),e.jsx(p,{icon:be,label:"Domain",value:s.domain||"—"})]}),e.jsxs("div",{className:"rounded-lg border border-border bg-muted/30 p-4 flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(y,{variant:t.variant,className:"text-sm",children:t.label}),e.jsx("span",{className:"text-sm text-muted-foreground",children:t.detail})]}),s.billing_email&&e.jsxs("div",{className:"flex items-center gap-1.5 text-xs text-muted-foreground",children:[e.jsx(ve,{className:"w-3.5 h-3.5"}),s.billing_email]})]}),e.jsxs("div",{children:[e.jsxs("h3",{className:"text-sm font-semibold text-foreground mb-3 flex items-center gap-2",children:[e.jsx(B,{className:"w-4 h-4 text-muted-foreground"}),"Team Members (",s.members.length,")"]}),s.members.length===0?e.jsx("p",{className:"text-sm text-muted-foreground py-4 text-center",children:"No members found."}):e.jsx("div",{className:"rounded-lg border border-border overflow-hidden",children:e.jsxs("table",{className:"w-full text-sm",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"border-b border-border bg-muted/50",children:[e.jsx("th",{className:"text-left px-4 py-2.5 font-medium text-muted-foreground",children:"Name"}),e.jsx("th",{className:"text-left px-4 py-2.5 font-medium text-muted-foreground",children:"Role"}),e.jsx("th",{className:"text-left px-4 py-2.5 font-medium text-muted-foreground",children:"Last Login"})]})}),e.jsx("tbody",{children:s.members.map(a=>e.jsxs("tr",{className:"border-b border-border last:border-0",children:[e.jsx("td",{className:"px-4 py-3",children:e.jsxs("div",{children:[e.jsx("div",{className:"font-medium text-foreground",children:a.full_name||"Unnamed"}),e.jsx("div",{className:"text-xs text-muted-foreground",children:a.email})]})}),e.jsx("td",{className:"px-4 py-3",children:e.jsx(y,{variant:"secondary",className:"text-xs capitalize",children:a.role||"member"})}),e.jsx("td",{className:"px-4 py-3 text-muted-foreground text-xs",children:a.last_login?L(new Date(a.last_login),{addSuffix:!0}):"Never"})]}
11,a.user_id))})]})})]})]})},Pe=()=>{const{isAuthorized:s,isLoading:t}=we("viewer");return t?e.jsx("div",{className:"flex items-center justify-center h-screen",children:e.jsx("div",{className:"text-muted-foreground",children:"Checking permissions..."})}):s?e.jsx(Ne,{children:e.jsxs("div",{className:"flex flex-col h-full",children:[e.jsx(Ce,{}),e.jsx("div",{className:"flex-1 overflow-auto",children:e.jsx(Ee,{})})]})}):null};export{Pe as default};
12//# sourceMappingURL=CompanyOverviewPage-B-9Af6fK.js.map

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.