PageSourceSearch

https://mountain-days.replit.app/assets/VendorChat-D4LmrPeu.js

js mountain-days.replit.app collected 2026-10-03 03:59:01 UTC 10,374 bytes, 1 lines download raw bytes

1import{r as i,K,w as P,q as j,j as e,B as N,R as B,i as E,F as J,U as V,s as $,I as U,D as Y}from"./index-Bcg6ZirZ.js";import{u as _}from"./useMutation-DyAvRERQ.js";import"./card--vI6b00c.js";import{L as H}from"./table-DeCMIz8f.js";import{C as Q}from"./circle-alert-CyCT8v6e.js";import{M as v}from"./message-square-BxWqCQ8K.js";import{C as W}from"./chevron-left-BVfK9YPC.js";import{S as G}from"./send-DIAtgpJk.js";function ie(){i.useEffect(()=>{K("Messages")},[]);const{toast:z}=P(),[a,x]=i.useState(null),[d,w]=i.useState(""),[l,y]=i.useState(""),b=i.useRef(null),u=i.useRef(null),{data:I}=j({queryKey:["/api/vendor/me"],queryFn:async()=>{const t=await fetch("/api/vendor/me",{credentials:"include"});if(!t.ok)throw new Error("Not authenticated");return t.json()}}),c=I?.vendor?.id,{data:M,isLoading:A,error:D,refetch:h}=j({queryKey:["/api/vendor/chat/orgs"],queryFn:async()=>{const t=await fetch("/api/vendor/chat/orgs",{credentials:"include"});if(!t.ok)throw new Error("Failed to load conversations");return t.json()},refetchInterval:1e4}),n=M?.orgs||[];i.useEffect(()=>{n.length===1&&!a&&(x(n[0].organizationId),w(n[0].orgName))},[n,a]);const{data:C,isLoading:L,refetch:k}=j({queryKey:["/api/vendor/chat",a,"messages"],queryFn:async()=>{const t=await fetch(`/api/vendor/chat/${a}/messages`,{credentials:"include"});if(!t.ok)throw new Error("Failed to load messages");return t.json()},enabled:!!a,refetchInterval:5e3}),m=_({mutationFn:async t=>{const s=await Y("POST",`/api/vendor/chat/${a}/send`,{message:t});if(!s.ok){const r=await s.json().catch(()=>({}));throw new Error(r.error||"Failed to send")}return s.json()},onSuccess:()=>{y(""),k(),h()},onError:t=>z({title:"Error",description:t.message,variant:"destructive"})});i.useEffect(()=>{if(!c)return;const t=window.location.protocol==="https:"?"wss:":"ws:",s=new WebSocket(`${t}//${window.location.host}/ws`);return u.current=s,s.onopen=()=>{s.send(JSON.stringify({type:"chat_auth",role:"vendor",vendorId:c}))},s.onmessage=r=>{try{const o=JSON.parse(r.data);o.type==="chat_message"&&o.vendorAccountId===c&&(k(),h())}catch{}},s.onclose=()=>{setTimeout(()=>{u.current===s&&(u.current=null)},3e3)},()=>{s.close()}},[c,a]),i.useEffect(()=>{b.current?.scrollIntoView({behavior:"smooth"})},[C]);const f=C?.messages||[],g=n.length>1,O=i.useCallback(t=>{x(t.organizationId),w(t.orgName)},[]),S=()=>{!l.trim()||!a||m.mutate(l.trim())},F=t=>{t.key==="Enter"&&!t.shiftKey&&(t.preventDefault(),S())},T=t=>new Date(t).toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"}),p=t=>new Date(t).toLocaleDateString([],{weekday:"long",month:"long",day:"numeric"}),q=t=>{const s=new Date(t),r=Date.now()-s.getTime();return r<6e4?"Just now":r<36e5?`${Math.floor(r/6e4)}m ago`:r<864e5?s.toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"}):s.toLocaleDateString([],{month:"short",day:"numeric"})};return A?e.jsx(H,{fullPage:!0,message:"Loading messages..."}):D?e.jsxs("div",{className:"flex flex-col items-center justify-center py-24 gap-3",children:[e.jsx(Q,{className:"h-10 w-10 text-red-400"}),e.jsx("p",{className:"text-sm font-medium text-red-600",children:"Failed to load conversations"}),e.jsxs(N,{variant:"outline",size:"sm",onClick:()=>h(),className:"gap-1.5 mt-2",children:[e.jsx(B,{className:"w-3.5 h-3.5"})," Retry"]})]}):n.length===0?e.jsxs("div",{className:"p-5 sm:p-8 max-w-3xl mx-auto animate-in fade-in duration-500","data-testid":"vendor-chat",children:[e.jsxs("header",{className:"mb-4",children:[e.jsx("h1",{className:"text-2xl font-display font-extrabold tracking-tight","data-testid":"text-page-title",children:"Messages"}),e.jsx("p",{className:"text-sm text-muted-foreground mt-0.5",children:"Chat with your event organizers"})]}),e.jsxs("div",{className:"border rounded-xl p-12 flex flex-col items-center gap-4 bg-card text-center",children:[e.jsx("div",{className:"w-14 h-14 rounded-2xl bg-muted/60 flex items-center justify-center",children:e.jsx(v,{className:"w-7 h-7 text-muted-foreground/40"})}),e.jsxs("div",{children:[e.jsx("h3",{className:"font-semibold text-sm mb-1",children:"No Conversations Yet"}),e.jsx("p",{className:"text-xs text-muted-foreground leading-relaxed max-w-xs",children:"Once you register for an event, you'll be able to message the event organizer directly here."})]})]})]}):e.jsxs("div",{className:"p-5 sm:p-8 max-w-5xl mx-auto animate-in fade-in duration-500","data-testid":"vendor-chat",children:[e.jsxs("header",{className:"mb-4",children:[e.jsx("h1",{className:"text-2xl font-display font-extrabold tracking-tight","data-testid":"text-page-title",children:"Messages"}),e.jsx("p",{className:"text-sm text-muted-foreground mt-0.5",children:"Chat with your event organizers"})]}),e.jsxs("div",{className:"border rounded-xl overflow-hidden bg-card flex",style:{height:"calc(100vh - 220p
1x)",minHeight:420},children:[g&&e.jsxs("div",{className:`w-full md:w-72 border-r flex flex-col shrink-0 ${a?"hidden md:flex":""}`,children:[e.jsx("div",{className:"px-3 py-2.5 border-b bg-muted/30",children:e.jsx("p",{className:"text-xs font-semibold text-muted-foreground uppercase tracking-wider",children:"Your Organizers"})}),e.jsx("div",{className:"flex-1 overflow-y-auto",children:n.map(t=>e.jsx("button",{className:`w-full text-left p-3 border-b transition-colors hover:bg-muted/40 ${a===t.organizationId?"bg-primary/5 border-l-2 border-l-primary":""}`,onClick:()=>O(t),"data-testid":`thread-${t.organizationId}`,children:e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx("div",{className:"w-9 h-9 rounded-full flex items-center justify-center shrink-0 mt-0.5",style:{backgroundColor:t.orgColor+"20"},children:e.jsx(E,{className:"w-4 h-4",style:{color:t.orgColor}})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsx("span",{className:`text-sm truncate ${t.unreadCount>0?"font-bold":"font-medium"}`,children:t.orgName}),t.lastAt&&e.jsx("span",{className:"text-[10px] text-muted-foreground shrink-0",children:q(t.lastAt)})]}),e.jsxs("div",{className:"flex items-center justify-between gap-2 mt-0.5",children:[e.jsx("p",{className:`text-xs truncate ${t.unreadCount>0?"text-foreground font-medium":"text-muted-foreground"}`,children:t.lastMessage||`${t.orgCity}, ${t.orgState}`}),t.unreadCount>0&&e.jsx(J,{className:"bg-primary text-primary-foreground text-[10px] h-4 min-w-4 px-1 rounded-full shrink-0",children:t.unreadCount})]})]})]})},t.organizationId))}),e.jsx("div",{className:"p-3 border-t bg-muted/30",children:e.jsxs("div",{className:"flex items-center gap-2 text-xs text-muted-foreground",children:[e.jsx(V,{className:"w-3.5 h-3.5"}),e.jsxs("span",{children:[n.length," organizer",n.length!==1?"s":""]})]})})]}),e.jsx("div",{className:`flex-1 flex flex-col min-w-0 ${g&&!a?"hidden md:flex":""}`,children:a?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"px-4 py-3 border-b bg-muted/30 flex items-center gap-3 shrink-0",children:[g&&e.jsx(N,{variant:"ghost",size:"sm",className:"md:hidden h-8 w-8 p-0",onClick:()=>x(null),children:e.jsx(W,{className:"w-4 h-4"})}),e.jsx("div",{className:"w-8 h-8 rounded-full flex items-center justify-center shrink-0",style:{backgroundColor:(n.find(t=>t.organizationId===a)?.orgColor||"#0EA5A4")+"20"},children:e.jsx(E,{className:"w-4 h-4",style:{color:n.find(t=>t.organizationId===a)?.orgColor||"#0EA5A4"}})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("h3",{className:"text-sm font-bold truncate",children:d}),e.jsx("p",{className:"text-[10px] text-muted-foreground",children:"Event Organizer"})]})]}),e.jsx("div",{className:"flex-1 overflow-y-auto px-4 py-4 space-y-3 bg-muted/10",children:L?e.jsx("div",{className:"flex items-center justify-center py-12",children:e.jsx($,{className:"w-5 h-5 animate-spin text-muted-foreground"})}):f.length===0?e.jsxs("div",{className:"flex flex-col items-center justify-center py-16 gap-3",children:[e.jsx("div",{className:"w-14 h-14 rounded-2xl bg-muted/60 flex items-center justify-center",children:e.jsx(v,{className:"w-7 h-7 text-muted-foreground/40"})}),e.jsxs("div",{className:"text-center max-w-xs",children:[e.jsx("h3",{className:"font-semibold text-sm mb-1",children:"Start a Conversation"}),e.jsxs("p",{className:"text-xs text-muted-foreground leading-relaxed",children:["Send a message to ",d,". Ask about booth details, event logistics, or anything else."]})]})]}):e.jsxs(e.Fragment,{children:[f.map((t,s)=>{const r=t.senderType==="vendor",o=s>0?f[s-1]:null,R=!o||p(t.createdAt)!==p(o.createdAt);return e.jsxs("div",{children:[R&&e.jsx("div",{className:"flex items-center justify-center my-3",children:e.jsx("span",{className:"text-[10px] text-muted-foreground bg-muted/80 px-3 py-1 rounded-full",children:p(t.createdAt)})}),e.jsx("div",{className:`flex ${r?"justify-end":"justify-start"}`,"data-testid":`msg-${t.id}`,children:e.jsxs("div",{className:`max-w-[80%] rounded-2xl px-3.5 py-2 ${r?"bg-primary text-primary-foreground rounded-br-md":"bg-card border rounded-bl-md shadow-sm"}`,children:[!r&&e.jsx("p",{className:"text-[10px] font-semibold text-primary mb-0.5",children:d}),e.jsx("p",{className:"text-sm whitespace-pre-wrap break-words",children:t.message}),e.jsx("p",{className:`text-[10px] mt-1 ${r?"text-primary-foreground
1/60":"text-muted-foreground"}`,children:T(t.createdAt)})]})})]},t.id)}),e.jsx("div",{ref:b})]})}),e.jsx("div",{className:"px-4 py-3 border-t bg-card shrink-0",children:e.jsxs("div",{className:"flex gap-2",children:[e.jsx(U,{value:l,onChange:t=>y(t.target.value),onKeyDown:F,placeholder:`Message ${d}…`,className:"flex-1 h-10",disabled:m.isPending,"data-testid":"input-message"}),e.jsx(N,{onClick:S,disabled:!l.trim()||m.isPending,className:"h-10 px-4","data-testid":"button-send",children:m.isPending?e.jsx($,{className:"w-4 h-4 animate-spin"}):e.jsx(G,{className:"w-4 h-4"})})]})})]}):e.jsxs("div",{className:"flex-1 flex flex-col items-center justify-center gap-4 px-6",children:[e.jsx("div",{className:"w-16 h-16 rounded-2xl bg-muted/60 flex items-center justify-center",children:e.jsx(v,{className:"w-8 h-8 text-muted-foreground/40"})}),e.jsxs("div",{className:"text-center max-w-sm",children:[e.jsx("h3",{className:"font-semibold text-base mb-1",children:"Select a Conversation"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Choose an organizer from the left to start messaging."})]})]})})]})]})}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.