PageSourceSearch

https://knuckl.com/assets/AdminCommunications-KyVlEgmV.js

js knuckl.com collected 2026-09-24 14:47:57 UTC 9,720 bytes, 1 lines download raw bytes

1import{a as j,j as e,c as v}from"./vendor-query-BxlSJxfF.js";import{I as A,P as S,r as N,B as $,ab as F,s as _}from"./index-DO0aGFYL.js";import{T as R,a as T,b as h,c as p}from"./tabs-BC396HY3.js";import{B as u}from"./badge-4jZnSn2H.js";import{A as D}from"./AdminPage-Bk0BX7la.js";import{A as x}from"./AdminCard-BSBYnc2T.js";import{A as y,a as w}from"./AdminLoading-DBn5PY9V.js";import{S as M}from"./search-BkqYkxAv.js";import{M as C}from"./message-square-CLxZQpIa.js";import{U as L}from"./users-4wDC2oQA.js";import{S as B}from"./send-C6vNENnO.js";import{L as f}from"./vendor-react-DdNhUK9-.js";import"./vendor-supabase-Csx7YFID.js";import"./index-B9yCq0Ag.js";import"./index-Ce1IEqmK.js";import"./index-Bidgsva9.js";function E(s,r=300){const[a,o]=j.useState(s);return j.useEffect(()=>{const d=setTimeout(()=>o(s),r);return()=>clearTimeout(d)},[s,r]),a}function q({role:s}){return s?e.jsx(u,{variant:"outline",className:"text-micro uppercase",children:s}):null}function ie(){const[s,r]=j.useState("direct"),[a,o]=j.useState({q:"",userA:"",userB:""}),d=E(a.q,300);return e.jsxs(D,{title:"Communications",subtitle:"Read-only. Every channel users can reach each other on.",children:[e.jsxs(x,{className:"p-2.5 grid gap-2 md:grid-cols-3",children:[e.jsxs("div",{className:"relative",children:[e.jsx(M,{className:"w-3.5 h-3.5 absolute left-2.5 top-2.5 text-muted-foreground"}),e.jsx(A,{placeholder:"Search content…",value:a.q,onChange:n=>o(t=>({...t,q:n.target.value})),className:"pl-8 h-9"})]}),e.jsxs("details",{className:"md:col-span-2",children:[e.jsx("summary",{className:"text-xs text-muted-foreground cursor-pointer py-2 px-1",children:"Filter by user ID"}),e.jsxs("div",{className:"grid gap-2 md:grid-cols-2 mt-1",children:[e.jsx(A,{placeholder:"User ID (sender or receiver)",value:a.userA,onChange:n=>o(t=>({...t,userA:n.target.value.trim()})),className:"h-9 font-mono text-xs"}),e.jsx(A,{placeholder:"…and (optional) other user ID",value:a.userB,onChange:n=>o(t=>({...t,userB:n.target.value.trim()})),className:"h-9 font-mono text-xs"})]})]})]}),e.jsxs(R,{value:s,onValueChange:r,children:[e.jsxs(T,{className:"w-full grid grid-cols-4 h-auto",children:[e.jsxs(h,{value:"direct",className:"flex-col gap-0.5 py-2 text-caption",children:[e.jsx(C,{className:"w-4 h-4"}),"Direct"]}),e.jsxs(h,{value:"group",className:"flex-col gap-0.5 py-2 text-caption",children:[e.jsx(L,{className:"w-4 h-4"}),"Group"]}),e.jsxs(h,{value:"sms",className:"flex-col gap-0.5 py-2 text-caption",children:[e.jsx(B,{className:"w-4 h-4"}),"SMS"]}),e.jsxs(h,{value:"calls",className:"flex-col gap-0.5 py-2 text-caption",children:[e.jsx(S,{className:"w-4 h-4"}),"Calls"]})]}),e.jsx(p,{value:"direct",className:"mt-3",children:e.jsx(K,{q:d,userA:a.userA,userB:a.userB})}),e.jsx(p,{value:"group",className:"mt-3",children:e.jsx(P,{q:d})}),e.jsx(p,{value:"sms",className:"mt-3",children:e.jsx(U,{q:d,userA:a.userA})}),e.jsx(p,{value:"calls",className:"mt-3",children:e.jsx(G,{userA:a.userA})})]})]})}function g(s){const r=s.trim();return/^[0-9a-f-]{36}$/i.test(r)?r:null}function K({q:s,userA:r,userB:a}){const o=g(r),d=g(a),{data:n,isLoading:t,refetch:i,isFetching:l}=v({queryKey:["admin-comms-direct",s,o,d],refetchInterval:3e4,queryFn:async()=>{const{data:c,error:k}=await _.rpc("admin_recent_messages",{p_limit:200,p_search:s||null,p_user_id:o,p_other_user_id:d});if(k)throw k;return c??[]}});return e.jsxs("div",{className:"space-y-2",children:[e.jsx(b,{count:(n==null?void 0:n.length)??0,loading:t||l,onRefresh:()=>i()}),t?e.jsx(y,{rows:4}):(n??[]).length===0?e.jsx(w,{Icon:C,title:"No messages match",description:"Adjust your filters or search terms."}):e.jsx(x,{className:"divide-y divide-border overflow-hidden",children:(n??[]).map(c=>e.jsxs("div",{className:"p-3 space-y-1.5",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2 text-xs text-muted-foreground",children:[e.jsxs("div",{className:"flex items-center gap-1.5 min-w-0",children:[e.jsx(f,{to:I(c.sender_role,c.sender_id),className:"font-medium text-foreground hover:underline truncate",children:c.sender_name||m(c.sender_id)}),e.jsx(q,{role:c.sender_role}),e.jsx("span",{children:"→"}),e.jsx(f,{to:I(c.receiver_role,c.receiver_id),className:"font-medium text-foreground hover:underline truncate",children:c.receiver_name||m(c.receiver_id)}),e.jsx(q,{role:c.receiver_role})]}),e.jsx("span",{className:"shrink-0",children:N(c.created_at)})]}),e.jsx("p",{className:"text-sm whitespace-pre-wrap break-words",children:c.content}),e.jsxs("div",{className:"flex items-center gap-2 text-caption text-muted-foreground",children:[c.job_title&&e.jsxs(f,{to:`/admin/jobs?id=${c.job_id}`,className:"hover:underline",children:["Job: ",c.job_title]}),!c.read&&e.jsx(u,{variant:"secondary",className:"text-micro",children:"unread"})]})]},c.id))})]})}function P({q:s}){const{data:r,isLoading:a,refetch:o,isFetching:d}=v({queryKey:["admin-comms-group",s],refetchInterval:3e4,queryFn:async()=>{const{data:n,error:t}=await _.rpc("admin_recent_group_messages",{p_limit:200,p_search:s||null});if(t)throw t;return n??[]}});return e.jsxs("div",{className:"space-y-2",children:[e.jsx(b,{count:(r==null?void 0:r.length)??0,loading:a||d,onRefresh:()=>o()}),a?e.jsx(y,{rows:4}):(r??[]).length===0?e.jsx(w,{Icon:L,title:"No group messages"}):e.jsx(x,{className:"divide-y divide-border overflow-hidden",children:(r??[]).map(n=>e.jsxs("div",{className:"p-3 space-y-1.5",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2 text-xs text-muted-foreground",children:[e.jsxs("div",{className:"flex items-center gap-1.5 min-w-0",children:[e.jsx(f,{to:I(n.sender_role,n.sender_id),className:"font-medium text-foreground hover:underline truncate",children:n.sender_name||m(n.sender_id)}),e.jsx(q,{role:n.sender_role}),e.jsx("span",{children:"in"}),e.jsx("span",{className:"font-medium text-foreground truncate",children:n.job_title||"(job)"})]}),e.jsx("span",{className:"shrink-0",children:N(n.created_at)})]}),e.jsx("p",{className:"text-sm whitespace-pre-wrap break-words",children:n.content})]},n.id))})]})}function U({q:s,userA:r}){const a=g(r),{data:o,isLoading:d,refetch:n,isFetching:t}=v({queryKey:["admin-comms-sms",s,a],refetchInterval:3e4,queryFn:async()=>{let i=_.from("sms_messages").select("id, created_at, phone, body, status, error, campaign, user_id").order("created_at",{ascending:!1}).limit(200);s&&(i=i.ilike("body",`%${s}%`)),a&&(i=i.eq("user_id",a));const{data:l,error:c}=await i;if(c)throw c;return l??[]}});return e.jsxs("div",{className:"space-y-2",children:[e.jsx(b,{count:(o==null?void 0:o.length)??0,loading:d||t,onRefresh:()=>n()}),d?e.jsx(y,{rows:4}):(o??[]).length===0?e.jsx(w,{Icon:B,title:"No SMS yet"}):e.jsx(x,{className:"divide-y divide-border overflow-hidden",children:(o??[]).map(i=>e.jsxs("div",{className:"p-3 space-y-1.5",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2 text-xs text-muted-foreground",children:[e.jsxs("div",{className:"flex items-center gap-1.5 min-w-0",children:[e.jsx("span",{className:"font-medium text-foreground",children:i.phone}),e.jsx(u,{variant:i.status==="sent"?"default":i.status==="failed"?"destructive":"secondary",className:"text-micro",children:i.status}),i.campaign&&e.jsx(u,{variant:"outline",className:"text-micro",children:i.campaign})]}),e.jsx("span",{className:"shrink-0",children:N(i.created_at)})]}),e.jsx("p",{className:"text-sm whitespace-pre-wrap break-words",children:i.body}),i.error&&e.jsx("p",{className:"text-caption text-destructive truncate",children:i.error})]},i.id))})]})}function G({userA:s}){const r=g(s),{data:a,isLoading:o,refetch:d,isFetching:n}=v({queryKey:["admin-comms-calls",r],refetchInterval:3e4,queryFn:async()=>{let t=_.from("call_logs").select("id, initiated_at, contractor_id, worker_id, status, duration_seconds, twilio_session_sid").order("initiated_at",{ascending:!1}).limit(200);r&&(t=t.or(`contractor_id.eq.${r},worker_id.eq.${r}`));const{data:i,error:l}=await t;if(l)throw l;return i??[]}});return e.jsxs("div",{className:"space-y-2",children:[e.jsx(b,{count:(a==null?void 0:a.length)??0,loading:o||n,onRefresh:()=>d()}),o?e.jsx(y,{rows:4}):(a??[]).length===0?e.jsx(w,{Icon:S,title:"No calls yet"}):e.jsx(x,{className:"divide-y divide-border overflow-hidden",children:(a??[]).map(t=>{var i;return e.jsxs("div",{className:"p-3 flex items-center justify-between gap-3",children:[e.jsxs("div",{className:"min-w-0 space-y-1",children:[e.jsxs("div",{className:"flex items-center gap-2 text-xs text-muted-foreground",children:[e.jsx("span",{className:"font-mono",children:m(t.contractor_id)}),e.jsx("span",{children:"→"}),e.jsx("span",{className:"font-mono",children:m(t.worker_id)}),e.jsx(u,{variant:t.status==="completed"?"default":["failed","busy","no-answer"].includes(t.status)?"destructive":"secondary",className:"text-micro",children:t.status})]}),e.jsxs("div",{className:"text-caption text-muted-foreground",children:[t.duration_seconds?`${t.duration_seconds}s`:"—"," · ",((i=t.twilio_session_sid)==null?void 0:i.slice(0,12))??""]})]}),e.jsx("span",{className:"text-xs text-muted-foreground shrink-0",children:N(t.initiated_at)})]},t.id)})})]})}function b({count:s,loading:r,onRefresh:a}){return e.jsxs("div",{className:"flex items-center justify-between text-xs text-muted-foreground px-1",children:[e.jsx("span",{children:r?"Loading…":`${s} result${s===1?"":"s"}`}),e.jsxs($,{variant:"ghost",size:"sm",className:"h-7 px-2",onClick:a,disabled:r,children:[e.jsx(F,{className:`w-3 h-3 mr-1 ${r?"animate-spin":""}`}),"Refresh"]})]})}function m(s){return s?s.slice(0,8):"—"}function I(s,r){return r?s==="contractor"?`/admin/users?role=contractor&id=${r}`:`/admin/users?role=worker&id=${r}`:"#"}export{ie 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.