PageSourceSearch

https://geltoynation.com/assets/admin.chats-BrUj0A02.js

js geltoynation.com collected 2026-10-04 02:39:54 UTC 7,956 bytes, 1 lines download raw bytes

1import{c as H,m as U,k as c,au as G,av as K,aw as V,ax as Y,r,s as g,j as e,b as k,K as b,a8 as $,ay as J,az as P,aA as Q}from"./index-BCW6nnV8.js";import{L as W}from"./log-out-Djy8vhZ5.js";const X=[["path",{d:"M12 8V4H8",key:"hb8ula"}],["rect",{width:"16",height:"12",x:"4",y:"8",rx:"2",key:"enze0r"}],["path",{d:"M2 14h2",key:"vft8re"}],["path",{d:"M20 14h2",key:"4cs60a"}],["path",{d:"M15 13v2",key:"1xurst"}],["path",{d:"M9 13v2",key:"rq6x2g"}]],Z=H("bot",X);function te(){const _=U(),C=c(G),L=c(K),I=c(V),h=c(Y),[i,M]=r.useState([]),[t,A]=r.useState(null),[n,R]=r.useState(null),[v,l]=r.useState([]),[o,j]=r.useState(""),[y,D]=r.useState(!0),[E,N]=r.useState(!1),[u,w]=r.useState(!1),[F,T]=r.useState(!1),d=r.useRef(null),x=async()=>{try{const s=await C();M(s.conversations)}catch(s){String(s?.message||"").includes("Forbidden")?T(!0):console.error(s)}finally{D(!1)}};r.useEffect(()=>{x()},[]),r.useEffect(()=>{const s=g.channel("admin-inbox").on("postgres_changes",{event:"*",schema:"public",table:"conversations"},()=>x()).on("postgres_changes",{event:"INSERT",schema:"public",table:"chat_messages"},a=>{const f=a.new;f.conversation_id===t&&l(p=>p.some(z=>z.id===f.id)?p:[...p,f]),x()}).subscribe();return()=>{g.removeChannel(s)}},[t]);const m=async s=>{A(s),N(!0);try{const a=await L({data:{conversationId:s}});R(a.conversation),l(a.messages)}finally{N(!1)}};r.useEffect(()=>{d.current&&(d.current.scrollTop=d.current.scrollHeight)},[v]);const B=async()=>{if(!t||!o.trim()||u)return;w(!0);const s=o.trim();j("");try{await I({data:{conversationId:t,content:s}}),l(a=>[...a,{id:crypto.randomUUID(),role:"agent",content:s,created_at:new Date().toISOString()}])}catch(a){console.error(a)}finally{w(!1)}},O=async()=>{t&&(await h({data:{conversationId:t,status:"open",releaseToBot:!0}}),await m(t))},q=async()=>{t&&(await h({data:{conversationId:t,status:"resolved"}}),await m(t))},S=async()=>{await g.auth.signOut(),_({to:"/auth",replace:!0})};return F?e.jsx("div",{className:"min-h-screen flex items-center justify-center bg-background px-4",children:e.jsxs("div",{className:"max-w-md text-center",children:[e.jsx("h1",{className:"font-display text-xl font-bold uppercase tracking-wider mb-2",children:"Not authorized"}),e.jsx("p",{className:"text-sm text-muted-foreground mb-4",children:"Your account doesn't have admin access. Ask an existing admin to grant you the admin role."}),e.jsx("button",{onClick:S,className:"text-xs underline text-muted-foreground",children:"Sign out"})]})}):e.jsxs("div",{className:"h-screen flex bg-background text-foreground",children:[e.jsxs("aside",{className:"w-80 border-r border-border flex flex-col",children:[e.jsxs("div",{className:"px-4 py-3 border-b border-border flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("p",{className:"font-display text-sm font-bold uppercase tracking-wider",children:"Inbox"}),e.jsxs("p",{className:"text-[11px] text-muted-foreground",children:[i.length," conversations"]})]}),e.jsx("button",{onClick:S,title:"Sign out",className:"h-8 w-8 rounded-md hover:bg-surface flex items-center justify-center",children:e.jsx(W,{className:"h-4 w-4"})})]}),e.jsxs("div",{className:"flex-1 overflow-y-auto",children:[y&&e.jsxs("div",{className:"p-4 text-xs text-muted-foreground flex items-center gap-2",children:[e.jsx(k,{className:"h-3.5 w-3.5 animate-spin"})," Loading…"]}),!y&&i.length===0&&e.jsx("div",{className:"p-4 text-xs text-muted-foreground",children:"No conversations yet."}),i.map(s=>e.jsxs("button",{onClick:()=>m(s.id),className:b("w-full text-left px-4 py-3 border-b border-border hover:bg-surface/60 transition",t===s.id&&"bg-surface"),children:[e.jsxs("div",{className:"flex items-center justify-between gap-2 mb-1",children:[e.jsx("p",{className:"text-sm font-medium truncate",children:s.customer_name||s.customer_email||"Anonymous visitor"}),e.jsx("span",{className:"text-[10px] text-muted-foreground",children:new Date(s.last_message_at).toLocaleString([],{month:"short",day:"numeric",hour:"2-digit",minute:"2-digit"})})]}),e.jsxs("div",{className:"flex items-center gap-1.5",children:[s.status==="resolved"?e.jsx("span",{className:"text-[10px] uppercase tracking-wider text-muted-foreground bg-muted/30 px-1.5 py-0.5 rounded",children:"Resolved"}):s.handoff_requested?e.jsx("span",{className:"text-[10px] uppercase tracking-wider text-brand bg-brand/10 px-1.5 py-0.5 rounded",children:"Needs human"}):e.jsx("span",{className:"text-[10px] uppercase tracking-wider text-muted-foreground bg-muted/30 px-1.5 py-0.5 rounded",children:"Bot handling"}),s.customer_email&&e.jsx("span",{className:"text-[10px] text-muted-foreground truncate",children:s.customer_email})]})]},s.id))]})]}),e.jsxs("main",{className:"flex-1 flex flex-col",children:[!t&&e.jsx("div",{className:"flex-1 flex items-center justify-center text-sm text-muted-foreground",children:"Select a conversation to reply"}),t&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"px-5 py-3 border-b border-border flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("p",{className:"font-display text-sm font-bold uppercase tracking-wider",children:n?.customer_name||n?.customer_email||"Anonymous visitor"}),e.jsxs("p",{className:"text-[11px] text-muted-foreground",children:[n?.customer_email?`${n.customer_email}
1 · `:"","Started ",n?new Date(n.created_at).toLocaleString():""]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[n?.handoff_requested&&n.status!=="resolved"&&e.jsxs("button",{onClick:O,className:"text-xs px-3 py-1.5 rounded-md border border-border hover:bg-surface flex items-center gap-1.5",title:"Hand back to the AI assistant",children:[e.jsx($,{className:"h-3 w-3"})," Return to bot"]}),n?.status!=="resolved"&&e.jsxs("button",{onClick:q,className:"text-xs px-3 py-1.5 rounded-md border border-border hover:bg-surface flex items-center gap-1.5",children:[e.jsx(J,{className:"h-3 w-3"})," Mark resolved"]})]})]}),e.jsxs("div",{ref:d,className:"flex-1 overflow-y-auto px-5 py-6 space-y-3 bg-surface/20",children:[E&&e.jsxs("div",{className:"text-xs text-muted-foreground flex items-center gap-2",children:[e.jsx(k,{className:"h-3.5 w-3.5 animate-spin"})," Loading messages…"]}),v.map(s=>{if(s.role==="event")return e.jsx("div",{className:"mx-auto max-w-md text-center text-[11px] text-muted-foreground bg-surface border border-border rounded-full px-3 py-1",children:s.content},s.id);const a=s.role==="customer";return e.jsxs("div",{className:b("max-w-[70%] flex flex-col gap-1",a?"mr-auto":"ml-auto items-end"),children:[e.jsxs("span",{className:"text-[10px] font-semibold uppercase tracking-wider text-muted-foreground flex items-center gap-1",children:[a?"Customer":s.role==="agent"?e.jsxs(e.Fragment,{children:[e.jsx(P,{className:"h-3 w-3"})," Agent (you)"]}):e.jsxs(e.Fragment,{children:[e.jsx(Z,{className:"h-3 w-3"})," AI"]}),e.jsxs("span",{className:"font-normal opacity-60",children:["· ",new Date(s.created_at).toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"})]})]}),e.jsx("div",{className:b("rounded-2xl px-3.5 py-2.5 text-sm whitespace-pre-wrap break-words",a?"bg-surface border border-border rounded-bl-sm":s.role==="agent"?"bg-brand text-brand-foreground rounded-br-sm":"bg-muted/40 border border-border rounded-br-sm"),children:s.content})]},s.id)})]}),e.jsxs("form",{onSubmit:s=>{s.preventDefault(),B()},className:"border-t border-border p-3 flex gap-2 bg-background",children:[e.jsx("input",{value:o,onChange:s=>j(s.target.value),placeholder:"Type a reply to the customer…",className:"flex-1 h-10 rounded-full bg-surface border border-border px-4 text-sm focus:border-brand focus:outline-none",disabled:u}),e.jsxs("button",{type:"submit",disabled:u||!o.trim(),className:"h-10 px-5 rounded-full bg-brand text-brand-foreground text-sm font-semibold flex items-center gap-2 disabled:opacity-50 hover:brightness-110",children:[e.jsx(Q,{className:"h-4 w-4"})," Send"]})]})]})]})]})}export{te as component};

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.