PageSourceSearch

https://whisperai.com/assets/AdminChatDashboard-BwvLm-jY.js

js whisperai.com collected 2026-10-01 11:42:38 UTC 10,218 bytes, 1 lines download raw bytes

1import{u as $,r,j as e}from"./react-vendor-jUbs3Udp.js";import{a as M,u as p,b as k}from"./query-vendor-DSnlNft5.js";import{A as Q,a as B}from"./avatar-CQI7xtqx.js";import{B as c,I as _,o as h}from"./index-gcDjpmFZ.js";import{S as O,a as U,b as z,c as V,d as m}from"./select-DvkV6m6v.js";import{T as H}from"./textarea-ykfa7rqe.js";import{R as J,b as Y,c as G,d as j,U as W,B as X,e as Z,f as R,T as ee,g as se}from"./icons-Cjebwm3l.js";import"./ui-vendor-DDR7ojRs.js";(function(){try{var t=typeof window<"u"?window:typeof global<"u"?global:typeof globalThis<"u"?globalThis:typeof self<"u"?self:{};t.SENTRY_RELEASE={id:"2156d85cf031d709fa1b379f59bedaa6c159aa65"};var a=new t.Error().stack;a&&(t._sentryDebugIds=t._sentryDebugIds||{},t._sentryDebugIds[a]="83062f7a-86f4-4d08-977f-b2a790d0c640",t._sentryDebugIdIdentifier="sentry-dbid-83062f7a-86f4-4d08-977f-b2a790d0c640")}catch{}})();function ue(){const[,t]=$(),[a,v]=r.useState(null),[o,E]=r.useState("all"),[d,A]=r.useState(""),[l,y]=r.useState(""),[b,ae]=r.useState(1),i=M(),{data:f}=p({queryKey:["/api/v2/admin/check-auth"],refetchInterval:!1});r.useEffect(()=>{f&&!f.isAuthenticated&&t("/admin/login")},[f,t]);const L=async()=>{try{await fetch("/api/v2/admin/logout",{method:"POST",credentials:"include"}),localStorage.removeItem("adminAuthenticated"),t("/admin/login")}catch(s){console.error("Logout failed:",s)}},{data:F,isLoading:q,refetch:g}=p({queryKey:["/api/v2/admin/chat/sessions",o,b,d],queryFn:async()=>{const s=new URLSearchParams({page:b.toString(),limit:"20"});o!=="all"&&s.append("status",o),d&&s.append("search",d);const x=await fetch(`/api/v2/admin/chat/sessions?${s}`,{credentials:"include"});if(!x.ok)throw new Error("Failed to fetch sessions");return await x.json()}});r.useEffect(()=>{const s=setInterval(()=>{g(),a&&i.invalidateQueries({queryKey:["/api/v2/admin/chat/conversations",a]})},5e3);return()=>clearInterval(s)},[a,g,i]);const{data:P,isLoading:D}=p({queryKey:["/api/v2/admin/chat/sessions",a],queryFn:async()=>{if(!a)return null;const s=await fetch(`/api/v2/admin/chat/sessions/${a}`,{credentials:"include"});if(!s.ok)throw new Error("Failed to fetch conversation");return await s.json()},enabled:!!a}),u=k({mutationFn:async({content:s,markResolved:x})=>{const I=await fetch(`/api/v2/admin/chat/sessions/${a}/respond`,{method:"POST",headers:{"Content-Type":"application/json"},credentials:"include",body:JSON.stringify({content:s,noteType:"admin_response",markResolved:x})});if(!I.ok)throw new Error("Failed to send response");return I.json()},onSuccess:()=>{i.invalidateQueries({queryKey:["/api/v2/admin/chat/sessions",a]}),i.invalidateQueries({queryKey:["/api/v2/admin/chat/sessions"]}),y("")}}),N=k({mutationFn:async()=>{const s=await fetch(`/api/v2/admin/chat/sessions/${a}/close`,{method:"POST",headers:{"Content-Type":"application/json"},credentials:"include"});if(!s.ok)throw new Error("Failed to close chat");return s.json()},onSuccess:()=>{i.invalidateQueries({queryKey:["/api/v2/admin/chat/sessions",a]}),i.invalidateQueries({queryKey:["/api/v2/admin/chat/sessions"]}),v(null)}}),w=F?.sessions||[],n=P,S=s=>{switch(s){case"active":return"bg-blue-100 text-blue-800";case"escalated":return"bg-orange-100 text-orange-800";case"resolved":return"bg-green-100 text-green-800";default:return"bg-gray-100 text-gray-800"}},C=s=>{switch(s){case"active":return e.jsx(se,{className:"h-4 w-4"});case"escalated":return e.jsx(ee,{className:"h-4 w-4"});case"resolved":return e.jsx(j,{className:"h-4 w-4"});default:return e.jsx(R,{className:"h-4 w-4"})}},T=(s=!1)=>{l.trim()&&u.mutate({content:l,markResolved:s})},K=()=>{N.mutate()};return e.jsxs("div",{className:"flex h-screen bg-gray-50",children:[e.jsxs("div",{className:"w-1/3 border-r border-gray-200 bg-white",children:[e.jsxs("div",{className:"p-4 border-b border-gray-200",children:[e.jsxs("div",{className:"flex items-center justify-between mb-4",children:[e.jsx("h2",{className:"text-lg font-semibold text-gray-900",children:"Chat 
1Conversations"}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(c,{onClick:()=>g(),size:"sm",variant:"outline",children:e.jsx(J,{className:"h-4 w-4"})}),e.jsxs(c,{onClick:L,size:"sm",variant:"outline",children:[e.jsx(Y,{className:"h-4 w-4 mr-1"}),"Logout"]})]})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"relative",children:[e.jsx(G,{className:"absolute left-3 top-1/2 transform -translate-y-1/2 text-gray-400 h-4 w-4"}),e.jsx(_,{placeholder:"Search conversations...",value:d,onChange:s=>A(s.target.value),className:"pl-10"})]}),e.jsxs(O,{value:o,onValueChange:E,children:[e.jsx(U,{children:e.jsx(z,{placeholder:"Filter by status"})}),e.jsxs(V,{children:[e.jsx(m,{value:"all",children:"All Conversations"}),e.jsx(m,{value:"active",children:"Active"}),e.jsx(m,{value:"escalated",children:"Escalated"}),e.jsx(m,{value:"resolved",children:"Resolved"})]})]})]})]}),e.jsx("div",{className:"overflow-y-auto h-full",children:q?e.jsx("div",{className:"flex items-center justify-center h-32",children:e.jsx("div",{className:"animate-spin rounded-full h-6 w-6 border-b-2 border-blue-600"})}):w.length===0?e.jsx("div",{className:"p-4 text-center text-gray-500",children:"No conversations found"}):w.map(s=>e.jsxs("button",{type:"button",onClick:()=>v(s.session.sessionId),"aria-pressed":a===s.session.sessionId,className:`block w-full text-left p-4 border-b border-gray-100 cursor-pointer hover:bg-gray-50 ${a===s.session.sessionId?"bg-blue-50 border-blue-200":""}`,children:[e.jsxs("div",{className:"flex items-start justify-between",children:[e.jsxs("div",{className:"flex-1",children:[e.jsxs("div",{className:"flex items-center space-x-2 mb-1",children:[e.jsxs(h,{className:S(s.session.status),children:[C(s.session.status),e.jsx("span",{className:"ml-1",children:s.session.status})]}),s.unreadCount>0&&e.jsxs(h,{variant:"destructive",children:[s.unreadCount," new"]})]}),e.jsx("div",{className:"text-sm text-gray-900 font-medium",children:s.userEmail||"Anonymous User"}),e.jsxs("div",{className:"text-xs text-gray-500",children:[s.userTier&&e.jsx("span",{className:"mr-2",children:s.userTier}),s.session.contextPage]}),s.lastMessage&&e.jsx("div",{className:"text-sm text-gray-600 mt-1 truncate",children:s.lastMessage}),e.jsx("div",{className:"text-xs text-gray-400 mt-1",children:new Date(s.session.lastActivityAt).toLocaleString()})]}),e.jsx("div",{className:"text-right",children:e.jsxs("div",{className:"text-xs text-gray-500",children:[s.messageCount," messages"]})})]}),s.session.escalationReason&&e.jsx("div",{className:"mt-2 text-xs text-orange-600 bg-orange-50 p-2 rounded",children:s.session.escalationReason})]},s.session.sessionId))})]}),e.jsx("div",{className:"flex-1 flex flex-col",children:a?e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"p-4 border-b border-gray-200 bg-white",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsxs("h3",{className:"text-lg font-semibold text-gray-900",children:["Session: ",a.slice(-8)]}),n?.userContext&&e.jsxs("div",{className:"text-sm text-gray-600",children:[n.userContext.accountInfo.email," •",n.userContext.subscription.tier," •",n.userContext.subscription.usage||0," minutes used"]})]}),e.jsxs("div",{className:"flex items-center space-x-3",children:[e.jsxs(h,{className:S(n?.session?.status||"active"),children:[C(n?.session?.status||"active"),e.jsx("span",{className:"ml-1",children:n?.session?.status||"active"})]}),n?.session?.status!=="resolved"&&e.jsxs(c,{onClick:K,disabled:N.isPending,variant:"outline",size:"sm",children:[e.jsx(j,{className:"h-4 w-4 mr-2"}),"Close Chat"]})]})]})}),e.jsx("div",{className:"flex-1 overflow-y-auto p-4 space-y-4",children:D?e.jsx("div",{className:"flex items-center justify-center h-32",children:e.jsx("div",{className:"animate-spin rounded-full h-6 w-6 border-b-2 border-blue-600"})}):n?.messages?.length===0?e.jsx("div",{className:"text-center text-gray-500",children:"No messages in this conversation"}):n?.messages?.map(s=>e.jsxs("div",{className:`flex items-start space-x-3 ${s.role==="user"?"flex-row-reverse space-x-reverse":""}`,children:[e.jsx(Q,{className:"w-8 h-8",children:e.jsx(B,{className:s.role==="user"?"bg-blue-100 text-blue-600":s.role==="admin"?"bg-purple-100 text-purple-600":"bg-gray-100 text-gray-600",children:s.role==="user"?e.jsx(W,{className:"h-4 w-4"}):e.jsx(X,{className:"h-4 w-4"})})}),e.jsxs("div",{className:`flex-1 max-w-2xl ${s.role==="user"?"text-right":""}`,children:[e.jsx("div",{className:`rounded-lg px-4 py-3 ${s.role==="user"?"bg-blue-600 text-white":s.role==="admin"?"bg-purple-100 text-purple-800":"bg-gray-100 text-gray-800"}`,children:s.content}),e.jsxs("div",{className:"flex items-center mt-2 space-x-2 text-xs text-gray-500",children:[e.jsx("span",{children:new Date(s.createdAt).toLocaleStr
1ing()}),s.confidenceScore!==void 0&&e.jsxs("span",{children:["Confidence: ",Math.round(s.confidenceScore*100),"%"]}),s.needsHumanReview&&e.jsx(h,{variant:"outline",className:"text-orange-600",children:"Needs Review"})]})]})]},s.id))}),e.jsx("div",{className:"p-4 border-t border-gray-200 bg-white",children:e.jsxs("div",{className:"space-y-3",children:[e.jsx(H,{value:l,onChange:s=>y(s.target.value),placeholder:"Type your response...",rows:3,disabled:u.isPending}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("div",{className:"text-xs text-gray-500",children:"Respond as admin to this conversation"}),e.jsxs("div",{className:"flex space-x-2",children:[e.jsxs(c,{onClick:()=>T(!1),disabled:!l.trim()||u.isPending,variant:"outline",children:[e.jsx(Z,{className:"h-4 w-4 mr-2"}),"Send Reply"]}),e.jsxs(c,{onClick:()=>T(!0),disabled:!l.trim()||u.isPending,children:[e.jsx(j,{className:"h-4 w-4 mr-2"}),"Send & Resolve"]})]})]})]})})]}):e.jsx("div",{className:"flex-1 flex items-center justify-center",children:e.jsxs("div",{className:"text-center",children:[e.jsx(R,{className:"h-12 w-12 text-gray-400 mx-auto mb-4"}),e.jsx("h3",{className:"text-lg font-medium text-gray-900 mb-2",children:"Select a Conversation"}),e.jsx("p",{className:"text-gray-600",children:"Choose a conversation from the list to view messages and respond"})]})})})]})}export{ue as AdminChatDashboard};

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.