/
opt
/
canhelp
/
apps
/
web
/
.next
/
static
/
chunks
/
app
/
chat
/
/opt/canhelp/apps/web/.next/static/chunks/app/chat
mkdir
upload
Name
Size
Mode
Actions
page-f9b6fb54fe0ff791.js
15660
0644
edit
dl
rm
Edit:
/opt/canhelp/apps/web/.next/static/chunks/app/chat/page-f9b6fb54fe0ff791.js
(15660B)
(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[8457],{1258:(e,t,r)=>{"use strict";function l(e){if(!(null==e?void 0:e.trim()))return"—";let t=e.trim().split(/\s+/);return t.length<2||!t[1]?t[0]:"".concat(t[0]," ").concat(t[1][0].toUpperCase(),".")}function s(e,t,r){if(null==e?void 0:e.trim()){let r=null==t?void 0:t.trim();return r?"".concat(e.trim()," ").concat(r[0].toUpperCase(),"."):e.trim()}return l(r)}r.d(t,{E:()=>l,H:()=>s})},1592:(e,t,r)=>{"use strict";r.d(t,{CI:()=>a,Hh:()=>n,Jv:()=>s,wV:()=>i,yK:()=>l});let l=(0,r(6504).M)({baseURL:"https://api.canhelp.gr"}),{signIn:s,signOut:a,signUp:n,useSession:i}=l},4251:(e,t,r)=>{"use strict";r.r(t),r.d(t,{default:()=>g});var l=r(4568),s=r(7620),a=r(7541),n=r(9664),i=r.n(n),o=r(1592),c=r(9906),d=r(2982),u=r(1258),x=r(2838);let m="https://api.canhelp.gr";function h(){var e,t,r,n,h,g,f;let p=(0,a.useRouter)(),v=(0,a.useSearchParams)(),{data:b,isPending:j}=(0,o.wV)(),{t:y,locale:w}=(0,c.Y)(),[N,k]=(0,s.useState)([]),[C,L]=(0,s.useState)(!0),[M,_]=(0,s.useState)(null),[S,U]=(0,s.useState)([]),[D,E]=(0,s.useState)(!1),[T,A]=(0,s.useState)(""),[R,B]=(0,s.useState)(!1),[H,W]=(0,s.useState)(null),[I,z]=(0,s.useState)(!1),[V,P]=(0,s.useState)(null),K=(0,s.useRef)(null),O=(0,s.useRef)(null),F=(0,s.useRef)(null),G=(0,s.useRef)(null);(0,s.useEffect)(()=>{j||b||p.push("/login")},[b,j]),(0,s.useEffect)(()=>{b&&((0,d.Zp)().then(e=>{k(e);let t=v.get("room");t&&_(t)}).catch(e=>console.error("[chat] getChatRooms error:",e)).finally(()=>L(!1)),(0,d.z4)().then(e=>W({left:e.messagesLeft,sent:e.messagesSent})).catch(e=>console.error("[chat] getDailyUsage error:",e)))},[b]),(0,s.useEffect)(()=>{if(!b)return;let e=(0,x.io)(m,{withCredentials:!0,transports:["websocket","polling"]});return K.current=e,e.on("connect",()=>B(!0)),e.on("disconnect",()=>B(!1)),e.on("new_message",e=>{U(t=>{var r,l;if(t.some(t=>t.message.id===e.id))return t;let s=b.user&&b.user.id===e.senderId?{id:b.user.id,name:null!=(r=b.user.name)?r:"",image:null!=(l=b.user.image)?l:void 0}:null;return[...t,{message:e,sender:s}]}),k(t=>t.map(t=>{var r,l;return t.room.id===e.roomId?{...t,lastMessage:{body:e.body,createdAt:e.createdAt,translations:null!=(r=e.translations)?r:null,imageUrl:null!=(l=e.imageUrl)?l:null}}:t}).sort((e,t)=>{var r,l;let s=(null==(r=e.lastMessage)?void 0:r.createdAt)?new Date(e.lastMessage.createdAt).getTime():new Date(e.room.createdAt).getTime();return((null==(l=t.lastMessage)?void 0:l.createdAt)?new Date(t.lastMessage.createdAt).getTime():new Date(t.room.createdAt).getTime())-s}))}),e.on("message_translated",e=>{let{id:t,roomId:r,translations:l}=e;U(e=>e.map(e=>e.message.id===t?{...e,message:{...e.message,translations:l}}:e)),r&&k(e=>e.map(e=>e.room.id===r&&e.lastMessage?{...e,lastMessage:{...e.lastMessage,translations:l}}:e))}),()=>{e.disconnect(),K.current=null}},[b]),(0,s.useEffect)(()=>{var e,t;M&&(E(!0),U([]),(0,d.VL)(M).then(U).catch(e=>console.error("[chat] getMessages error:",e)).finally(()=>E(!1)),null==(e=K.current)||e.emit("join_room",M),null==(t=K.current)||t.emit("mark_read",M))},[M]),(0,s.useEffect)(()=>{if(!M)return;let e=setTimeout(()=>{var e;return null==(e=F.current)?void 0:e.focus()},50);return()=>clearTimeout(e)},[M]),(0,s.useEffect)(()=>{var e;null==(e=O.current)||e.scrollIntoView({behavior:"smooth",block:"nearest"})},[S]),(0,s.useEffect)(()=>{let e=e=>{"Escape"===e.key&&P(null)};return window.addEventListener("keydown",e),()=>window.removeEventListener("keydown",e)},[]);let J=(0,s.useCallback)(()=>{let e=T.trim();e&&M&&K.current&&(H&&null!==H.left&&H.left<=0||(K.current.emit("send_message",{roomId:M,body:e,locale:w}),A(""),W(e=>e&&null!==e.left?{...e,left:e.left-1,sent:e.sent+1}:e)))},[T,M,H]),Y=(0,s.useCallback)(async e=>{if(M&&K.current){z(!0);try{let t=new FormData;t.append("file",e);let r=await fetch("".concat(m,"/api/uploads"),{method:"POST",credentials:"include",body:t});if(!r.ok)throw Error("Upload failed");let{url:l}=await r.json();K.current.emit("send_message",{roomId:M,body:"",imageUrl:l,locale:w})}catch(e){}finally{z(!1),G.current&&(G.current.value="")}}},[M,w]),Z=null!=(g=({ru:"ru-RU",en:"en-US",el:"el-GR"})[w])?g:"el-GR";if(j||C)return(0,l.jsx)("div",{className:"text-center py-20 text-white",children:y("common.loading")});let q=N.find(e=>e.room.id===M),Q=null==b||null==(e=b.user)?void 0:e.id;return(0,l.jsxs)("div",{className:"max-w-5xl mx-auto px-4 py-6 h-[calc(100vh-80px)] flex gap-4",children:[(0,l.jsxs)("div",{className:"w-72 flex-shrink-0 bg-white rounded-xl border border-gray-200 overflow-hidden flex flex-col",children:[(0,l.jsxs)("div",{className:"p-4 border-b border-gray-100",children:[(0,l.jsx)("h1",{className:"font-bold text-gray-900 text-lg",children:y("nav.chat")}),(0,l.jsxs)("div",{className:"flex items-center gap-1.5 mt-1",children:[(0,l.jsx)("span",{className:"w-2 h-2 rounded-full ".concat(R?"bg-green-400":"bg-gray-300")}),(0,l.jsx)("span",{className:"text-xs text-gray-400",children:R?y("chat.connected"):y("chat.disconnected")})]})]}),(0,l.jsx)("div",{className:"flex-1 overflow-y-auto",children:0===N.length?(0,l.jsx)("div",{className:"p-6 text-center text-gray-400 text-sm",children:y("chat.no_rooms")}):N.map(e=>{var t,r,s;let{room:a,task:n,otherUser:i,lastMessage:o}=e,c=null!=(r=null==n?void 0:n.title)?r:(0,u.H)(null==i?void 0:i.firstName,null==i?void 0:i.lastName,null==i?void 0:i.name)||y("chat.direct_chat"),d=n?(0,u.H)(null==i?void 0:i.firstName,null==i?void 0:i.lastName,null==i?void 0:i.name)||"":y("chat.direct_chat");return(0,l.jsxs)("button",{onClick:()=>{_(a.id),setTimeout(()=>{var e;return null==(e=F.current)?void 0:e.focus()},50)},className:"w-full text-left px-4 py-3 border-b border-gray-50 hover:bg-gray-50 transition ".concat(M===a.id?"bg-green-50 border-l-2 border-l-green-500":""),children:[(0,l.jsxs)("div",{className:"flex items-start justify-between gap-1",children:[(0,l.jsx)("p",{className:"text-sm font-medium text-gray-800 line-clamp-1 flex-1",children:c}),o&&(0,l.jsx)("span",{className:"text-[10px] text-gray-400 shrink-0 mt-0.5",children:function(e){let t=new Date(e),r=new Date,l=Math.floor((r.getTime()-t.getTime())/6e4);return l<1?y("chat.just_now"):l<60?"".concat(l).concat(y("chat.min_ago")):t.toDateString()===r.toDateString()?t.toLocaleTimeString(Z,{hour:"2-digit",minute:"2-digit"}):t.toLocaleDateString(Z,{day:"2-digit",month:"2-digit"})}(o.createdAt)})]}),o?(0,l.jsx)("p",{className:"text-xs text-gray-400 mt-0.5 line-clamp-1",children:o.imageUrl&&!o.body?"\uD83D\uDCF7":null!=(s=null==(t=o.translations)?void 0:t[w])?s:o.body}):n?(0,l.jsx)("p",{className:"text-xs text-gray-400 mt-0.5 line-clamp-1",children:d}):null]},a.id)})})]}),(0,l.jsx)("div",{className:"flex-1 bg-white rounded-xl border border-gray-200 flex flex-col overflow-hidden",children:M?(0,l.jsxs)(l.Fragment,{children:[(0,l.jsx)("div",{className:"px-5 py-4 border-b border-gray-100",children:(0,l.jsx)("p",{className:"font-semibold text-gray-800 text-sm",children:null!=(f=null==q||null==(t=q.task)?void 0:t.title)?f:(0,u.H)(null==q||null==(r=q.otherUser)?void 0:r.firstName,null==q||null==(n=q.otherUser)?void 0:n.lastName,null==q||null==(h=q.otherUser)?void 0:h.name)||y("chat.direct_chat")})}),(null==q?void 0:q.task)&&(0,l.jsxs)(i(),{href:"/tasks/".concat(q.task.id),className:"flex items-center gap-3 mx-5 mt-4 px-4 py-3 bg-green-50 border border-green-200 rounded-xl hover:bg-green-100 transition group",children:[(0,l.jsx)("div",{className:"w-8 h-8 rounded-lg bg-green-600 flex items-center justify-center flex-shrink-0",children:(0,l.jsxs)("svg",{className:"w-4 h-4 text-white",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round",children:[(0,l.jsx)("path",{d:"M16 4h2a2 2 0 012 2v14a2 2 0 01-2 2H6a2 2 0 01-2-2V6a2 2 0 012-2h2"}),(0,l.jsx)("rect",{x:"8",y:"2",width:"8",height:"4",rx:"1",ry:"1"})]})}),(0,l.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,l.jsx)("p",{className:"text-xs text-gray-500 font-medium",children:y("chat.linked_task")}),(0,l.jsx)("p",{className:"text-sm font-semibold text-gray-800 truncate group-hover:underline",children:q.task.title})]}),(0,l.jsx)("svg",{className:"w-4 h-4 text-gray-400 flex-shrink-0",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round",children:(0,l.jsx)("polyline",{points:"9 18 15 12 9 6"})})]}),(0,l.jsxs)("div",{className:"flex-1 overflow-y-auto px-5 py-4 space-y-3",children:[D?(0,l.jsx)("div",{className:"text-center text-gray-400 text-sm py-10",children:y("common.loading")}):0===S.length?(0,l.jsx)("div",{className:"text-center text-gray-400 text-sm py-10",children:y("chat.no_messages")}):S.map(e=>{var t,r,s,a,n;let{message:i,sender:o}=e,c=i.senderId===Q;return(0,l.jsxs)("div",{className:"flex gap-2.5 ".concat(c?"flex-row-reverse":""),children:[(0,l.jsx)("div",{className:"w-8 h-8 rounded-full bg-green-100 flex-shrink-0 flex items-center justify-center text-green-700 text-xs font-bold overflow-hidden",children:(null==o?void 0:o.image)?(0,l.jsx)("img",{src:o.image,alt:o.name,className:"w-full h-full object-cover"}):null!=(a=null==o||null==(r=o.name)||null==(t=r[0])?void 0:t.toUpperCase())?a:"?"}),(0,l.jsxs)("div",{className:"max-w-[70%] ".concat(c?"items-end":"items-start"," flex flex-col gap-1"),children:[!c&&(0,l.jsx)("span",{className:"text-xs text-gray-400 px-1",children:(0,u.H)(null==o?void 0:o.firstName,null==o?void 0:o.lastName,null==o?void 0:o.name)}),i.imageUrl?(0,l.jsx)("button",{type:"button",onClick:()=>P("".concat(m).concat(i.imageUrl)),className:"block focus:outline-none",children:(0,l.jsx)("img",{src:"".concat(m).concat(i.imageUrl),alt:"photo",className:"rounded-2xl max-w-[240px] max-h-[320px] object-cover cursor-pointer hover:opacity-90 transition"})}):(0,l.jsx)("div",{className:"px-4 py-2 rounded-2xl text-sm leading-relaxed ".concat(c?"bg-green-600 text-white rounded-tr-sm":"bg-gray-100 text-gray-800 rounded-tl-sm"),children:null!=(n=null==(s=i.translations)?void 0:s[w])?n:i.body}),(0,l.jsx)("span",{className:"text-xs text-gray-300 px-1",children:new Date(i.createdAt).toLocaleTimeString(Z,{hour:"2-digit",minute:"2-digit"})})]})]},i.id)}),(0,l.jsx)("div",{ref:O})]}),V&&(0,l.jsx)("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/80 backdrop-blur-sm",onClick:()=>P(null),children:(0,l.jsxs)("div",{className:"relative max-w-[90vw] max-h-[90vh]",onClick:e=>e.stopPropagation(),children:[(0,l.jsx)("img",{src:V,alt:"photo",className:"max-w-[90vw] max-h-[90vh] rounded-2xl object-contain shadow-2xl"}),(0,l.jsx)("button",{onClick:()=>P(null),className:"absolute -top-3 -right-3 w-8 h-8 bg-white rounded-full flex items-center justify-center shadow-lg hover:bg-gray-100 transition","aria-label":"Close",children:(0,l.jsx)("svg",{className:"w-4 h-4 text-gray-700",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2.5,children:(0,l.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M6 18L18 6M6 6l12 12"})})}),(0,l.jsx)("a",{href:V,download:!0,target:"_blank",rel:"noreferrer",className:"absolute -bottom-3 -right-3 w-8 h-8 bg-white rounded-full flex items-center justify-center shadow-lg hover:bg-gray-100 transition","aria-label":"Download",onClick:e=>e.stopPropagation(),children:(0,l.jsx)("svg",{className:"w-4 h-4 text-gray-700",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:(0,l.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M4 16v2a2 2 0 002 2h12a2 2 0 002-2v-2M7 10l5 5 5-5M12 15V3"})})})]})}),(0,l.jsxs)("div",{className:"px-4 py-3 border-t border-gray-100",children:[" ",(0,l.jsx)("input",{ref:G,type:"file",accept:"image/jpeg,image/png,image/gif,image/webp",className:"hidden",onChange:e=>{var t;let r=null==(t=e.target.files)?void 0:t[0];r&&Y(r)}})," ",H&&null!==H.left&&H.left<=0&&(0,l.jsxs)("div",{className:"mb-2 flex items-center gap-2 bg-red-50 border border-red-200 rounded-xl px-3 py-2",children:[(0,l.jsx)("svg",{className:"w-4 h-4 text-red-400 shrink-0",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:(0,l.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M12 9v2m0 4h.01M10.29 3.86L1.82 18a2 2 0 001.71 3h16.94a2 2 0 001.71-3L13.71 3.86a2 2 0 00-3.42 0z"})}),(0,l.jsx)("span",{className:"text-xs text-red-700 flex-1",children:y("chat.limit_reached","Daily message limit reached")}),(0,l.jsx)(i(),{href:"/pricing",className:"text-xs font-medium text-red-700 underline",children:y("dashboard.plan.upgrade","Upgrade plan")})]}),H&&null!==H.left&&H.left>0&&H.left<=Math.ceil((H.left+H.sent)*.2)&&(0,l.jsxs)("div",{className:"mb-2 flex items-center gap-2 bg-amber-50 border border-amber-200 rounded-xl px-3 py-2",children:[(0,l.jsx)("svg",{className:"w-4 h-4 text-amber-400 shrink-0",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:(0,l.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M12 9v2m0 4h.01M10.29 3.86L1.82 18a2 2 0 001.71 3h16.94a2 2 0 001.71-3L13.71 3.86a2 2 0 00-3.42 0z"})}),(0,l.jsx)("span",{className:"text-xs text-amber-700 flex-1",children:y("chat.limit_warning","{n} messages left today").replace("{n}",String(H.left))}),(0,l.jsx)(i(),{href:"/pricing",className:"text-xs font-medium text-amber-700 underline",children:y("dashboard.plan.upgrade","Upgrade plan")})]}),(0,l.jsxs)("div",{className:"flex gap-2 items-end",children:[(0,l.jsx)("button",{type:"button",onClick:()=>{var e;return null==(e=G.current)?void 0:e.click()},disabled:I||!R||!!(H&&null!==H.left&&H.left<=0),className:"h-10 w-10 text-gray-400 hover:text-gray-500 disabled:opacity-40 disabled:cursor-not-allowed flex-shrink-0 flex items-center justify-center rounded-xl hover:bg-gray-50 transition",title:"Send photo",children:I?(0,l.jsxs)("svg",{className:"w-5 h-5 animate-spin",fill:"none",viewBox:"0 0 24 24",children:[(0,l.jsx)("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"4"}),(0,l.jsx)("path",{className:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8v8H4z"})]}):(0,l.jsxs)("svg",{className:"w-5 h-5",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:1.8,children:[(0,l.jsx)("rect",{x:"3",y:"3",width:"18",height:"18",rx:"3",ry:"3"}),(0,l.jsx)("circle",{cx:"8.5",cy:"8.5",r:"1.5"}),(0,l.jsx)("polyline",{points:"21 15 16 10 5 21"})]})}),(0,l.jsx)("textarea",{ref:F,value:T,onChange:e=>A(e.target.value),onKeyDown:e=>{"Enter"!==e.key||e.shiftKey||(e.preventDefault(),J())},rows:1,placeholder:y("chat.placeholder"),disabled:!!(H&&null!==H.left&&H.left<=0),className:"flex-1 border border-gray-300 rounded-xl px-3 py-2 text-sm focus:outline-none focus:ring-2 focus:ring-blue-400 resize-none max-h-32 disabled:bg-gray-50 disabled:text-gray-400",style:{minHeight:"40px"}}),(0,l.jsx)("button",{onClick:J,disabled:!T.trim()||!R||!!(H&&null!==H.left&&H.left<=0),className:"h-10 w-10 bg-green-600 text-white rounded-xl hover:bg-green-700 disabled:opacity-40 disabled:cursor-not-allowed flex-shrink-0 flex items-center justify-center",children:(0,l.jsx)("svg",{className:"w-4 h-4",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2.2,children:(0,l.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M5 12h14M12 5l7 7-7 7"})})})]})]})]}):(0,l.jsx)("div",{className:"flex-1 flex items-center justify-center text-gray-400 text-sm",children:y("chat.select")})})]})}function g(){return(0,l.jsx)(s.Suspense,{fallback:(0,l.jsx)("div",{className:"text-center py-20 text-white",children:"..."}),children:(0,l.jsx)(h,{})})}},7016:(e,t,r)=>{Promise.resolve().then(r.bind(r,4251))}},e=>{e.O(0,[1516,9664,2838,9906,2982,587,18,7358],()=>e(e.s=7016)),_N_E=e.O()}]);
Save
cmd:
run