PageSourceSearch

https://splashiq.ai/assets/chat.dispatch-Dv29sP4I.js

js splashiq.ai collected 2026-10-05 12:44:34 UTC 3,155 bytes, 1 lines download raw bytes

1import{j as e,r as n,s as r,cY as f,I as y,B as g,t as b}from"./index-CzAkNt2W.js";import{C as j}from"./card-DyZ6_8_C.js";import{R as _}from"./RequireRole-DhUlFC_T.js";import{S as v}from"./send-CH5TfEm8.js";function w(){const[d,l]=n.useState([]),[i,m]=n.useState(""),[a,h]=n.useState(null),[o,p]=n.useState(!1),u=n.useRef(null);n.useEffect(()=>{(async()=>{const{data:s}=await r.auth.getUser();if(!s.user)return;const{data:t}=await r.from("profiles").select("full_name, company_id").eq("id",s.user.id).maybeSingle();h({id:s.user.id,name:t?.full_name??s.user.email??"Me",company_id:t?.company_id??null});const{data:c}=await r.from("dispatch_messages").select("id, sender_id, sender_name, body, created_at").order("created_at",{ascending:!0}).limit(200);l(c??[])})()},[]),n.useEffect(()=>{const s=r.channel("dispatch-chat").on("postgres_changes",{event:"INSERT",schema:"public",table:"dispatch_messages"},t=>{l(c=>[...c,t.new])}).subscribe();return()=>{r.removeChannel(s)}},[]),n.useEffect(()=>{u.current?.scrollIntoView({behavior:"smooth"})},[d.length]);async function x(){if(!i.trim()||!a?.company_id||o)return;p(!0);const{error:s}=await r.from("dispatch_messages").insert({company_id:a.company_id,sender_id:a.id,sender_name:a.name,body:i.trim()});if(p(!1),s){b.error(s.message);return}m("")}return e.jsxs("div",{className:"mx-auto max-w-3xl px-4 md:px-6 py-6 space-y-4",children:[e.jsxs("header",{className:"flex items-center gap-3",children:[e.jsx(f,{className:"h-6 w-6 text-primary"}),e.jsxs("div",{children:[e.jsx("h1",{className:"font-display text-2xl font-bold",children:"Dispatch chat"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Internal channel — techs ↔ office. Not visible to homeowners."})]})]}),e.jsxs(j,{className:"p-0 overflow-hidden flex flex-col",style:{height:"60vh"},children:[e.jsxs("div",{className:"flex-1 overflow-y-auto p-4 space-y-3",children:[d.length===0&&e.jsx("div",{className:"text-center text-sm text-muted-foreground py-8",children:"No messages yet. Say hi 👋"}),d.map(s=>{const t=s.sender_id===a?.id;return e.jsx("div",{className:`flex ${t?"justify-end":"justify-start"}`,children:e.jsxs("div",{className:`max-w-[75%] rounded-2xl px-3 py-2 text-sm ${t?"bg-primary text-primary-foreground":"bg-muted"}`,children:[!t&&e.jsx("div",{className:"text-xs font-semibold opacity-70 mb-0.5",children:s.sender_name??"Teammate"}),e.jsx("div",{className:"whitespace-pre-wrap",children:s.body}),e.jsx("div",{className:`text-[10px] mt-0.5 ${t?"opacity-70":"text-muted-foreground"}`,children:new Date(s.created_at).toLocaleTimeString([],{hour:"numeric",minute:"2-digit"})})]})},s.id)}),e.jsx("div",{ref:u})]}),e.jsxs("form",{onSubmit:s=>{s.preventDefault(),x()},className:"border-t border-border p-3 flex gap-2 bg-card",children:[e.jsx(y,{value:i,onChange:s=>m(s.target.value),placeholder:a?.company_id?"Message dispatch…":"Join a company to chat",disabled:!a?.company_id||o}),e.jsx(g,{type:"submit",disabled:!i.trim()||!a?.company_id||o,children:e.jsx(v,{className:"h-4 w-4"})})]})]})]})}const E=()=>e.jsx(_,{allowed:["technician","office","owner","superadmin"],children:e.jsx(w,{})});export{E 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.