PageSourceSearch

https://greenlight-gcm.lovable.app/assets/FacilityChatsPage.BaLbP8_I.js

js greenlight-gcm.lovable.app collected 2026-10-03 03:28:52 UTC 11,079 bytes, 1 lines download raw bytes

1import{r as c,v as W,j as e}from"./vendor-react.BsJ9eaQA.js";import{ac as Z,a as G,s as y,t as N,P as J,C as K,e as Q,f as X,j as Y,B as ee,h as se,z as _}from"./index.B_dQ8nW1.js";import{T as ae,a as te,b as R,c as d,d as re,e as m}from"./table.BwkXE4Ao.js";import{B as j}from"./badge.DxTJnYb5.js";import{C as g}from"./checkbox.Cic20IWC.js";import{A as ie,a as le,b as ne,c as oe,d as ce,e as de,f as me,g as xe}from"./alert-dialog.BKj8TWen.js";import{S as he,a as ue,b as pe,c as fe,d as h}from"./select.BM50gTi0.js";import{M as je}from"./message-square.DEC39Y37.js";import{T as ge}from"./trash-2.BjyfEkNS.js";import{A as k}from"./audio-waveform.DZcx372Y.js";import{T as w}from"./type.DgwwsWXl.js";import{U as C}from"./users.BRv1QrID.js";import{S as be}from"./settings.DAmJ3cj7.js";import{C as ve}from"./chevron-right.C7hG-Qsm.js";import"./vendor-supabase.rDbyZezT.js";import"./vendor-ui.BMOhr5L7.js";import"./minus.jXRz70Gs.js";import"./check.BuxoXE3q.js";import"./chevron-down.Bg3v1ybW.js";import"./chevron-up.VFwp5Ip9.js";const Oe=()=>{const[o,E]=c.useState([]),[I,S]=c.useState(!0),[l,u]=c.useState(new Set),[p,A]=c.useState(!1),[q,b]=c.useState(!1),[x,B]=c.useState("all"),O=W(),{facility:v,facilityId:f,slug:P,isLoading:V}=Z(),{isSuperAdmin:D}=G();c.useEffect(()=>{f&&T()},[f,x]);const T=async()=>{if(f)try{S(!0);let s=y.from("chat_transcripts").select("id, user_id, user_name, conversation_date, summary, duration_seconds, evaluation_score, created_at, booking_metadata, model_used, is_test, transcript, conversation_type, ip_city, ip_country").eq("facility_id",f).or("is_test.is.null,is_test.eq.fal
1se");x==="realtime"?s=s.ilike("model_used","%realtime%"):x==="text"?s=s.not("model_used","ilike","%realtime%").not("model_used","ilike","%rally%"):x==="rally"?s=s.ilike("model_used","%rally%"):x==="setup_intake"?s=s.eq("conversation_type","setup_intake"):D||(s=s.or("conversation_type.is.null,conversation_type.neq.setup_intake"));const{data:a,error:t}=await s.order("conversation_date",{ascending:!1}).limit(200);if(t)throw t;const r=(a||[]).filter(i=>(Array.isArray(i.transcript)?i.transcript:[]).length>0);E(r)}catch(s){console.error("Error fetching chats:",s),N.error("Failed to load chat transcripts")}finally{S(!1)}},z=s=>{if(!s)return"N/A";const a=Math.floor(s/60),t=s%60;return`${a}m ${t}s`},M=s=>{var a,t;if((a=s.booking_metadata)!=null&&a.userName)return s.booking_metadata.userName;if(s.user_name&&!s.user_name.includes("@"))return s.user_name;if(s.transcript&&Array.isArray(s.transcript)){for(const r of s.transcript)if(r.role==="assistant"&&r.content){const i=r.content.match(/Thanks,\s+([A-Za-z]+)|Welcome back,\s+([A-Za-z]+)/i);if(i)return i[1]||i[2]}}if((t=s.booking_metadata)!=null&&t.phoneNumber)return s.booking_metadata.phoneNumber;if(s.transcript&&Array.isArray(s.transcript)){for(const r of s.transcript)if(r.role==="user"&&r.content){const i=r.content.match(/\b(\d{3}[-.]?\d{3}[-.]?\d{4})\b/);if(i)return`+1${i[1].replace(/[-. ]/g,"")}`}}return"N/A"},F=s=>{u(s?new Set(o.map(a=>a.id)):new Set)},$=(s,a)=>{const t=new Set(l);a?t.add(s):t.delete(s),u(t)},H=async()=>{try{A(!0);const s=Array.from(l),{error:a}=await y.from("golfer_outreach_sessions").delete().in("chat_transcript_id",s);a&&console.warn("Error deleting linked outreach sessions:",a);const{error:t}=await y.from("chat_transcripts").delete().in("id",s);if(t)throw t;N.success(`Successfully deleted ${s.length} chat transcript${s.length>1?"s":""}`),u(new Set),b(!1),T()}catch(s){console.error("Error deleting chats:",s),N.error("Failed to delete chat transcripts")}finally{A(!1)}},L=(s,a)=>{a.target.closest("[data-checkbox]")||O(`/f/${P}/admin/chats/${s}`)},U=({chat:s})=>{var a,t,r,i;return e.jsx("div",{className:"p-4 border-b border-border active:bg-muted/50 cursor-pointer",onClick:n=>L(s.id,n),children:e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx("div",{"data-checkbox":!0,onClick:n=>n.stopPropagation(),className:"pt-0.5",children:e.jsx(g,{checked:l.has(s.id),onCheckedChange:n=>$(s.id,n),"aria-label":`Select chat ${s.id}`})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2 mb-1",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[((a=s.booking_metadata)==null?void 0:a.module)==="rally"?e.jsx(C,{className:"h-4 w-4 text-violet-500 flex-shrink-0","aria-label":"Rally outreach"}):(t=s.model_used)!=null&&t.includes("realtime")?e.jsx(k,{className:"h-4 w-4 text-success flex-shrink-0","aria-label":"Voice chat"}):e.jsx(w,{className:"h-4 w-4 text-info flex-shrink-0","aria-label":"Text chat"}),e.jsx("span",{className:"font-medium text-sm",children:_(new Date(s.conversation_date),"MMM d, yyyy")}),e.jsx("span",{className:"text-muted-foreground text-xs",children:_(new Date(s.conversation_date),"h:mm a")})]}),e.jsx(ve,{className:"h-4 w-4 text-muted-foreground flex-shrink-0"})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2 text-xs text-muted-foreground mb-2",children:[((r=s.booking_metadata)==null?void 0:r.module)==="rally"&&e.jsxs(e.Fragment,{children:[e.jsxs(j,{variant:"outline",className:"text-[10px] px-1.5 py-0 border-violet-300 text-violet-700 bg-violet-50 dark:border-violet-600 dark:text-violet-400 dark:bg-violet-950/30",children:[((i=s.booking_metadata)==null?void 0:i.topic)==="leagues"?"League":"Outreach"," · Rally"]}),e.jsx("span",{children:"•"})]}),e.jsx("span",{children:M(s)}),e.jsx("span",{children:"•"}),e.jsx("span",{children:z(s.duration_seconds)}),s.evaluation_score&&e.jsxs(e.Fragment,{children:[e.jsx("span",{children:"•"}),e.jsxs(j,{variant:s.evaluation_score>=8?"default":s.evaluation_score>=6?"secondary":"destructive",className:"text-[10px] px-1.5 py-0",children:[s.evaluation_score,"/10"]})]})]}),s.summary&&e.jsx("p",{className:"text-xs text-muted-foreground line-clamp-2",children:s.summary})]})]})})};return V?e.jsx(J,{}):e.jsxs("div",{className:"p-3 sm:p-6",children:[e.jsxs(K,{children:[e.jsxs(Q,{className:"space-y-3 pb-3 sm:pb-6",children:[e.jsxs("div",{className:"flex items-start justify-between gap-2",children:[e.jsxs("div",{children:[e.jsxs(X,{className:"flex items-center gap-2 text-base sm:text-xl",children:[e.jsx(je,{className:"h-4 w-4 sm:h-5 sm:w-5"}),e.jsx("span",{className:"hidden xs:inline",children:"Chat Transcripts"}),e.jsx("span",{className:"xs:hidden",children:"Chats"})]}),e.jsxs(Y,{className:"text-xs sm:text-sm mt-1",children:["Chat conversations for ",(v==null?void 0:v.name)||"this facility"]})]}),l.size>0&&e.jsxs(ee,{variant:"destructive",size:"sm",onClick:()=>b(!0),disabled:p,className:"flex-shrink-0",children:[e.jsx(ge,{className:"h-4 w-4 sm:mr-2"}),e.jsxs("span",{className:"hidden sm:inline",children:["Delete (",l.size,")"]}),e.jsx("span",{className:"sm:hidden",children:l.size})]})]}),e.jsx("div",{className:"flex flex-wrap items-center gap-3",children:e.jsxs(he,{value:x,onValueChange:s=>B(s),children:[e.jsx(ue,{className:"w-[140px] h-8 text-xs sm:text-sm",children:e.jsx(pe,{placeholder:"Filter by type"})}),e.jsxs(fe,{children:[e.jsx(h,{value:"all",children:"All Types"}),e.jsx(h,{value:"realtime",children:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(k,{className:"h-3.5 w-3.5 text-emerald-500"}),"Voice Chat"]})}),e.jsx(h,{value:"text",children:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(w,{className:"h-3.5 w-3.5 text-sky-500"}),"Text Chat"]})}),e.jsx(h,{value:"rally",children:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(C,{className:"h-3.5 w-3.5 text-purple-500"}),"Rally Outreach"]})}),D&&e.jsx(h,{value:"setup_intake",children:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(be,{className:"h-3.5 w-3.5 text-amber-500"}
1),"Setup Intake"]})})]})]})})]}),e.jsx(se,{className:"p-0",children:I?e.jsxs("div",{className:"text-center py-12 text-sm text-muted-foreground",children:[e.jsx("div",{className:"animate-spin rounded-full h-6 w-6 border-b-2 border-primary mx-auto mb-2"}),"Loading chats..."]}):o.length===0?e.jsx("div",{className:"text-center py-12 text-muted-foreground text-sm",children:"No chat transcripts found for this facility"}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"sm:hidden",children:[e.jsxs("div",{className:"flex items-center gap-3 px-4 py-2 bg-muted/30 border-b border-border",children:[e.jsx(g,{checked:l.size===o.length&&o.length>0,onCheckedChange:F,"aria-label":"Select all"}),e.jsx("span",{className:"text-xs text-muted-foreground",children:l.size>0?`${l.size} selected`:`${o.length} conversations`})]}),o.map(s=>e.jsx(U,{chat:s},s.id))]}),e.jsx("div",{className:"hidden sm:block overflow-x-auto",children:e.jsxs(ae,{children:[e.jsx(te,{children:e.jsxs(R,{children:[e.jsx(d,{className:"w-[50px]",children:e.jsx(g,{checked:l.size===o.length&&o.length>0,onCheckedChange:F,"aria-label":"Select all"})}),e.jsx(d,{className:"w-[50px]",children:"Type"}),e.jsx(d,{children:"Date"}),e.jsx(d,{children:"User"}),e.jsx(d,{children:"Duration"}),e.jsx(d,{children:"Score"}),e.jsx(d,{className:"max-w-[300px]",children:"Summary"})]})}),e.jsx(re,{children:o.map(s=>{var a,t,r,i;return e.jsxs(R,{className:"cursor-pointer hover:bg-muted/50",onClick:n=>L(s.id,n),children:[e.jsx(m,{children:e.jsx("div",{"data-checkbox":!0,onClick:n=>n.stopPropagation(),children:e.jsx(g,{checked:l.has(s.id),onCheckedChange:n=>$(s.id,n),"aria-label":`Select chat ${s.id}`})})}),e.jsx(m,{children:e.jsxs("div",{className:"flex items-center gap-1.5",children:[((a=s.booking_metadata)==null?void 0:a.module)==="rally"?e.jsx(C,{className:"h-4 w-4 text-violet-500","aria-label":"Rally outreach"}):(t=s.model_used)!=null&&t.includes("realtime")?e.jsx(k,{className:"h-4 w-4 text-success","aria-label":"Voice chat"}):e.jsx(w,{className:"h-4 w-4 text-info","aria-label":"Text chat"}),((r=s.booking_metadata)==null?void 0:r.module)==="rally"&&e.jsx(j,{variant:"outline",className:"text-[10px] px-1.5 py-0 border-violet-300 text-violet-700 bg-violet-50 dark:border-violet-600 dark:text-violet-400 dark:bg-violet-950/30",children:((i=s.booking_metadata)==null?void 0:i.topic)==="leagues"?"League":"Outreach"})]})}),e.jsx(m,{className:"whitespace-nowrap",children:_(new Date(s.conversation_date),"MMM d, yyyy h:mm a")}),e.jsx(m,{children:M(s)}),e.jsx(m,{children:z(s.duration_seconds)}),e.jsx(m,{children:s.evaluation_score?e.jsxs(j,{variant:s.evaluation_score>=8?"default":s.evaluation_score>=6?"secondary":"destructive",children:[s.evaluation_score,"/10"]}):"N/A"}),e.jsx(m,{className:"max-w-[300px] truncate",children:s.summary||"No summary"})]},s.id)})})]})})]})})]}),e.jsx(ie,{open:q,onOpenChange:b,children:e.jsxs(le,{children:[e.jsxs(ne,{children:[e.jsx(oe,{children:"Delete Chat Transcripts"}),e.jsxs(ce,{children:["Are you sure you want to delete ",l.size," chat transcript",l.size>1?"s":"","? This action cannot be undone."]})]}),e.jsxs(de,{children:[e.jsx(me,{disabled:p,children:"Cancel"}),e.jsx(xe,{onClick:H,disabled:p,className:"bg-destructive text-destructive-foreground hover:bg-destructive/90",children:p?"Deleting...":"Delete"})]})]})})]})};export{Oe 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.