PageSourceSearch

https://app.stoqui.com.br/assets/ChatsPage-CbynnMKh.js

js stoqui.com.br collected 2026-09-24 11:57:33 UTC 10,628 bytes, 16 lines download raw bytes

1import{j as e,T as b,R as te,as as ne,an as F,az as ae,ab as S,a7 as M,I as k,ao as re,Q as ie,at as R,n as E,ar as w,ac as T,X as oe,ai as le,Z as ce,aq as de,O as ue,N as B}from"./mui-CRsYZxVY.js";import{r as j}from"./vendor-Dwao9eNC.js";import{a as me,az as Q}from"./icons-D8aatgQ4.js";import{eK as he,eL as $,b8 as ge,eR as pe,ev as xe,cF as fe,u as U,w as I,t as _e,l as ye,b as je,v as be,bK as z,ca as Ce,T as Se,aC as Ie,eC as K,e9 as ve,K as N,dO as ke,g6 as Ee,bm as we}from"./index-TALscxEc.js";import{p as Te}from"./parseMessage-BE7jpFco.js";import{u as Me}from"./useProduct-BltDnkHr.js";import{a as W,u as De,b as Ae}from"./query-8ViTdhdk.js";import"./datePickers-BIJXYOKG.js";import"./lab-DSem1Osk.js";(function(){try{var t=typeof window<"u"?window:typeof global<"u"?global:typeof globalThis<"u"?globalThis:typeof self<"u"?self:{};t.SENTRY_RELEASE={id:"2ad85febf9735404429b0670d4acf56a0af5a0a2"}}catch{}})();try{(function(){var t=typeof window<"u"?window:typeof global<"u"?global:typeof globalThis<"u"?globalThis:typeof self<"u"?self:{},a=new t.Error().stack;a&&(t._sentryDebugIds=t._sentryDebugIds||{},t._sentryDebugIds[a]="944b434c-c243-4f63-ac8a-532c3d47b33d",t._sentryDebugIdIdentifier="sentry-dbid-944b434c-c243-4f63-ac8a-532c3d47b33d")})()}catch{}const Le=({status:t})=>t?e.jsx(e.Fragment,{children:t==="sent"?e.jsx(me,{sx:{color:"#667781",fontSize:"14px",display:"inline",marginLeft:"3px",lineHeight:"14px"}}):t==="delivered"?e.jsx(Q,{sx:{color:"#667781",fontSize:"14px",display:"inline",marginLeft:"3px"}}):e.jsx(Q,{sx:{minWidth:"14px",color:"#52bfea",fontSize:"14px",display:"inline",marginLeft:"3px"}})}):null,Oe=({id:t})=>{const{data:a,error:c}=Me(t);return c||!a?e.jsx(b,{display:"inline",fontSize:"inherit",children:` Produto #${t} `}):e.jsx(b,{display:"inline",fontSize:"inherit",sx:{},children:` ${a.nome} `})},qe=({id:t,profileUrl:a,name:c,lastMessage:m,unreadMessagesCount:r,onClick:i,timestamp:o,direction:p,status:n,selectEnabled:g=!1,selected:f=!1,longPressEvents:C})=>{let x="",_=!1;try{x=JSON.parse(m).text||""}catch{x="Error: Invalid message"}const y=Te(x);return e.jsx(te,{disablePadding:!0,sx:{display:"flex",alignItems:"center",backgroundColor:"white"},children:e.jsxs(ne,{onClick:i,...g?{}:C==null?void 0:C(),sx:{padding:2,display:"flex",alignItems:"center",width:"100%",overflow:"hidden"},children:[g&&e.jsx(F,{edge:"start",checked:f,tabIndex:-1,disableRipple:!0,onClick:h=>{h.stopPropagation(),i()},sx:{ml:-1,mr:1}}),e.jsx(ae,{sx:{minWidth:72},children:e.jsx(he,{alt:c,id:`customer-avatar-${t}`,src:a||void 0,sx:{width:$,height:$}})}),e.jsxs(S,{direction:"column",spacing:.5,sx:{flex:1,minWidth:0},children:[e.jsxs(S,{direction:"row",alignItems:"center",spacing:1,sx:{width:"100%"},children:[e.jsx(b,{sx:{...ge,flex:1,whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"},children:c||"Desconhecido"}),e.jsx(b,{sx:pe,children:xe(fe(o))})]}),e.jsxs(S,{direction:"row",alignItems:"center",spacing:.5,sx:{width:"100%"},children:[p==="sent"&&e.jsx(Le,{status:n}),e.jsx(b,{variant:"body2",sx:{flex:1,whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis",color:"text.secondary"},children:y.map((h,d)=>{if(h.type==="text")return h.content.includes("digitando...")?"":e.jsx("span",{children:h.content},d);if(!_&&(h.type==="inlineProducts"||h.type==="blockProducts")){_=!0;const v=h.content[0];return e.jsx(Oe,{id:v},v)}return null})})]})]}),!g&&r>0&&e.jsx(M,{sx:{ml:1,flexShrink:0,minWidth:20,height:20,px:.5,borderRadius:"999px",bgcolor:"primary.main",color:"primary.contrastText",display:"inline-flex",alignItems:"center",justifyContent:"center",fontSize:"12px",fontWeight:600},children:r>99?"99+":r})]})})},Pe=()=>{const{user:t}=U(),a=t==null?void 0:t.id,c=W(),m=De({queryKey:["conversations"],queryFn:async()=>{if(!a)throw new Error("Usuário não autenticado");const{data:r,error:i}=await I.from("conversa_cliente_view").select(`
2          conversa_id,
3          customer_user_id,
4          cliente_id,
5          cliente_nome,
6          cliente_profile_url,
7          mensagem_id,
8          mensagem_timestamp,
9          mensagem_conteudo,
10          mensagem_tipo,
11          mensagem_direcao,
12          mensagem_status,
13          id_ultima_mensagem,
14          nao_lidas,
15          timestamp_ultima_mensagem
16        `).not("id_ultima_mensagem","is",null).eq("vendedor_id",a).order("timestamp_ultima_mensagem",{ascending:!1}).limit(200);if(i)throw new Error(i.message);const o=r.map(n=>({id:n.conversa_id,customer_user_id:n.customer_user_id,vendedor_id:n.vendedor_id,cliente:{id:n.cliente_id,nome:n.cliente_nome,profile_url:n.cliente_profile_url},ultima_mensagem:{id:n.mensagem_id,timestamp:n.mensagem_timestamp,conteudo:n.mensagem_conteudo,tipo:n.mensagem_tipo,direcao:n.mensagem_direcao,status:n.mensagem_status},id_ultima_mensagem:n.id_ultima_mensagem,nao_lidas:n.nao_lidas,timestamp_ultima_mensagem:n.timestamp_ultima_mensagem})),p=new Map;for(const n of o){const g=n.customer_user_id,f=p.get(g);(!f||f.timestamp_ultima_mensagem<n.timestamp_ultima_mensagem)&&p.set(g,n)}return Array.from(p.values())},enabled:!!a});return j.useEffect(()=>{if(!a){console.log("User not authenticated");return}console.log("Subscribing to conversations changes",a);const r=I.channel("conversa-changes").on("postgres_changes",{event:"*",schema:"public",table:"conversa",filter:`vendedor_id=eq.${a}`},()=>{console.log("Conversations updated"),c.invalidateQueries({queryKey:["conversations"]})}).subscribe();return()=>{I.removeChannel(r)}},[c,a]),m},Re=()=>{const t=W(),{user:a}=U(),c=a==null?void 0:a.id;return Ae({mutationFn:async({customer_user_ids:r})=>{if(!c)throw new Error("User must be logged in to delete chats.");const{data:i,error:o}=await I.from("conversa").select("id").in("customer_user_id",r).eq("vendedor_id",c);if(o)throw new Error(o.message);if(!i||i.length===0)return[];const p=i.map(g=>g.id),{error:n}=await I.from("conversa").update({deletado_em:new Date().toISOString()}).in("id",p);if(n)throw n;return r.map(g=>({customer_user_id:g}))},onMutate:async r=>{await t.cancelQueries({queryKey:["conversations"]});const i=t.getQueryData(["conversations"])||[];return t.setQueryData(["conversations"],o=>o?o.filter(p=>!r.customer_user_ids.includes(p.customer_user_id)):[]),{previousChats:i}},onError:(r,i,o)=>{console.error("Error deleting chats:",r.message),o!=null&&o.previousChats&&t.setQueryData(["conversations"],o.previousChats)},onSuccess:(r,i)=>{_e(ye.DELETE.CONVERSATION_BULK,{customerUserIds:i.customer_user_ids,count:i.customer_user_ids.length})},onSettled:()=>{t.invalidateQueries({queryKey:["conversations"]})},retry:0})},Be="/assets/chats-bIJennoy.png";function Qe(){return e.jsxs(S,{alignItems:"center",spacing:1.5,sx:{pt:8,pb:4,px:3},children:[e.jsx(M,{component:"img",src:Be,alt:"",sx:{height:120,mb:1}}),e.jsx(b,{variant:"subtitle1",fontWeight:600,textAlign:"center",children:"Suas conversas aparecerão aqui"}),e.jsx(b,{variant:"body2",color:"text.secondary",textAlign:"center",sx:{maxWidth:280},children:"Quando seus clientes entrarem em contato, as mensagens vão aparecer aqui."})]})}const Je=()=>{const t=je(),[a]=be(),c=a.get("query")||"",[m,r]=j.useState([]),[i,o]=j.useState(!1),[p,n]=j.useState(null),[g,f]=j.useState(null),[C,x]=j.useState(!1),{data:_,isLoading:y,isError:h}=Pe(),d=j.useMemo(()=>_?c.trim()?_.filter(s=>{var u,l;return z(c,(u=s.cliente)==null?void 0:u.nome)||z(c,(l=s.ultima_mensagem)==null?void 0:l.conteudo)}):_:[],[_,c]),v=Re(),H=s=>{r(u=>u.includes(s)?u.filter(l=>l!==s):[...u,s])},V=Ce(()=>{we(),o(!0)},{cancelOnMovement:!0}),J=s=>{n(s.currentTarget)},D=()=>{n(null)},Z=s=>{f(s.currentTarget)},A=()=>{f(null)},X=()=>{D(),x(!0)},Y=()=>{o(!0),A()},G=()=>{o(!1),r([])},ee=()=>{const s=(d==null?void 0:d.map(l=>l.customer_user_id))||[],u=s.length>0&&s.every(l=>m.includes(l));r(u?m.filter(l=>!s.includes(l)):[...m.filter(l=>!s.includes(l)),...s])},L=()=>{const s=(d==null?void 0:d.map(l=>l.customer_user_id))||[],u=s.filter(l=>m.includes(l)).length;return u===0?{checked:!1,indeterminate:!1}:u===s.length?{checked:!0,indeterminate:!1}:{checked:!1,indeterminate:!0}},se=()=>{v.mutate({customer_user_ids:m}),x(!1),o(!1),r([])};return e.jsxs(M,{sx:{position:"relative",minHeight:"70vh",padding:2,overflow:"auto"},children:[e.jsx(Se,{title:"Conversas",navigateBack:()=>t(-1),children:i?e.jsxs(e.Fragment,{children:[e.jsx(k,{color:"inherit",onClick:G,children:e.jsx(Ie,{})}),e.jsx(k,{color:"inherit",onClick:J,children:e.jsx(K,{})})]}):e.jsxs(e.Fragment,{children:[e.jsx(ve,{}),d&&d.length>0&&e.jsx(k,{color:"inherit",onClick:Z,sx:{ml:1},children:e.jsx(K,{})})]})}),y&&e.jsx(S,{spacing:1,sx:{backgroundColor:"background.paper"},children:Array.from({length:10}).map((s,u)=>e.jsx(re,{variant:"rectangular",sx:{borderRadius:1},width:"100%",height:"88px"},u))}),!y&&h&&e.jsx(N,{primaryText:"Erro ao carregar as conversas"}
16),!y&&!h&&d&&d.length===0&&c&&e.jsx(N,{primaryText:"Nenhuma conversa encontrada",secondaryText:"Tente remover os filtros ou a palavra-chave de busca"}),!y&&!h&&d&&d.length===0&&!c&&e.jsx(Qe,{}),!y&&d&&d.length>0&&e.jsx(ie,{sx:{backgroundColor:"background.paper"},children:d.map(s=>{var u,l,O,q,P;return e.jsx(qe,{id:s.customer_user_id,profileUrl:(u=s==null?void 0:s.cliente)==null?void 0:u.profile_url,name:(l=s==null?void 0:s.cliente)==null?void 0:l.nome,lastMessage:(O=s==null?void 0:s.ultima_mensagem)==null?void 0:O.conteudo,unreadMessagesCount:s.nao_lidas,onClick:()=>{i?H(s.customer_user_id):t(`/chats/${s.customer_user_id}`)},timestamp:s.timestamp_ultima_mensagem,direction:(q=s==null?void 0:s.ultima_mensagem)==null?void 0:q.direcao,status:(P=s==null?void 0:s.ultima_mensagem)==null?void 0:P.status,selectEnabled:i,selected:m.includes(s.customer_user_id),longPressEvents:V},s.customer_user_id)})}),e.jsxs(R,{anchorEl:p,open:!!p,onClose:D,children:[e.jsxs(E,{onClick:ee,children:[e.jsx(w,{children:e.jsx(F,{checked:L().checked,indeterminate:L().indeterminate,tabIndex:-1,disableRipple:!0,sx:{p:"0px"}})}),e.jsx(T,{children:"Selecionar todos"})]}),e.jsxs(E,{onClick:X,disabled:m.length===0,children:[e.jsx(w,{children:e.jsx(ke,{})}),e.jsx(T,{children:m.length>0?`Excluir (${m.length})`:"Excluir"})]})]}),e.jsx(R,{anchorEl:g,open:!!g,onClose:A,children:e.jsxs(E,{onClick:Y,children:[e.jsx(w,{children:e.jsx(Ee,{})}),e.jsx(T,{children:"Selecionar"})]})}),e.jsxs(oe,{open:C,onClose:()=>x(!1),children:[e.jsx(le,{children:"Excluir conversas?"}),e.jsx(ce,{children:e.jsx(de,{children:`Quer excluir ${m.length} conversa(s)?`})}),e.jsxs(ue,{children:[e.jsx(B,{onClick:()=>x(!1),color:"primary",children:"Cancelar"}),e.jsx(B,{onClick:se,color:"primary",autoFocus:!0,children:"Confirmar"})]})]})]})};export{Je 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.