PageSourceSearch

https://ytprompt.ai/assets/AdminUserChats-C3u6Y6ZR.js

js ytprompt.ai collected 2026-10-05 14:48:59 UTC 15,079 bytes, 1 lines download raw bytes

1import{j as e}from"./vendor-markdown-Bj2spg3f.js";import{r}from"./vendor-react-B-0p-RVf.js";import{k as q,b as u}from"./index-45gJDKBt.js";import{a as J}from"./Pagination-YjWvfJrB.js";import{j as f,O as L,aC as Y,U as G,aD as K,aX as Q,bc as Z,av as M,E as ee,ae as te,C as se,a as re,aa as ne,a3 as ae}from"./vendor-icons-D-5f6XKt.js";import"./vendor-misc-D0V4jby4.js";import"./vendor-i18n-D8j9R6P3.js";const W=i=>{if(!i)return"-";try{return new Date(i).toLocaleDateString("en-US",{month:"short",day:"numeric",year:"numeric",hour:"2-digit",minute:"2-digit"})}catch{return i}},P=i=>{const a=(i||"free").toLowerCase();return a.includes("pro")||a.includes("premium")?"#8B5CF6":a.includes("business")||a.includes("enterprise")?"#F59E0B":a.includes("starter")||a.includes("basic")?"#3B82F6":"#6B7280"};function ge(){const i=(()=>{try{return JSON.parse(localStorage.getItem("user")||"{}")}catch{return{}}})(),a=!!(i.is_admin||i.role==="admin"),[I,N]=r.useState([]),[m,y]=r.useState(!0),[o,$]=r.useState(null),[d,c]=r.useState(1),[j,B]=r.useState(0),[v,T]=r.useState(""),[b,_]=r.useState(""),[n,x]=r.useState(null),[D,F]=r.useState([]),[O,A]=r.useState(!1),[R,p]=r.useState(null),[g,V]=r.useState(50),S=r.useRef(null),C=async()=>{try{const t=await u.get("/api/admin/user-chats-stats");$(t.data)}catch(t){console.error(t)}},h=async(t,s)=>{y(!0);try{const l=typeof t=="string"?t:v,z=typeof s=="string"?s:b;let k=`/api/admin/user-chats?page=${d}&limit=${g}`;if(l.trim()&&(k+=`&search=${encodeURIComponent(l.trim())}`),z.trim()){if(!/^\d+$/.test(z.trim())){y(!1);return}k+=`&user_id=${z.trim()}`}const E=await u.get(k);N(E.data.conversations||[]),B(E.data.total||0)}catch(l){console.error(l)}finally{y(!1)}};r.useEffect(()=>{C()},[]),r.useEffect(()=>{h()},[d,g]);const H=t=>{t.preventDefault(),c(1),h()},U=async t=>{x(t),A(!0),F([]);try{const s=await u.get(`/api/admin/user-chats/${t.id}`);F(s.data.messages||[]),setTimeout(()=>{S.current&&S.current.scrollIntoView({behavior:"smooth"})},100)}catch(s){console.error(s)}finally{A(!1)}},X=async t=>{try{await u.delete(`/api/admin/user-chats/${t}`),N(s=>s.filter(l=>l.id!==t)),B(s=>s-1),p(null),n&&n.id===t&&x(null),C()}catch(s){console.error(s)}},w=Math.ceil(j/g);return e.jsxs("div",{className:"fade-in",children:[e.jsxs("div",{className:"page-header stagger-1",children:[e.jsxs("div",{children:[e.jsxs("h1",{className:"page-title",style:{display:"flex",alignItems:"center",gap:10},children:[e.jsx(f,{size:24})," User Chats"]}),e.jsxs("p",{className:"page-subtitle",children:["View all AI assistant conversations (",j," total)"]})]}),e.jsxs("button",{className:"btn btn-secondary",onClick:()=>{h(),C()},disabled:m,style:{display:"flex",alignItems:"center",gap:6},children:[e.jsx(L,{size:16,className:m?"spinning":""})," Refresh"]})]}),o&&e.jsx("div",{className:"stagger-2",style:{display:"grid",gridTemplateColumns:"repeat(auto-fit, minmax(180px, 1fr))",gap:12,marginBottom:20},children:[{label:"Total Conversations",value:o.total_conversations,icon:e.jsx(f,{size:18}),color:"#8B5CF6"},{label:"Total Messages",value:o.total_messages,icon:e.jsx(Y,{size:18}),color:"#3B82F6"},{label:"Active Users",value:o.active_users,icon:e.jsx(G,{size:18}),color:"#10B981"},{label:"Today's Messages",value:o.today_messages,icon:e.jsx(K,{size:18}),color:"#F59E0B"}].map((t,s)=>e.jsxs("div",{className:"card",style:{padding:"16px 18px",display:"flex",alignItems:"center",gap:14},children:[e.jsx("div",{style:{width:40,height:40,borderRadius:10,background:`${t.color}15`,display:"flex",alignItems:"center",justifyContent:"center",color:t.color,flexShrink:0},children:t.icon}),e.jsxs("div",{children:[e.jsx("div",{style:{fontSize:22,fontWeight:700,color:"var(--text)"},children:t.value?.toLocaleString()}),e.jsx("div",{style:{fontSize:11,fontWeight:600,color:"var(--text-muted)",textTransform:"uppercase"},children:t.label})]})]},s))}),e.jsxs("form",{onSubmit:H,className:"card stagger-3",style:{display:"flex",gap:10,alignItems:"center",padding:12,marginBottom:16,flexWrap:"wrap"},children:[e.jsx(Q,{size:16,style:{color:"var(--text-muted)",flexShrink:0}}),e.jsx("input",{className:"form-input",placeholder:"Search by title, email, or name...",value:v,onCh
1ange:t=>T(t.target.value),style:{margin:0,flex:1,minWidth:180}}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:6},children:[e.jsx(Z,{size:14,style:{color:"var(--text-muted)"}}),e.jsx("input",{className:"form-input",placeholder:"User ID",value:b,onChange:t=>_(t.target.value),style:{margin:0,width:90}})]}),e.jsx("button",{className:"btn btn-primary btn-sm",type:"submit",children:"Search"}),(v||b)&&e.jsx("button",{className:"btn btn-secondary btn-sm",type:"button",onClick:()=>{T(""),_(""),c(1),h("","")},children:"Clear"})]}),m?e.jsxs("div",{className:"page-loading-content",style:{padding:"40px 0"},children:[e.jsx("div",{className:"page-loading-spinner"}),e.jsx("p",{className:"page-loading-text",children:"Loading conversations..."})]}):I.length===0?e.jsxs("div",{className:"card",style:{padding:40,textAlign:"center",color:"var(--text-muted)"},children:[e.jsx(f,{size:40,style:{marginBottom:12,opacity:.3}}),e.jsx("p",{style:{fontSize:15,fontWeight:600},children:"No conversations found"})]}):e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"card stagger-4",style:{overflow:"hidden"},children:e.jsx("div",{style:{overflowX:"auto"},children:e.jsxs("table",{className:"table",style:{width:"100%",borderCollapse:"collapse"},children:[e.jsx("thead",{children:e.jsxs("tr",{style:{borderBottom:"1px solid var(--border)"},children:[e.jsx("th",{style:{padding:"12px 14px",fontSize:11,fontWeight:700,color:"var(--text-muted)",textTransform:"uppercase",textAlign:"left"},children:"ID"}),e.jsx("th",{style:{padding:"12px 14px",fontSize:11,fontWeight:700,color:"var(--text-muted)",textTransform:"uppercase",textAlign:"left"},children:"User"}),e.jsx("th",{style:{padding:"12px 14px",fontSize:11,fontWeight:700,color:"var(--text-muted)",textTransform:"uppercase",textAlign:"left"},children:"Title"}),e.jsx("th",{style:{padding:"12px 14px",fontSize:11,fontWeight:700,color:"var(--text-muted)",textTransform:"uppercase",textAlign:"center"},children:"Messages"}),e.jsx("th",{style:{padding:"12px 14px",fontSize:11,fontWeight:700,color:"var(--text-muted)",textTransform:"uppercase",textAlign:"left"},children:"Plan"}),e.jsx("th",{style:{padding:"12px 14px",fontSize:11,fontWeight:700,color:"var(--text-muted)",textTransform:"uppercase",textAlign:"left"},children:"Last Activity"}),e.jsx("th",{style:{padding:"12px 14px",fontSize:11,fontWeight:700,color:"var(--text-muted)",textTransform:"uppercase",textAlign:"center"},children:"Actions"})]})}),e.jsx("tbody",{children:I.map(t=>e.jsxs("tr",{style:{borderBottom:"1px solid var(--border)",cursor:"pointer",transition:"background 0.15s"},onMouseEnter:s=>s.currentTarget.style.background="var(--bg-secondary, rgba(0,0,0,0.02))",onMouseLeave:s=>s.currentTarget.style.background="",onClick:()=>U(t),children:[e.jsxs("td",{style:{padding:"10px 14px",fontSize:13,color:"var(--text-muted)",fontWeight:600},children:["#",t.id]}),e.jsx("td",{style:{padding:"10px 14px"},children:e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8},children:[e.jsx("div",{style:{width:30,height:30,borderRadius:8,background:"linear-gradient(135deg, #8B5CF6, #6D28D9)",display:"flex",alignItems:"center",justifyContent:"center",flexShrink:0},children:e.jsx(M,{size:14,color:"white"})}),e.jsxs("div",{children:[e.jsx("div",{style:{fontSize:13,fontWeight:600,color:"var(--text)"},children:t.user_name||"Unknown"}),e.jsx("div",{style:{fontSize:11,color:"var(--text-muted)"},children:t.user_email})]})]})}),e.jsx("td",{style:{padding:"10px 14px",fontSize:13,color:"var(--text)",fontWeight:500,maxWidth:250,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:t.title||"Untitled"}),e.jsx("td",{style:{padding:"10px 14px",textAlign:"center"},children:e.jsx("span",{style:{fontSize:12,fontWeight:700,color:"#8B5CF6",background:"rgba(139,92,246,0.1)",padding:"3px 10px",borderRadius:12},children:t.message_count})}),e.jsx("td",{style:{padding:"10px 14px"},children:e.jsx("span",{style:{fontSize:11,fontWeight:700,color:P(t.user_plan),textTransform:"uppercase"},children:t.user_plan||"Free"})}),e.jsx("td",{style:{padding:"10px 14px",fontSize:12,color:"var(--text-muted)"},children:W(t.last_message_at||t.updated_at)}),e.jsx("td",{style:{padding:"10px 14px",textAlign:"center"},onClick:s=>s.stopPropagation(),children:e.jsxs("div",{style:{display:"flex",gap:6,justifyContent:"center"},children:[e.jsx("button",{onClick:()=>U(t),style:{padding:6,borderRadius:6,border:"1px solid var(--border)",background:"var(--card-bg)",cursor:"pointer",color:"#8B5CF6",display:"flex"},title:"View Messages",children:e.jsx(ee,{size:14})}),a&&e.jsx("button",{onClick:()=>p(t.id),style:{padding:6,borderRadius:6,border:"1px solid var(--border)",background:"var(--card-bg)",cursor:"pointer",color:"#EF4444",dis
1play:"flex"},title:"Delete",children:e.jsx(te,{size:14})})]})})]},t.id))})]})})}),e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",flexWrap:"wrap",gap:8,marginTop:16},children:[e.jsx(J,{value:g,onChange:t=>{V(t),c(1)},total:j}),w>1&&e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8},children:[e.jsxs("button",{className:"btn btn-secondary btn-sm",disabled:d<=1,onClick:()=>c(t=>t-1),style:{display:"flex",alignItems:"center",gap:4},children:[e.jsx(se,{size:14})," Prev"]}),e.jsxs("span",{style:{fontSize:13,fontWeight:600,color:"var(--text-muted)"},children:["Page ",d," of ",w]}),e.jsxs("button",{className:"btn btn-secondary btn-sm",disabled:d>=w,onClick:()=>c(t=>t+1),style:{display:"flex",alignItems:"center",gap:4},children:["Next ",e.jsx(re,{size:14})]})]})]})]}),n&&e.jsx("div",{style:{position:"fixed",top:0,left:0,right:0,bottom:0,background:"rgba(0,0,0,0.6)",zIndex:1e4,display:"flex",alignItems:"center",justifyContent:"center",padding:20},onClick:()=>x(null),children:e.jsxs("div",{style:{background:"var(--card-bg)",borderRadius:16,width:"100%",maxWidth:700,maxHeight:"90vh",overflow:"hidden",display:"flex",flexDirection:"column",boxShadow:"0 20px 60px rgba(0,0,0,0.3)"},onClick:t=>t.stopPropagation(),children:[e.jsxs("div",{style:{padding:"16px 20px",borderBottom:"1px solid var(--border)",display:"flex",alignItems:"center",justifyContent:"space-between",flexShrink:0},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:10,flex:1,minWidth:0},children:[e.jsx("div",{style:{width:36,height:36,borderRadius:10,background:"linear-gradient(135deg, #8B5CF6, #6D28D9)",display:"flex",alignItems:"center",justifyContent:"center",flexShrink:0},children:e.jsx(f,{size:18,color:"white"})}),e.jsxs("div",{style:{minWidth:0},children:[e.jsx("h2",{style:{margin:0,fontSize:15,fontWeight:700,color:"var(--text)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:n.title||"Untitled Conversation"}),e.jsxs("p",{style:{margin:0,fontSize:12,color:"var(--text-muted)"},children:[n.user_name||n.user_email," · ",n.message_count," messages"]})]})]}),e.jsx("button",{onClick:()=>x(null),style:{padding:6,borderRadius:8,border:"1px solid var(--border)",background:"var(--card-bg)",cursor:"pointer",color:"var(--text-muted)",display:"flex",alignItems:"center",flexShrink:0,marginLeft:10},children:e.jsx(ne,{size:18})})]}),e.jsxs("div",{style:{padding:"8px 16px",borderBottom:"1px solid var(--border)",display:"flex",gap:16,flexShrink:0,background:"var(--bg-secondary, var(--bg))"},children:[e.jsxs("div",{style:{fontSize:11,color:"var(--text-muted)"},children:[e.jsx("span",{style:{fontWeight:700,textTransform:"uppercase"},children:"User: "}),e.jsx("span",{style:{color:"var(--text)",fontWeight:600},children:n.user_email})]}),e.jsxs("div",{style:{fontSize:11,color:"var(--text-muted)"},children:[e.jsx("span",{style:{fontWeight:700,textTransform:"uppercase"},children:"Plan: "}),e.jsx("span",{style:{color:P(n.user_plan),fontWeight:700},children:(n.user_plan||"Free").toUpperCase()})]}),e.jsxs("div",{style:{fontSize:11,color:"var(--text-muted)"},children:[e.jsx("span",{style:{fontWeight:700,textTransform:"uppercase"},children:"Created: "}),e.jsx("span",{style:{fontWeight:500},children:W(n.created_at)})]})]}),e.jsx("div",{style:{flex:1,overflowY:"auto",padding:"16px 20px"},children:O?e.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"center",padding:40,color:"var(--text-muted)",gap:8},children:[e.jsx(L,{size:16,className:"spinning"})," Loading messages..."]}):D.length===0?e.jsx("div",{style:{textAlign:"center",padding:40,color:"var(--text-muted)"},children:"No messages in this conversation"}):e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:12},children:[D.map(t=>e.jsxs("div",{style:{display:"flex",gap:10,flexDirection:t.role==="user"?"row-reverse":"row"},children:[e.jsx("div",{style:{width:30,height:30,borderRadius:"50%",flexShrink:0,background:t.role==="user"?"linear-gradient(135deg, #3B82F6, #2563EB)":"linear-gradient(135deg, #8B5CF6, #6D28D9)",display:"flex",alignItems:"center",justifyContent:"center"},children:t.role==="user"?e.jsx(M,{size:14,color:"white"}):e.jsx(ae,{size:14,color:"white"})}),e.jsxs("div",{style:{maxWidth:"80%",padding:"10px 14px",borderRadius:12,background:t.role==="user"?"rgba(59,130,246,0.1)":"var(--bg-secondary, rgba(0,0,0,0.03))",border:`1px solid ${t.role==="user"?"rgba(59,130,246,0.15)":"var(--border)"}`},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:6,marginBottom:4},children:[e.jsx("span",{style:{fontSize:11,fontWeight:700,color:t.role==="user"?"#3B82F6":"#8B5CF6",textTransform:"uppercase"},children:t.role==="user"?"User":"Assistant"}
1),e.jsx("span",{style:{fontSize:10,color:"var(--text-muted)"},children:W(t.created_at)})]}),e.jsx("div",{style:{fontSize:13,color:"var(--text)",lineHeight:1.6,wordBreak:"break-word"},children:t.role==="assistant"?e.jsx(q,{content:t.content}):e.jsx("span",{style:{whiteSpace:"pre-wrap"},children:t.content})})]})]},t.id)),e.jsx("div",{ref:S})]})})]})}),R&&e.jsx("div",{style:{position:"fixed",top:0,left:0,right:0,bottom:0,background:"rgba(0,0,0,0.5)",zIndex:10001,display:"flex",alignItems:"center",justifyContent:"center",padding:20},onClick:()=>p(null),children:e.jsxs("div",{style:{background:"var(--card-bg)",borderRadius:14,padding:24,maxWidth:400,width:"100%",boxShadow:"0 20px 60px rgba(0,0,0,0.3)"},onClick:t=>t.stopPropagation(),children:[e.jsx("h3",{style:{margin:"0 0 10px",fontSize:16,fontWeight:700,color:"var(--text)"},children:"Delete Conversation"}),e.jsx("p",{style:{margin:"0 0 20px",fontSize:13,color:"var(--text-muted)",lineHeight:1.5},children:"Are you sure you want to delete this conversation? This will permanently remove all messages and cannot be undone."}),e.jsxs("div",{style:{display:"flex",gap:10,justifyContent:"flex-end"},children:[e.jsx("button",{className:"btn btn-secondary btn-sm",onClick:()=>p(null),children:"Cancel"}),e.jsx("button",{className:"btn btn-sm",style:{background:"#EF4444",color:"white",border:"none"},onClick:()=>X(R),children:"Delete"})]})]})})]})}export{ge 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.