PageSourceSearch

https://ineedleads.co.uk/assets/WhatsApp-FCnBE6Ct.js

js ineedleads.co.uk collected 2026-10-09 22:58:05 UTC 17,158 bytes, 1 lines download raw bytes

1import{r as l,j as e,u as G}from"./index-DKJ0tKwF.js";import{u as J}from"./useDesktopToolbarAction-BjAss24h.js";import{u as X}from"./useDesktopStatusUpdate-V-hQXDku.js";import{a2 as I,ck as T,cm as A,b2 as Z,r as Q,bR as H,bS as U,eq as ee,bU as $,bV as v,ba as z,eS as se,g0 as q,cC as ae,gB as te,aM as ne,ap as re,aq as le,ar as ie,as as oe,at as ce,T as de,bz as me,bj as ue}from"./App-CL-mfmhu.js";import{S as V,k as M,t as _,D as d,b as xe,P as he,g as L,f as pe,V as fe}from"./button-DFML8rOM.js";import{al as F,U as je,am as R}from"./V2Layout-DEbe2yZA.js";import{b as ge,a as Ne,u as O}from"./useWhatsApp-D5uGG735.js";import{c as we}from"./useContactDocuments-csZrQP7x.js";import{L as D,S as K}from"./tracker-DzJH7QDt.js";import{g as be,p as ye,I as ve}from"./v3LegalOverrides-BUgTGJPl.js";import{T as _e,M as Ce}from"./MessageTemplatesDialog-n_gUwLYh.js";import{I as De}from"./InternalPageSEO-loZWkmv4.js";import"./mouse-pointer-2-CzsmklB8.js";import"./index-BNGwt955.js";import"./SEOHead-B5IBZJEm.js";import"./types-DU7944Yl.js";function ke(){var y;const u=l.useRef(null),[n,x]=l.useState(null),[i,m]=l.useState(""),[t,k]=l.useState(""),{data:h=[],isLoading:f}=ge(),{data:j=[],isLoading:g}=Ne((n==null?void 0:n.id)||null),p=O(),N=we();l.useEffect(()=>{u.current&&(u.current.scrollTop=u.current.scrollHeight)},[j]);const w=async()=>{if(!i.trim()||!n)return;const s=n.phone||n.mobile;if(!s){G.error("Contact has no phone number");return}p.mutate({contactId:n.id,phoneNumber:s,message:i.trim()}),m("")},W=s=>{!s.media_stored_url||!s.contact_id||N.mutate({contactId:s.contact_id,mediaUrl:s.media_stored_url,filename:s.media_filename||`whatsapp-${s.message_type}-${Date.now()}`,mimeType:s.media_mime_type||"application/octet-stream",source:"whatsapp",sourceMessageId:s.id})},b=h.filter(s=>{if(!t)return!0;const o=`${s.contact.first_name||""} ${s.contact.last_name||""}`.toLowerCase(),a=(s.contact.phone||s.contact.mobile||"").toLowerCase(),r=t.toLowerCase();return o.includes(r)||a.includes(r)}),C=s=>s.first_name||s.last_name?`${s.first_name||""} ${s.last_name||""}`.trim():s.phone||s.mobile||"Unknown",S=s=>{switch(s){case"read":return e.jsx(q,{className:"h-3 w-3 text-blue-500"});case"delivered":return e.jsx(q,{className:"h-3 w-3 text-muted-foreground"});case"sent":return e.jsx(pe,{className:"h-3 w-3 text-muted-foreground"});case"pending":return e.jsx(be,{className:"h-3 w-3 text-muted-foreground"});default:return null}},E=s=>{switch(s){case"image":return e.jsx(ve,{className:"h-4 w-4"});case"video":return e.jsx(fe,{className:"h-4 w-4"});case"audio":return e.jsx(ye,{className:"h-4 w-4"});case"document":return e.jsx(L,{className:"h-4 w-4"});default:return null}},P=s=>{const o=s.media_stored_url||s.media_url;return e.jsxs("div",{className:"space-y-2",children:[o&&e.jsxs("div",{className:"relative group",children:[s.message_type==="image"&&e.jsx("img",{src:s.media_stored_url||s.media_url||"",alt:"WhatsApp image",className:"max-w-[200px] rounded-lg cursor-pointer hover:opacity-90",onClick:()=>window.open(s.media_stored_url||s.media_url||"","_blank")}),s.message_type==="video"&&e.jsx("video",{src:s.media_stored_url||s.media_url||"",controls:!0,className:"max-w-[200px] rounded-lg"}),s.message_type==="audio"&&e.jsx("audio",{src:s.media_stored_url||s.media_url||"",controls:!0,className:"max-w-[200px]"}),s.message_type==="document"&&e.jsxs("a",{href:s.media_stored_url||s.media_url||"",target:"_blank",rel:"noopener noreferrer",className:"flex items-center gap-2 p-3 bg-muted/50 rounded-lg hover:bg-muted",children:[e.jsx(L,{className:"h-8 w-8 text-primary"}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("p",{className:"text-sm font-medium truncate",children:s.media_filename||"Document"}),s.media_file_size&&e.jsxs("p",{className:"text-xs text-muted-foreground",children:[(s.media_file_size/1024).toFixed(1)," KB"]})]}),e.jsx(ae,{className:"h-4 w-4"})]}),s.media_stored_url&&s.contact_id&&e.jsx("div",{className:"absolute top-1 right-1 opacity-0 group-hover:opacity-100 transition-opacity",children:e.jsxs(d,{size:"sm",variant:"secondary",className:"h-7 text-xs",onClick:()=>W(s),disabled:N.isPending,children:[e.jsx(te,{className:"h-3 w-3 mr-1"}),"Save"]})})]}),s.content&&e.jsx("p",{className:"text-sm whitespace-pre-wrap",children:s.content})]})};return e.jsxs("div",{className:"flex h-[600px] border rounded-lg overflow-hidden bg-background",children:[e.jsxs("div",{className:_("w-80 border-r flex flex-col",n&&"hidden md:flex"),children:[e.jsx("div",{className:"p-3 border-b bg-[#075E54]/10",children:e.jsxs("div",{className:"relative",children:[e.jsx(V,{className:"absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground"}),e.jsx(F,{placeholder:"Search conversations...",value:t,onChange:s=>k(s.target.value),className:"pl-9"})]})}),e.jsx(I,{className:"flex-1",children:f?e.jsx("div",{className:"flex items-center justify-center py-12",children:e.jsx(D,{className:"h-8 w-8 animate-spin text-[#25D366]"})}):b.length===0?e.jsxs("div",{className:"flex flex-col items-center justify-center py-12 px-4 text-center",children:[e.jsx(M,{className:"h-12 w-12 text-muted-foreground mb-4"}),e.jsx("p",{className:"font-medium mb-1",children:"No conversations yet"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"WhatsApp conversations will appear here"})]}):e.jsx("div",{className:"divide-y",children:b.map(s=>{var o,a;return e.jsx("div",{onClick:()=>x(s.contact),className:_("p-3 cursor-pointer hover:bg-muted/50 transition-colors",(n==null?void 0:n.id)===s.contact.
1id&&"bg-muted"),children:e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx(T,{className:"h-10 w-10",children:e.jsx(A,{className:"bg-[#25D366]/20 text-[#25D366]",children:(((o=s.contact.first_name)==null?void 0:o[0])||((a=s.contact.phone)==null?void 0:a[0])||"?").toUpperCase()})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("p",{className:"font-medium truncate",children:C(s.contact)}),e.jsx("span",{className:"text-xs text-muted-foreground",children:Z(s.lastMessage.created_at,{addSuffix:!1})})]}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("p",{className:"text-sm text-muted-foreground truncate flex items-center gap-1",children:[s.lastMessage.direction==="outbound"&&S(s.lastMessage.status),E(s.lastMessage.message_type),s.lastMessage.content||`[${s.lastMessage.message_type}]`]}),s.unreadCount>0&&e.jsx(Q,{className:"h-5 w-5 rounded-full p-0 flex items-center justify-center bg-[#25D366]",children:s.unreadCount})]})]})]})},s.contact.id)})})})]}),e.jsx("div",{className:_("flex-1 flex flex-col",!n&&"hidden md:flex"),children:n?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"p-3 border-b flex items-center gap-3 bg-[#075E54]/10",children:[e.jsx(d,{variant:"ghost",size:"icon",className:"md:hidden",onClick:()=>x(null),children:e.jsx(xe,{className:"h-4 w-4"})}),e.jsx(T,{className:"h-10 w-10",children:e.jsx(A,{className:"bg-[#25D366]/20 text-[#25D366]",children:(((y=n.first_name)==null?void 0:y[0])||"?").toUpperCase()})}),e.jsxs("div",{className:"flex-1",children:[e.jsx("p",{className:"font-medium",children:C(n)}),e.jsx("p",{className:"text-xs text-muted-foreground",children:n.phone||n.mobile})]}),e.jsx(d,{variant:"ghost",size:"icon",children:e.jsx(he,{className:"h-4 w-4"})}
1),e.jsxs(H,{children:[e.jsx(U,{asChild:!0,children:e.jsx(d,{variant:"ghost",size:"icon",children:e.jsx(ee,{className:"h-4 w-4"})})}),e.jsxs($,{align:"end",children:[e.jsx(v,{children:"View Contact"}),e.jsx(v,{children:"Clear Chat"})]})]})]}),e.jsx(I,{ref:u,className:"flex-1 p-4 bg-[#ECE5DD]/30 dark:bg-muted/20",children:g?e.jsx("div",{className:"flex items-center justify-center h-full",children:e.jsx(D,{className:"h-8 w-8 animate-spin text-[#25D366]"})}):j.length===0?e.jsxs("div",{className:"flex flex-col items-center justify-center h-full text-center",children:[e.jsx(M,{className:"h-12 w-12 text-muted-foreground mb-4"}),e.jsx("p",{className:"font-medium mb-1",children:"No messages yet"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Start the conversation by sending a message"})]}):e.jsx("div",{className:"space-y-4",children:j.map((s,o)=>{const a=o===0||new Date(s.created_at).toDateString()!==new Date(j[o-1].created_at).toDateString();return e.jsxs("div",{children:[a&&e.jsx("div",{className:"flex items-center justify-center my-4",children:e.jsx("span",{className:"px-3 py-1 text-xs text-muted-foreground bg-background rounded-lg shadow-sm",children:z(s.created_at,"MMMM d, yyyy")})}),e.jsx("div",{className:_("flex",s.direction==="outbound"?"justify-end":"justify-start"),children:e.jsxs("div",{className:_("max-w-[75%] rounded-lg px-3 py-2 shadow-sm",s.direction==="outbound"?"bg-[#DCF8C6] dark:bg-[#005C4B] text-foreground rounded-br-none":"bg-background rounded-bl-none"),children:[P(s),e.jsxs("div",{className:_("flex items-center gap-1 mt-1",s.direction==="outbound"?"justify-end":"justify-start"),children:[e.jsx("span",{className:"text-xs text-muted-foreground",children:z(s.created_at,"h:mm a")}),s.direction==="outbound"&&S(s.status)]})]})})]},s.id)})})}),e.jsx("div",{className:"p-3 border-t bg-background",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(d,{variant:"ghost",size:"icon",className:"shrink-0",children:e.jsx(se,{className:"h-4 w-4"})}
1),e.jsxs(H,{children:[e.jsx(U,{asChild:!0,children:e.jsx(d,{variant:"ghost",size:"icon",className:"shrink-0",title:"Template Messages",children:e.jsx(L,{className:"h-4 w-4"})})}),e.jsxs($,{align:"start",className:"w-64",children:[e.jsx(v,{onClick:()=>m("Hi {{name}}, thank you for your interest. How can we help you today?"),children:e.jsx("span",{className:"text-sm",children:"Welcome Template"})}),e.jsx(v,{onClick:()=>m("Hi {{name}}, just following up on our earlier conversation. Do you have any questions?"),children:e.jsx("span",{className:"text-sm",children:"Follow Up"})}),e.jsx(v,{onClick:()=>m("Thank you for choosing us! We look forward to working with you."),children:e.jsx("span",{className:"text-sm",children:"Thank You"})}),e.jsx(v,{onClick:()=>m("Hi {{name}}, we have a special offer for you. Would you like to know more?"),children:e.jsx("span",{className:"text-sm",children:"Promotional"})})]})]}),e.jsx(F,{placeholder:"Type a message...",value:i,onChange:s=>m(s.target.value),onKeyDown:s=>s.key==="Enter"&&!s.shiftKey&&w(),className:"flex-1"}),e.jsx(d,{size:"icon",onClick:w,disabled:!i.trim()||p.isPending,className:"shrink-0 bg-[#25D366] hover:bg-[#128C7E]",children:p.isPending?e.jsx(D,{className:"h-4 w-4 animate-spin"}):e.jsx(K,{className:"h-4 w-4"})})]})})]}):e.jsxs("div",{className:"flex-1 flex flex-col items-center justify-center text-center p-8 bg-[#ECE5DD]/30 dark:bg-muted/20",children:[e.jsx("div",{className:"w-20 h-20 rounded-full bg-[#25D366]/20 flex items-center justify-center mb-4",children:e.jsx(M,{className:"h-10 w-10 text-[#25D366]"})}),e.jsx("h3",{className:"text-xl font-semibold mb-2",children:"WhatsApp Conversations"}),e.jsx("p",{className:"text-muted-foreground max-w-sm",children:"Select a conversation from the list to view messages and continue the conversation"})]})})]})}const B=[{id:"welcome",name:"Welcome Message",body:"Hi {{name}}, welcome to {{company}}! How can we help you today?"},{id:"followup",name:"Follow Up",body:"Hi {{name}}, just following up on our last conversation. Is there anything else you need?"},{id:"appointment",name:"Appointment Reminder",body:"Hi {{name}}, this is a reminder for your appointment on {{date}}. Please confirm your attendance."},{id:"thankyou",name:"Thank You",body:"Hi {{name}}, thank you for choosing {{company}}! We appreciate your business."},{id:"promotion",name:"Promotion",body:"Hi {{name}}, we have an exclusive offer just for you! Contact us to learn more."}];function Se({open:u,onOpenChange:n,onConversationStarted:x}){var o;const[i,m]=l.useState(""),[t,k]=l.useState(null),[h,f]=l.useState(""),[j,g]=l.useState(null),[p,N]=l.useState("contact"),{data:w=[],isLoading:W}=ne(),b=O(),C=l.useMemo(()=>{if(!i)return w.filter(r=>r.phone||r.mobile);const a=i.toLowerCase();return w.filter(r=>{const c=`${r.first_name||""} ${r.last_name||""}`.toLowerCase(),Y=(r.phone||r.mobile||"").toLowerCase();return(c.includes(a)||Y.includes(a))&&(r.phone||r.mobile)})},[w,i]),S=a=>{k({id:a.id,name:`${a.first_name||""} ${a.last_name||""}`.trim()||"Unknown",phone:a.phone||a.mobile||""}),N("compose")},E=a=>{const r=B.find(c=>c.id===a);if(r&&t){let c=r.body;c=c.replace("{{name}}",t.name),c=c.replace("{{company}}","our team"),c=c.replace("{{date}}",new Date().toLocaleDateString()),f(c),g(a)}},P=async()=>{!t||!h.trim()||b.mutate({contactId:t.id,phoneNumber:t.phone,message:h.trim()},{onSuccess:()=>{x==null||x(t.id),y()}})},y=()=>{m(""),k(null),f(""),g(null),N("contact"),n(!1)},s=h.length;return e.jsx(re,{open:u,onOpenChange:y,children:e.jsxs(le,{className:"max-w-lg",children:[e.jsxs(ie,{children:[e.jsxs(oe,{className:"flex items-center gap-2",children:[e.jsx(M,{className:"h-5 w-5 text-[#25D366]"}),"New WhatsApp Message"]}),e.jsx(ce,{children:p==="contact"?"Select a contact to message":`Composing to ${t==null?void 0:t.name}`})]}),p==="contact"?e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"relative",children:[e.jsx(V,{className:"absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground"}),e.jsx(F,{placeholder:"Search contacts by name or phone...",value:i,onChange:a=>m(a.target.value),className:"pl-9",autoFocus:!0})]}),e.jsx(I,{className:"h-[300px]",children:W?e.jsx("div",{className:"flex items-center justify-center py-12",children:e.jsx(D,{className:"h-6 w-6 animate-spin text-muted-foreground"})}):C.length===0?e.jsxs("div",{className:"text-center py-12 text-muted-foreground",children:[e.jsx(je,{className:"h-10 w-10 mx-auto mb-2 opacity-50"}),e.jsx("p",{className:"text-sm",children:"No contacts with phone numbers found"})]}):e.jsx("div",{className:"space-y-1",children:C.slice(0,50).map(a=>{var r;return e.jsxs("button",{onClick:()=>S(a),className:"w-full flex items-center gap-3 p-2.5 rounded-lg hover:bg-muted/60 transition-colors text-left",children:[e.jsx(T,{className:"h-9 w-9",children:e.jsx(A,{className:"bg-[#25D366]/15 text-[#25D366] text-xs",children:(((r=a.first_name)==null?void 0:r[0])||"?").toUpperCase()})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("p",{className:"text-sm font-medium truncate",children:[a.first_name," ",a.last_name]}),e.jsx("p",{className:"text-xs text-muted-foreground font-mono",children:a.phone||a.mobile})]})]},a.id)})})})]}):e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center gap-3 p-2 bg-muted/40 rounded-lg",children:[e.jsx(T,{className:"h-8 w-8",children:e.jsx(A,{className:"bg-[#25D366]/15 text-[#25D366] text-xs",children:((o=t==null?void 0:t.name[0])==null?void 0:o.toUpperCase())||"?"})}),e.jsxs("div",{className:"flex-1",children:[e.jsx("p",{className:"text-sm font-medium",children:t==null?void 0:t.name}),e.jsx("p",{className:"text-xs text-muted-foreground font-mono",children:t==null?void 0:t.phone})]}),e.jsx(d,{variant:"ghost",size:"sm",onClick:()=>N("contact"),children:"Change"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(R,{className:"text-xs text-muted-foreground",children:"Qu
1ick Templates"}),e.jsx(_e,{channel:"whatsapp",contactData:{first_name:t==null?void 0:t.name.split(" ")[0]},onSelect:a=>{f(a),g(null)}})]}),e.jsx("div",{className:"flex flex-wrap gap-1.5",children:B.map(a=>e.jsx(Q,{variant:j===a.id?"default":"outline",className:"cursor-pointer text-xs",onClick:()=>E(a.id),children:a.name},a.id))})]}),e.jsxs("div",{children:[e.jsx(R,{htmlFor:"wa-message",children:"Message"}),e.jsx(de,{id:"wa-message",placeholder:"Type your message...",value:h,onChange:a=>{f(a.target.value),g(null)},rows:4,className:"mt-1.5"}),e.jsxs("p",{className:"text-xs text-muted-foreground mt-1 text-right",children:[s," characters"]})]})]}),e.jsxs(me,{children:[e.jsx(d,{variant:"outline",onClick:y,children:"Cancel"}),p==="compose"&&e.jsxs(d,{onClick:P,disabled:!h.trim()||b.isPending,className:"bg-[#25D366] hover:bg-[#128C7E] gap-2",children:[b.isPending?e.jsx(D,{className:"h-4 w-4 animate-spin"}):e.jsx(K,{className:"h-4 w-4"}),"Send"]})]})]})})}function Qe(){const[u,n]=l.useState(!1),[x,i]=l.useState(!1);return J("whatsapp",{"+ New Message":()=>n(!0),Templates:()=>i(!0),"Filter ▾":()=>{window.dispatchEvent(new CustomEvent("whatsapp-toolbar-action",{detail:{action:"filter"}}))}}),X("whatsapp","WhatsApp"),e.jsxs(ue,{children:[e.jsx(De,{title:"WhatsApp",description:"Manage your WhatsApp conversations"}),e.jsx("div",{className:"p-4 sm:p-5",children:e.jsxs("div",{className:"w-full",children:[e.jsxs("div",{className:"mb-6",children:[e.jsx("h1",{className:"text-2xl font-bold",children:"WhatsApp"}),e.jsx("p",{className:"text-muted-foreground",children:"Manage your WhatsApp conversations with contacts"})]}),e.jsx(ke,{})]})}),e.jsx(Se,{open:u,onOpenChange:n}),e.jsx(Ce,{open:x,onOpenChange:i,defaultChannel:"whatsapp"})]})}export{Qe 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.