PageSourceSearch

https://fleck.ai/assets/Inbox-D1M9xhjG.js

js fleck.ai collected 2026-10-05 14:00:52 UTC 16,180 bytes, 6 lines download raw bytes

1import{j as e}from"./vendor-query-CsHYnmF8.js";import{u as ee,r as c}from"./vendor-i18n-FzC2q7WE.js";import{s as u,b as k,L as M,B as y,S as O,A as se}from"./index-wKN3roZE.js";import{T as re}from"./textarea-WKa2Fxyq.js";import{u as te}from"./usePageMeta-h8XNEFq-.js";import{f as z}from"./fleck-icon-BELrtmeo.js";import{o as ae}from"./openProject-q_waxf97.js";import{l as ie,d as ne}from"./systemMessages-Dop0aCPJ.js";import{a as le}from"./vendor-react-CmGg2B8n.js";import{I as oe}from"./inbox-DeRUAS-v.js";import{M as W}from"./mail-open-CzN8wcAv.js";import{A as de}from"./arrow-left-B0M1U5r9.js";import{M as ce}from"./message-square-Dz5TmQ9S.js";import{S as me}from"./send-B2lUsY1u.js";import"./vendor-supabase-DinKeC8L.js";import"./vendor-ui-CakNjGXO.js";import"./ideas-BXcfQxWg.js";const Fe=()=>{var D,L;const{t,i18n:G}=ee(),H=(D=G.language)==null?void 0:D.startsWith("fa"),b=le(),[m,J]=c.useState(null),[j,F]=c.useState([]),[v,A]=c.useState([]),[a,_]=c.useState(null),[K,w]=c.useState([]),[Q,S]=c.useState(!0),[V,E]=c.useState(!1),[N,I]=c.useState(""),[P,$]=c.useState(!1),p=c.useMemo(()=>a!=null&&a.startsWith("sys:")?v.find(s=>`sys:${s.id}`===a)??null:null,[a,v]),X=async s=>{const r=s.match(/^fleck:(project|publish)\/(.+)$/);if(!r){b(s);return}const n=r[1]==="publish",l=r[2],{data:d,error:f}=await u.from("ideas").select("id,name,original_idea,rephrased_idea,mvp_features,mode").eq("id",l).maybeSingle();if(f||!d){k.error(t("inbox.projectMissing","Could not open that project.")),b("/fleck-agent");return}await ae(b,{id:d.id,name:d.name,original_idea:d.original_idea,rephrased_idea:d.rephrased_idea,mvp_features:d.mvp_features,mode:d.mode,has_generated_code:!0},n?{extraState:{autoPublish:!0}}:{})};te({title:"Messages — Fleck",description:"Message designers and manage showcase inquiries — all inside Fleck."}),c.useEffect(()=>{(async()=>{const{data:s}=await u.auth.getUser();if(!s.user){b("/auth?redirect=/inbox");return}J(s.user.id),window.dispatchEvent(new CustomEvent("fleck:messages-read"));try{const{error:r}=await u.rpc("mark_incoming_messages_read");if(r)throw r}catch(r){console.warn("[inbox] unable to mark messages as read",r)}try{await u.from("system_messages").update({read_at:new Date().toISOString()}).eq("user_id",s.user.id).is("read_at",null)}catch(r){console.warn("[inbox] unable to mark system messages as read",r)}window.dispatchEvent(new CustomEvent("fleck:messages-read"))})()},[b]),c.useEffect(()=>{if(!m)return;let s=!0;return(async()=>{S(!0);const{data:r,error:n}=await u.from("conversations").select(`
2          id, subject, status, opportunity_status, last_message_at, created_at,
3          public_project_id, guest_sender_id, sender_user_id, designer_user_id,
4          guest_senders ( name, company ),
5          public_projects ( title, slug )
6        `).or(`designer_user_id.eq.${m},sender_user_id.eq.${m}`).order("last_message_at",{ascending:!1,nullsFirst:!1});if(!s)return;if(n){k.error(n.message),F([]),S(!1);return}const l=r??[],d=Array.from(new Set(l.map(i=>i.designer_user_id===m?i.sender_user_id:i.designer_user_id).filter(i=>!!i))),f=Array.from(new Set(l.map(i=>i.designer_user_id)));let C={};if(d.length>0){const{data:i}=await u.from("profiles").select("user_id, display_name, first_name, last_name").in("user_id",d);(i??[]).forEach(o=>{const g=o.display_name||[o.first_name,o.last_name].filter(Boolean).join(" ")||"";g&&(C[o.user_id]=g)})}let T={};if(f.length>0){const{data:i}=await u.from("designer_profiles").select("user_id, public_name, username, professional_title, avatar_url").in("user_id",f);(i??[]).forEach(o=>{T[o.user_id]={name:o.public_name||o.username||"",title:o.professional_title||null,avatar:o.avatar_url||null}})}const q=l.map(i=>{var U;const o=i.designer_user_id===m?"designer":"sender";let g,R=null,B=null;if(o==="designer")g=i.sender_user_id?C[i.sender_user_id]||t("inbox.member","Fleck member"):((U=i.guest_senders)==null?void 0:U.name)||t("inbox.member","Fleck member");else{const h=T[i.designer_user_id];g=(h==null?void 0:h.name)||C[i.designer_user_id]||t("inbox.member","Fleck member"),R=(h==null?void 0:h.title)||null,B=(h==null?void 0:h.avatar)||null}return{...i,_role:o,_counterpartName:g,_counterpartTitle:R,_counterpartAvatar:B}});F(q);const{data:Z}=await ie(m);s&&A(Z??[]);try{const o=new URLSearchParams(window.location.search).get("c");o&&q.some(g=>g.id===o)&&_(o)}catch{}S(!1)})(),()=>{s=!1}},[m,t]),c.useEffect(()=>{if(!a){w([]);return}let s=!0;return(async()=>{E(!0);const{data:r}=await u.from("messages").select("id, body, sender_type, sender_user_id, created_at, read_at").eq("conversation_id",a).order("created_at",{ascending:!0});if(!s)return;if(w(r??[]),E(!1),(r??[]).filter(l=>l.sender_user_id!==m&&!l.read_at).length>0){const{error:l}=await u.rpc("mark_incoming_messages_read",{_conversation_id:a});l||(w(d=>d.map(f=>f.sender_user_id!==m&&!f.read_at?{...f,read_at:new Date().toISOString()}:f)),window.dispatchEvent(new CustomEvent("fleck:messages-read")))}})(),()=>{s=!1}},[a,m]);const x=c.useMemo(()=>j.find(s=>s.id===a)||null,[j,a]),Y=async()=>
6{if(!a||!m||!x||N.trim().length<1)return;const s=N.trim(),r=x._role==="designer";$(!0);try{const{error:n}=await u.from("messages").insert({conversation_id:a,sender_type:r?"designer":"user",sender_user_id:m,body:s});if(n)throw n;await u.from("conversations").update({last_message_at:new Date().toISOString()}).eq("id",a),I("");const{data:l}=await u.from("messages").select("id, body, sender_type, sender_user_id, created_at, read_at").eq("conversation_id",a).order("created_at",{ascending:!0});w(l??[]),u.functions.invoke("notify-conversation",{body:{conversation_id:a}}).catch(d=>console.warn("[inbox] notify failed",d)),k.success(t("inbox.replySent","Reply sent"))}catch(n){k.error((n==null?void 0:n.message)||"Failed to send reply")}finally{$(!1)}};return e.jsx("div",{className:"min-h-screen bg-background",dir:H?"rtl":"ltr",children:e.jsxs("div",{className:"mx-auto max-w-6xl px-4 sm:px-6 py-6 sm:py-10",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-6",children:[e.jsx(oe,{className:"w-5 h-5 text-primary"}),e.jsx("h1",{className:"text-xl font-semibold",children:t("inbox.title","Messages")})]}),Q?e.jsx("div",{className:"flex items-center justify-center py-16",children:e.jsx(M,{className:"w-5 h-5 animate-spin text-muted-foreground"})}):j.length===0&&v.length===0?e.jsxs("div",{className:"relative overflow-hidden rounded-3xl border border-border/60 bg-card px-6 py-16 sm:py-20",children:[e.jsx("div",{"aria-hidden":!0,className:"pointer-events-none absolute inset-0 opacity-40",style:{background:"radial-gradient(60% 50% at 50% 0%, hsl(184 55% 38% / 0.25), transparent 70%), radial-gradient(40% 40% at 20% 90%, hsl(280 70% 60% / 0.18), transparent 70%), radial-gradient(40% 40% at 85% 85%, hsl(30 90% 60% / 0.18), transparent 70%)"}}),e.jsxs("div",{className:"relative mx-auto max-w-md text-center flex flex-col items-center gap-5",children:[e.jsx("div",{className:"w-16 h-16 rounded-2xl bg-primary/10 ring-1 ring-primary/20 flex items-center justify-center",children:e.jsx(W,{className:"w-8 h-8 text-primary"})}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("h2",{className:"text-xl sm:text-2xl font-semibold tracking-tight",children:t("inbox.emptyTitle","No messages yet")}),e.jsx("p",{className:"text-sm text-muted-foreground leading-relaxed",children:t("inbox.emptyBodyBoth","Conversations with designers and clients live here. Publish your work to be discovered, or explore Portfolio to reach out to a designer.")})]}),e.jsxs("div",{className:"flex flex-col sm:flex-row items-center gap-2 pt-1",children:[e.jsx(y,{onClick:()=>b("/dashboard?tab=showcase"),className:"rounded-full",children:t("inbox.emptyCta","Publish to Portfolio")}),e.jsx(y,{variant:"ghost",onClick:()=>b("/portfolio"),className:"rounded-full",children:t("inbox.emptyExplore","Explore")})]})]})]}):e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-[320px_1fr] gap-4 min-h-[60vh]",children:[e.jsx("div",{className:`rounded-2xl border border-border/60 bg-card overflow-hidden ${a?"hidden md:block":""}`,children:e.jsxs("ul",{className:"space-y-2 max-h-[70vh] overflow-y-auto p-2",children:[v.map(s=>{const r=`sys:${s.id}`,n=a===r,l=!s.read_at;return e.jsx("li",{children:e.jsx("button",{type:"button",onClick:()=>_(r),className:`w-full text-left p-3 rounded-xl border bg-background hover:border-primary/40 hover:shadow-sm transition ${n?"border-primary/50 shadow-sm bg-primary/5":"border-border/60"}`,children:e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx("div",{className:"w-9 h-9 rounded-full overflow-hidden bg-primary/10 ring-1 ring-primary/20 flex items-center justify-center flex-shrink-0",children:e.jsx("img",{src:z,alt:"Fleck",className:"w-5 h-5"})}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsxs("p",{className:"text-sm font-semibold truncate flex items-center gap-1.5",children:["Fleck",l&&e.jsx("span",{className:"w-1.5 h-1.5 rounded-full bg-primary","aria-hidden":!0})]}),e.jsx("span",{className:"text-[10px] text-muted-foreground shrink-0",children:new Date(s.created_at).toLocaleDateString()})]}),e.jsx("p",{className:"text-xs text-foreground truncate mt-0.5",children:s.title}),e.jsx("p",{className:"text-xs text-muted-foreground truncate mt-0.5",children:s.body}),e.jsx("div",{className:"flex items-center gap-1.5 mt-1.5",children:e.jsxs("span",{className:"inline-flex items-center gap-1 text-[10px] rounded-full bg-primary/10 text-primary px-2 py-0.5",children:[e.jsx(O,{className:"w-2.5 h-2.5"}),t("inbox.fromFleck","From Fleck")]})})]})]})})},r)}),j.map(s=>{var l;const r=(s._counterpartName||"F").split(" ").map(d=>
6d[0]).filter(Boolean).slice(0,2).join("").toUpperCase(),n=a===s.id;return e.jsx("li",{children:e.jsx("button",{type:"button",onClick:()=>_(s.id),className:`w-full text-left p-3 rounded-xl border bg-background hover:border-primary/40 hover:shadow-sm transition ${n?"border-primary/50 shadow-sm bg-primary/5":"border-border/60"}`,children:e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx("div",{className:"w-9 h-9 rounded-full overflow-hidden bg-primary/10 ring-1 ring-primary/20 flex items-center justify-center flex-shrink-0",children:s._counterpartAvatar?e.jsx("img",{src:s._counterpartAvatar,alt:s._counterpartName,className:"w-full h-full object-cover"}):e.jsx("span",{className:"text-[11px] font-semibold text-primary",children:r})}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsx("p",{className:"text-sm font-semibold truncate",children:s._counterpartName}),e.jsx("span",{className:"text-[10px] text-muted-foreground shrink-0",children:new Date(s.last_message_at||s.created_at).toLocaleDateString()})]}),s._counterpartTitle&&e.jsx("p",{className:"text-xs text-primary truncate mt-0.5",children:s._counterpartTitle}),((l=s.public_projects)==null?void 0:l.title)&&e.jsx("p",{className:"text-xs text-muted-foreground truncate mt-0.5",children:s.public_projects.title}),e.jsxs("div",{className:"flex items-center gap-1.5 mt-1.5 flex-wrap",children:[e.jsx("span",{className:`inline-block text-[10px] rounded-full px-2 py-0.5 ${s._role==="designer"?"bg-primary/10 text-primary":"bg-muted text-muted-foreground"}`,children:s._role==="designer"?t("inbox.roleIncoming","Incoming"):t("inbox.roleSent","Sent")}),s.opportunity_status&&e.jsx("span",{className:"inline-block text-[10px] rounded-full bg-primary/10 text-primary px-2 py-0.5",children:s.opportunity_status.replace("_"," ")})]})]})]})})},s.id)})]})}),e.jsx("div",{className:`rounded-2xl border border-border/60 bg-card flex flex-col min-h-[60vh] ${a?"flex":"hidden md:flex"}`,children:p?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"p-4 border-b border-border/60 flex items-start gap-3",children:[e.jsx("div",{className:"w-11 h-11 rounded-full overflow-hidden bg-primary/10 ring-1 ring-primary/20 flex items-center justify-center flex-shrink-0",children:e.jsx("img",{src:z,alt:"Fleck",className:"w-6 h-6"})}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("p",{className:"text-sm font-semibold flex items-center gap-1.5",children:["Fleck",e.jsx(O,{className:"w-3 h-3 text-primary"})]}),e.jsx("p",{className:"text-[11px] text-muted-foreground mt-0.5",children:new Date(p.created_at).toLocaleString()})]}),e.jsx(y,{variant:"ghost",size:"sm",className:"text-xs text-muted-foreground",onClick:async()=>{const s=p.id;A(r=>r.filter(n=>n.id!==s)),_(null),await ne(s)},children:t("inbox.dismiss","Dismiss")})]}),e.jsxs("div",{className:"flex-1 p-6 space-y-4 overflow-y-auto",children:[e.jsx("h3",{className:"text-lg font-semibold tracking-tight",children:p.title}),e.jsx("p",{className:"text-sm text-muted-foreground whitespace-pre-wrap leading-relaxed",children:p.body}),p.action_label&&p.action_route&&e.jsx("div",{children:e.jsxs(y,{onClick:()=>void X(p.action_route),className:"gap-2 rounded-full",children:[p.action_label,e.jsx(se,{className:"w-3.5 h-3.5"})]})})]})]}):x?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"p-4 border-b border-border/60 flex items-start gap-3",children:[e.jsx("div",{className:"w-11 h-11 rounded-full overflow-hidden bg-primary/10 ring-1 ring-primary/20 flex items-center justify-center flex-shrink-0",children:x._counterpartAvatar?e.jsx("img",{src:x._counterpartAvatar,alt:x._counterpartName,className:"w-full h-full object-cover"}):e.jsx("span",{className:"text-sm font-semibold text-primary",children:(x._counterpartName||"F").split(" ").map(s=>s[0]).filter(Boolean).slice(0,2).join("").toUpperCase()})}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("button",{type:"button",onClick:()=>_(null),className:"md:hidden inline-flex items-center gap-1 text-xs text-muted-foreground mb-1",children:[e.jsx(de,{className:"w-3.5 h-3.5"})," ",t("common.back","Back")]}),e.jsx("p",{className:"text-sm font-semibold truncate",children:x._counterpartName}),x._counterpartTitle&&e.jsx("p",{className:"text-xs text-primary truncate mt-0.5",children:x._counterpartTitle}),((L=x.public_projects)==null?void 0:L.title)&&e.jsx("p",{className:"text-xs text-muted-foreground truncate mt-0.5",children:x.public_projects.title})]})]}),e.jsx("div",{className:"flex-1 overflow-y-auto p-4 space-y-3 max-h-[55vh]",children:V?e.jsx(M,{className:"w-4 h-4 animate-spin text-muted-foreground mx-auto"}):K.map(s=>{const r=s.sender_user_id===m;return e.jsxs("div",{className:`flex gap-2 ${r?"justify-end":"justify-start"}`,children:[!r&&e.jsx("div",{className:"w-6 h-6 rounded-full bg-primary/10 flex items-center justify-center flex-shrink-0 mt-0.5",children:e.jsx(ce,{className:"w-3 h-3 text-primary"})}),e.jsxs("div",{className:`max-w-[85%] px-4 py-2.5 text-xs leading-relaxed text-left ${r?"bg-primary/15 text-foreground rounded-2xl rounded-tr-none":"bg-muted/60 text-foreground border border-border/40 rounded-2xl rounded-tl-none"}`,children:[e.jsx("p",{className:"whitespace-pre-wrap",children:s.body}),e.jsx("p",{className:"text-[10px] mt-1 text-muted-foreground",children:new Date(s.created_at).toLocaleStr
6ing()})]})]},s.id)})}),e.jsx("div",{className:"border-t border-border/60 p-3",children:e.jsxs("div",{className:"relative rounded-xl border border-border/60 bg-muted/30 focus-within:border-primary/50 transition",children:[e.jsx(re,{value:N,onChange:s=>I(s.target.value),placeholder:t("inbox.replyPlaceholder","Write a reply…"),rows:1,className:"resize-none border-0 bg-transparent focus-visible:ring-0 focus-visible:ring-offset-0 pr-12 pb-1 min-h-[44px]"}),e.jsx(y,{size:"icon",onClick:Y,disabled:P||N.trim().length===0,"aria-label":t("inbox.reply","Reply"),title:t("inbox.reply","Reply"),className:"absolute bottom-1.5 right-1.5 h-8 w-8 rounded-full shadow-sm",children:P?e.jsx(M,{className:"w-3.5 h-3.5 animate-spin"}):e.jsx(me,{className:"w-3.5 h-3.5"})})]})})]}):e.jsx("div",{className:"flex-1 flex items-center justify-center text-sm text-muted-foreground",children:e.jsxs("div",{className:"text-center",children:[e.jsx(W,{className:"w-8 h-8 text-muted-foreground/50 mx-auto mb-2"}),t("inbox.selectPrompt","Select a conversation to read.")]})})})]})]})})};export{Fe 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.