PageSourceSearch

https://slickinbox.ai/assets/Drafts-B0ct0AMQ.js

js slickinbox.ai collected 2026-10-05 15:05:07 UTC 8,742 bytes, 7 lines download raw bytes

1import{c as q,r as i,A as I,j as t,B as w,b,s as p}from"./index-ZkJ-s1rB.js";import{L as C,k as M,F as H,G as Q}from"./Layout-DJM8Nhr5.js";import{C as k}from"./checkbox-DKWDhTaI.js";import{E as Y}from"./EmptyState-CsbWFNEA.js";import{E as G}from"./ErrorAlert-DT1JNSTA.js";import{D as J,A as K,a as V,b as W,c as X,d as Z,e as ee,f as te,g as re}from"./alert-dialog-B6beMukR.js";import{T as E}from"./trash-2-DdrI1I0J.js";import{f as se}from"./formatDistanceToNow-DIxqAR2j.js";import"./card-BuXUi2qO.js";import"./textarea-8E-iyF7K.js";import"./index-3n2vhJSo.js";import"./en-US-DNUEYIb-.js";/**
2 * @license lucide-react v0.462.0 - ISC
3 *
4 * This source code is licensed under the ISC license.
5 * See the LICENSE file in the root directory of this source tree.
6 */const ae=q("Pencil",[["path",{d:"M21.174 6.812a1 1 0 0 0-3.986-3.987L3.842 16.174a2 2 0 0 0-.5.83l-1.321 4.352a.5.5 0 0 0 .623.622l4.353-1.32a2 2 0 0 0 .83-.497z",key:"1a8usu"}],["path",{d:"m15 5 4 4",key:"1mk7zo"}]]);function je(){const[A,v]=i.useState([]),[oe,y]=i.useState(!0),[L,D]=i.useState(null),[T,m]=i.useState(!1),[c,h]=i.useState(null),[_,g]=i.useState(!1),[N,S]=i.useState(null),[u,P]=i.useState(""),[l,f]=i.useState(new Set),{toast:d}=I(),x=async()=>{try{y(!0);const{data:{user:e},error:r}=await p.auth.getUser();if(r)throw new Error("Authentication error. Please log in again.");if(!e)throw new Error("User not found. Please log in.");const{data:s,error:a}=await p.from("drafts").select("*").eq("user_id",e.id).order("updated_at",{ascending:!1});if(a)throw console.error("Supabase error:",a),new Error(a.message||"Failed to fetch drafts");v(s||[]),D(null)}catch(e){console.error("Error loading drafts:",e),D(e.message||"Failed to load drafts"),d({title:"Error loading drafts",description:e.message||"Failed to load drafts. Please try again.",variant:"destructive"}),v([])}finally{y(!1)}};i.useEffect(()=>{x()},[]);const z=e=>{h(e),m(!0)},F=async()=>{if(N)try{const{error:e}=await p.from("drafts").delete().eq("id",N);if(e)throw console.error("Delete error:",e),new Error(e.message||"Failed to delete draft");d({title:"Draft deleted",description:"Your draft has been deleted successfully"}),await x()}catch(e){console.error("Error deleting draft:",e),d({title:"Error deleting draft",description:e.message||"Failed to delete draft. Please try again.",variant:"destructive"})}finally{g(!1),S(null)}},O=e=>{S(e),g(!0)},j=e=>{const r=document.createElement("div");return r.innerHTML=e,r.textContent||r.innerText||""},n=A.filter(e=>{var s,a;if(!u)return!0;const r=u.toLowerCase();return((s=e.to_recipients)==null?void 0:s.toLowerCase().includes(r))||((a=e.subject)==null?void 0:a.toLowerCase().includes(r))||j(e.body_html||"").toLowerCase().includes(r)}),U=e=>{f(e?new Set(n.map(r=>r.id)):new Set)},R=(e,r)=>{const s=new Set(l);r?s.add(e):s.delete(e),f(s)},B=async()=>{if(l.size!==0)try{const{error:e}=await p.from("drafts").delete().in("id",Array.from(l));if(e)throw console.error("Bulk delete error:",e),new Error(e.message||"Failed to delete drafts");d({title:"Drafts deleted",description:`${l.size} drafts deleted successfully`}),f(new Set),await x()}catch(e){console.error("Error deleting drafts:",e),d({title:"Error deleting drafts",description:e.message||"Failed to delete drafts. Please try again.",variant:"destructive"})}},$=()=>{try{if(n.length===0){d({title:"No drafts to export",description:"There are no drafts available to export."});return}const e=[["To","Subject","Preview","Updated"],...n.map(o=>[o.to_recipients||"(No recipients)",o.subject||"(No subject)",j(o.body_html||"").substring(0,100),new Date(o.updated_at).toLocaleDateString()])].map(o=>o.join(",")).join(`
7`),r=new Blob([e],{type:"text/csv"}),s=URL.createObjectURL(r),a=document.createElement("a");a.href=s,a.download=`drafts-${new Date().toISOString().split("T")[0]}.csv`,a.click(),URL.revokeObjectURL(s),d({title:"Export Complete",description:"Drafts exported successfully."})}catch(e){console.error("Export error:",e),d({title:"Export Failed",description:"Failed to export drafts. Please try again.",variant:"destructive"})}};return L?t.jsx(C,{children:t.jsx("div",{className:"p-4 sm:p-6",children:t.jsx(G,{message:"Unable to load your drafts. Please try again.",onRetry:()=>window.location.reload()})})}):t.jsx(C,{children:t.jsxs("div",{className:"w-full max-w-full px-4 sm:px-8 py-6 sm:py-8",children:[t.jsxs("div",{className:"mb-6",children:[t.jsxs("div",{className:"flex flex-col sm:flex-row items-start sm:items-center justify-between mb-4 gap-4",children:[t.jsxs("div",{children:[t.jsx("h1",{className:"text-2xl sm:text-3xl font-medium text-foreground mb-1",children:"Drafts"}
7),t.jsxs("p",{className:"text-sm text-foreground/60",children:[n.length," ",n.length===1?"draft":"drafts",u&&` matching "${u}"`]})]}),t.jsxs("div",{className:"flex items-center gap-2 w-full sm:w-auto",children:[t.jsxs(w,{variant:"minimal",size:"sm",onClick:$,className:"gap-1.5",children:[t.jsx(J,{className:"h-3.5 w-3.5"}),"Export"]}),t.jsxs(w,{variant:"default",size:"sm",onClick:()=>{h(null),m(!0)},className:"gap-1.5",children:[t.jsx(ae,{className:"h-3.5 w-3.5"}),"New Draft"]})]})]}),t.jsx("div",{className:"flex gap-3 items-center",children:t.jsxs("div",{className:"relative flex-1 max-w-md",children:[t.jsx(M,{className:"absolute left-4 top-1/2 -translate-y-1/2 h-4 w-4 text-foreground/40"}),t.jsx("input",{type:"text",placeholder:"Search drafts...",value:u,onChange:e=>P(e.target.value),className:"w-full bg-background border rounded-xl pl-11 pr-4 py-3 text-sm text-foreground placeholder:text-foreground/40 focus:outline-none focus:border-foreground/30 transition-colors shadow-lg"})]})}),l.size>0&&t.jsxs("div",{className:"flex items-center gap-2 mt-4 p-3 bg-muted/50 rounded-lg border",children:[t.jsxs("span",{className:"text-sm text-muted-foreground mr-2",children:[l.size," selected"]}),t.jsxs(w,{variant:"minimal",size:"sm",onClick:B,className:"gap-1.5 h-8 text-destructive hover:text-destructive",children:[t.jsx(E,{className:"h-3.5 w-3.5"}),"Delete"]})]})]}),t.jsx("div",{className:"bg-[hsl(39,100%,97%)] border rounded-lg overflow-hidden shadow-sm w-full",children:n.length===0?t.jsx(Y,{icon:H,title:"No Drafts",description:u?"No drafts match your search criteria":"Your draft emails will appear here",action:u?void 0:{label:"Create Draft",onClick:()=>{h(null),m(!0)}}}):t.jsxs("div",{children:[t.jsxs("div",{className:"flex items-center gap-4 px-6 py-3 border-b border-border/50 bg-muted/30",children:[t.jsx(k,{checked:l.size===n.length&&n.length>0,onCheckedChange:U,className:"flex-shrink-0"}),t.jsx("span",{className:"text-xs font-medium text-muted-foreground uppercase tracking-wide",children:l.size>0?`${l.size} of ${n.length}`:"Select All"})]}),n.map(e=>{const r=l.has(e.id),s=e.subject||"(No subject)",a=j(e.body_html||"");return t.jsxs("div",{className:b("flex items-center gap-4 px-6 py-4 cursor-pointer transition-all border-b border-border/30 group bg-[hsl(39,100%,97%)]","hover:bg-gradient-to-r hover:from-[hsl(220,9%,44%)] hover:to-[hsl(220,13%,18%)]",r&&"bg-primary/10"),onClick:()=>z(e),children:[t.jsx("div",{onClick:o=>o.stopPropagation(),children:t.jsx(k,{checked:r,onCheckedChange:o=>R(e.id,!!o),className:"flex-shrink-0"})}),t.jsx("div",{className:"flex-shrink-0 w-44",children:t.jsx("div",{className:b("truncate text-sm font-medium group-hover:text-[hsl(39,100%,97%)] text-foreground"),children:e.to_recipients||"(No recipients)"})}),t.jsxs("div",{className:"flex-1 min-w-0 flex items-center gap-2",children:[t.jsx("span",{className:b("text-sm font-medium truncate group-hover:text-[hsl(39,100%,97%)] text-foreground"),children:s}),a&&t.jsxs("span",{className:"text-sm text-muted-foreground group-hover:text-[hsl(39,100%,97%)] truncate hidden md:block",children:["— ",a]})]}),t.jsx("button",{onClick:o=>{o.stopPropagation(),O(e.id)},className:"flex-shrink-0 text-muted-foreground hover:text-destructive group-hover:text-[hsl(39,100%,97%)] transition-colors opacity-0 group-hover:opacity-100",children:t.jsx(E,{className:"h-4 w-4"})}),t.jsx("div",{className:"flex-shrink-0 text-xs text-muted-foreground group-hover:text-[hsl(39,100%,97%)] w-20 text-right",children:se(new Date(e.updated_at),{addSuffix:!0})})]},e.id)})]})}),t.jsx(Q,{open:T,onOpenChange:e=>{m(e),e||(h(null),x())},draftId:c==null?void 0:c.id,initialData:c?{to:c.to_recipients,cc:c.cc_recipients,bcc:c.bcc_recipients,subject:c.subject,body:c.body_html}:void 0}),t.jsx(K,{open:_,onOpenChange:g,children:t.jsxs(V,{children:[t.jsxs(W,{children:[t.jsx(X,{children:"Delete Draft"}),t.jsx(Z,{children:"Are you sure you want to delete this draft? This action cannot be undone."})]}),t.jsxs(ee,{children:[t.jsx(te,{children:"Cancel"}),t.jsx(re,{onClick:F,children:"Delete"})]})]})})]})})}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.