PageSourceSearch

https://tymora.ai/assets/SpamRulesSettings-CrWptrov.js

js tymora.ai collected 2026-10-05 14:06:57 UTC 10,778 bytes, 1 lines download raw bytes

1import{u as ne,d as ce,r,j as s,C as z,g as Q,h as U,i as q,k as I,B as n,I as w,P as $,s as c}from"./index-D2nTIUW6.js";import{L as E}from"./label-CqvUOikV.js";import{A as de}from"./AppSidebar-z8a-fGHs.js";import{c as me,d as ue}from"./useSubAccountAccess-DcruaA3L.js";import{C as j}from"./checkbox-CssqmpkD.js";import{T as he,a as pe,b as V,c as W}from"./tabs-DNTL1gGW.js";import{S as xe}from"./switch-DeNfWETS.js";import{P as fe}from"./plus-C5t7hVrC.js";import{T as b}from"./trash-2-CCEV_PQQ.js";import"./tymora-logo-light-BXiYSJSy.js";import"./tymora-logo-dark-DNZmS7Qy.js";import"./index-Cd_VlP8R.js";import"./phone-BvYrHctJ.js";import"./calendar-D_FPvrmV.js";import"./sparkles-DvPruXp3.js";import"./target-C1IqMhQ-.js";import"./shield-_bFRplVx.js";import"./chart-column-DpOlYG77.js";import"./chevron-down-Bac42aUA.js";import"./mail-2z0kfNQf.js";import"./instagram-B2JW29hO.js";import"./trending-up-DfYHHR-b.js";import"./building-2-2OWELtM3.js";import"./file-text-DPmRdMJZ.js";import"./video-BdmJ_s6b.js";import"./users-5MY5JoBQ.js";import"./book-open-CIK4t68s.js";import"./sheet-7Db38C20.js";import"./index-Dvy0CvIF.js";import"./index-OeKMS4_g.js";import"./index-DGqKI25R.js";import"./check-MbD2Kqf2.js";import"./index-CHONsatH.js";function Oe(){const D=ne(),{toast:i}=ce(),[H,K]=r.useState(!0),[A,_]=r.useState(!1),[a,x]=r.useState([]),[l,f]=r.useState([]),[L,S]=r.useState(""),[d,h]=r.useState([]),[m,p]=r.useState([]),[M,N]=r.useState(!1),[G,y]=r.useState(!1),[T,B]=r.useState(!1),[g,J]=r.useState(""),[v,O]=r.useState(""),[R,F]=r.useState(!1);r.useEffect(()=>{(async()=>{await k();const{data:{user:t}}=await c.auth.getUser();if(!t)return;const o=c.channel("spam-rules-changes").on("postgres_changes",{event:"UPDATE",schema:"public",table:"user_preferences",filter:`user_id=eq.${t.id}`},u=>{console.log("Spam rules updated:",u),k()}).subscribe();return()=>{c.removeChannel(o)}})()},[]);const k=async()=>{try{const{data:{user:e}}=await c.auth.getUser();if(!e){D("/auth");return}const{data:t,error:o}=await c.from("user_preferences").select("blocked_domains, blocked_emails, auto_delete_spam").eq("user_id",e.id).single();if(o)throw o;t&&(x((t.blocked_domains||[]).sort((u,C)=>u.localeCompare(C))),f((t.blocked_emails||[]).sort((u,C)=>u.localeCompare(C))),F(t.auto_delete_spam||!1))}catch(e){console.error("Error loading preferences:",e),i({title:"Error",description:"Failed to load spam rules",variant:"destructive"})}finally{K(!1)}},X=async()=>{_(!0);try{const{data:{user:e}}=await c.auth.getUser();if(!e)throw new Error("Not authenticated");const{error:t}=await c.from("user_preferences").update({blocked_domains:a,blocked_emails:l,auto_delete_spam:R}).eq("user_id",e.id);if(t)throw console.error("Supabase error:",t),t;i({title:"Success",description:"Spam rules saved"}),await k()}catch(e){console.error("Error saving preferences:",e),i({title:"Error",description:"Failed to save spam rules",variant:"destructive"})}finally{_(!1)}},Y=e=>/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(e),P=()=>{const e=L.trim().toLowerCase();if(e)if(Y(e)){if(l.includes(e)){i({title:"Already blocked",description:"This email is already in the block list",variant:"destructive"});return}f([...l,e].sort((t,o)=>t.localeCompare(o))),S(""),i({title:"Email added",description:"Don't forget to click Save Settings to persist changes"})}else{const t=e.startsWith("@")?e.substring(1):e;if(!t.includes(".")){i({title:"Invalid format",description:"Enter a valid domain (e.g., 'spam.com') or email address",variant:"destructive"});return}if(a.includes(t)){i({title:"Already blocked",description:"This domain is already in the block list",variant:"destructive"});return}x([...a,t].sort((o,u)=>o.localeCompare(u))),S(""),i({title:"Domain added",description:"Don't forget to click Save Settings to persist changes"})}},Z=e=>{x(a.filter(t=>t!==e)),h(d.filter(t=>t!==e))},ee=e=>{f(l.filter(t=>t!==e)),p(m.filter(t=>t!==e))},se=e=>{N(e),h(e?[...a]:[])},te=e=>{y(e),p(e?[...l]:[])},ae=(e,t)=>{t?h([...d,e]):(h(d.filter(o=>o!==e)),N(!1))},le=(e,t)=>{t?p([...m,e]):(p(m.filter(o=>o!==e)),y(!1))},re=()=>{x(a.filter(e=>!d.includes(e))),h([]),N(!1),i({title:"Domains removed",description:"Don't forget to click Save Settings to persist changes"})},ie=()=>{f(l.filter(e=>!m.includes(e))),p([]),y(!1),i({title:"Emails removed",description:"Don't forget to click Save Settings to persist changes"})},oe=async()=>{B(!0);try{const{data:e,error:t}=await c.functions.invoke("reclassify-conversations");
1if(t)throw t;i({title:"Success",description:e.message||`Reclassified ${e.updated} emails as spam`})}catch(e){console.error("Error reclassifying emails:",e),i({title:"Error",description:"Failed to reclassify existing emails",variant:"destructive"})}finally{B(!1)}};return H?s.jsx("div",{className:"min-h-screen bg-background flex items-center justify-center",children:s.jsx("p",{className:"text-muted-foreground",children:"Loading spam rules..."})}):s.jsx(me,{children:s.jsxs("div",{className:"min-h-screen flex w-full overflow-x-hidden",children:[s.jsx(de,{}),s.jsxs("div",{className:"flex-1 flex flex-col overflow-x-hidden",children:[s.jsxs("header",{className:"h-16 border-b bg-background flex items-center px-4 sm:px-6",children:[s.jsx(ue,{className:"mr-4"}),s.jsxs("div",{className:"min-w-0",children:[s.jsx("h1",{className:"text-xl sm:text-2xl font-bold truncate",children:"Spam Filter Rules"}),s.jsx("p",{className:"text-xs sm:text-sm text-muted-foreground truncate",children:"Manage blocked domains and spam filtering"})]})]}),s.jsx("main",{className:"flex-1 p-4 sm:p-8 pb-32 overflow-x-hidden",children:s.jsxs("div",{className:"max-w-4xl mx-auto space-y-6",children:[s.jsxs(z,{children:[s.jsxs(Q,{children:[s.jsx(U,{children:"Auto-Delete Spam"}),s.jsx(q,{children:"Automatically delete emails classified as spam instead of keeping them in the spam category"})]}),s.jsx(I,{children:s.jsxs("div",{className:"flex items-center justify-between",children:[s.jsxs("div",{className:"space-y-0.5",children:[s.jsx(E,{htmlFor:"auto-delete-spam",className:"text-base",children:"Auto-Delete Spam Emails"}),s.jsx("p",{className:"text-sm text-muted-foreground",children:"When enabled, emails classified as spam will be automatically deleted from your inbox"})]}),s.jsx(xe,{id:"auto-delete-spam",checked:R,onCheckedChange:F})]})})]}),s.jsxs(z,{children:[s.jsx(Q,{children:s.jsxs("div",{className:"flex items-start justify-between",children:[s.jsxs("div",{children:[s.jsx(U,{children:"Spam Filter Rules"}),s.jsx(q,{children:"Block emails from specific domains or individual email addresses"})]}),(a.length>0||l.length>0)&&s.jsx(n,{variant:"outline",onClick:oe,disabled:T,children:T?"Reclassifying...":"Apply to Existing Emails"})]})}),s.jsxs(I,{className:"space-y-4",children:[s.jsxs("div",{className:"flex gap-2",children:[s.jsx(w,{placeholder:"Enter email ([email protected]) or domain (spam.com)",value:L,onChange:e=>S(e.target.value),onKeyDown:e=>e.key==="Enter"&&P(),className:"flex-1"}),s.jsx(n,{onClick:P,size:"icon",children:s.jsx(fe,{className:"h-4 w-4"})})]}),s.jsxs(he,{defaultValue:"domains",className:"w-full",children:[s.jsxs(pe,{className:"grid w-full grid-cols-2",children:[s.jsxs(V,{value:"domains",children:["Blocked Domains (",a.length,")"]}),s.jsxs(V,{value:"emails",children:["Blocked Emails (",l.length,")"]})]}),s.jsxs(W,{value:"domains",className:"space-y-4",children:[a.length>0&&s.jsxs("div",{className:"relative mb-4",children:[s.jsx($,{className:"absolute left-3 top-1/2 transform -translate-y-1/2 h-4 w-4 text-muted-foreground"}),s.jsx(w,{placeholder:"Search domains...",value:g,onChange:e=>J(e.target.value),className:"pl-9"})]}),a.filter(e=>e.toLowerCase().includes(g.toLowerCase())).length>0&&s.jsxs("div",{className:"flex items-center gap-2 pb-2 border-b",children:[s.jsx(j,{id:"select-all-domains",checked:M,onCheckedChange:se}),s.jsx(E,{htmlFor:"select-all-domains",className:"text-sm font-medium cursor-pointer",children:"Select All"}),d.length>0&&s.jsxs(n,{variant:"destructive",size:"sm",onClick:re,className:"ml-auto",children:[s.jsx(b,{className:"h-4 w-4 mr-2"}),"Delete Selected (",d.length,")"]})]}),s.jsxs("div",{className:"space-y-2",children:[a.filter(e=>e.toLowerCase().includes(g.toLowerCase())).map(e=>s.jsxs("div",{className:"flex items-center gap-3 p-3 border rounded-lg bg-muted/50",children:[s.jsx(j,{checked:d.includes(e),onCheckedChange:t=>ae(e,t)}),s.jsx("span",{className:"font-mono text-sm flex-1",children:e}),s.jsx(n,{variant:"ghost",size:"icon",onClick:()=>Z(e),children:s.jsx(b,{className:"h-4 w-4 text-destructive"})})]},e)),a.length===0&&s.jsx("p",{className:"text-sm text-muted-foreground text-center py-8",children:"No domains blocked. Add domains to filter out spam from entire domains."}),a.length>0&&a.filter(e=>e.toLowerCase().includes(g.toLowerCase())).length===0&&s.jsx("p",{className:"text-sm text-muted-foreground text-center py-8",children:"No domains match your search."})]})]}),s.jsxs(W,{value:"emails",className:"space-y-4",children:[l.length>0&&s.jsxs("div",{className:"relative mb-4",children:[s.jsx($,{className:"absolute left-3 top-1/2 transform -translate-y-1/2 h-4 w-4 text-muted-foreground"}
1),s.jsx(w,{placeholder:"Search emails...",value:v,onChange:e=>O(e.target.value),className:"pl-9"})]}),l.filter(e=>e.toLowerCase().includes(v.toLowerCase())).length>0&&s.jsxs("div",{className:"flex items-center gap-2 pb-2 border-b",children:[s.jsx(j,{id:"select-all-emails",checked:G,onCheckedChange:te}),s.jsx(E,{htmlFor:"select-all-emails",className:"text-sm font-medium cursor-pointer",children:"Select All"}),m.length>0&&s.jsxs(n,{variant:"destructive",size:"sm",onClick:ie,className:"ml-auto",children:[s.jsx(b,{className:"h-4 w-4 mr-2"}),"Delete Selected (",m.length,")"]})]}),s.jsxs("div",{className:"space-y-2",children:[l.filter(e=>e.toLowerCase().includes(v.toLowerCase())).map(e=>s.jsxs("div",{className:"flex items-center gap-3 p-3 border rounded-lg bg-muted/50",children:[s.jsx(j,{checked:m.includes(e),onCheckedChange:t=>le(e,t)}),s.jsx("span",{className:"font-mono text-sm flex-1",children:e}),s.jsx(n,{variant:"ghost",size:"icon",onClick:()=>ee(e),children:s.jsx(b,{className:"h-4 w-4 text-destructive"})})]},e)),l.length===0&&s.jsx("p",{className:"text-sm text-muted-foreground text-center py-8",children:"No emails blocked. Add specific email addresses to block individual senders."}),l.length>0&&l.filter(e=>e.toLowerCase().includes(v.toLowerCase())).length===0&&s.jsx("p",{className:"text-sm text-muted-foreground text-center py-8",children:"No emails match your search."})]})]})]})]})]}),s.jsxs("div",{className:"flex justify-end gap-2",children:[s.jsx(n,{variant:"outline",onClick:()=>D("/dashboard/settings"),children:"Cancel"}),s.jsx(n,{onClick:X,disabled:A,children:A?"Saving...":"Save Settings"})]})]})})]})]})})}export{Oe 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.