PageSourceSearch

https://zapdata.co/_releases/admin/assets/NotifyAdminPage-zQqybgve.js

js zapdata.co collected 2026-10-02 01:22:57 UTC 16,750 bytes, 1 lines download raw bytes

1import{d as Ae,r as d,j as e}from"./react-vendor-CQjOo-Vj.js";import{a as Ce,an as Le,u as ke,t as r,aE as Se,ad as B,B as m,aA as te,bx as De,c as ne,C,w as L,x as k,bq as Ie,aF as S,y as D,L as I,b as F,d as z,e as R,f as H,g as U,U as Me,a8 as O,aH as Ee,X as Te,aM as ae,J as V,b6 as W,z as qe,m as Pe,n as Be,o as Fe,q as ze,r as Re,I as He,s as Ue}from"./App-B-9YH1AD.js";import{s as c}from"./index-DdOu1uvL.js";import{f as M}from"./phoneFormatter-Cv-TSM1Y.js";import{L as J}from"./zernioPopup-BqWuxn6F.js";import{R as Oe}from"./refresh-cw-ClHeqbQi.js";import{P as X}from"./plus-B8uP4sl6.js";import{P as Ve}from"./phone-CoTQvLVp.js";import{C as We}from"./chart-column-CaaAIcGj.js";import{P as Je}from"./pencil-CU32j5zN.js";import{W as Xe}from"./wifi-off-DcAQGh4u.js";import{W as Ge}from"./wifi-DavK7w4N.js";import{S as re}from"./shopping-bag-LejHjwp2.js";import"./supabase-zVFFtMAE.js";import"./countryDdi-BvyH1gQc.js";function ls(){const{t:i}=Ce(["tools","common"]),E=Ae(),{user:o}=Le(),{effectiveUserId:u}=ke(),[G,oe]=d.useState([]),[l,K]=d.useState(null),[T,de]=d.useState([]),[Q,ce]=d.useState([]),[Y,le]=d.useState([]),[me,fe]=d.useState(!0),[j,p]=d.useState(!1),[Z,$]=d.useState(!1),[y,ee]=d.useState(""),[f,q]=d.useState([]),[xe,g]=d.useState(!1),[N,P]=d.useState(null),[v,_]=d.useState(""),[b,w]=d.useState(30),x=d.useCallback(async()=>{const s=u||(o==null?void 0:o.id);if(s)try{const{data:t}=await c.from("maturador_instances").select("id, instance_name, phone_number, label, status").eq("user_id",s).order("created_at",{ascending:!1});oe(t||[]);const{data:n}=await c.from("admin_notify_configs").select("*").eq("user_id",s).maybeSingle();if(n){K(n),ee(n.notifier_instance_id||""),q(n.admin_instance_ids||[]);const{data:a}=await c.from("admin_notify_lead_limits").select("*").eq("config_id",n.id);de(a||[]);const{data:be}=await c.from("admin_notify_instance_monitor").select("*").eq("config_id",n.id);ce(be||[]);const{data:we}=await c.from("admin_notify_sales_monitor").select("*").eq("config_id",n.id);le(we||[])}}catch(t){console.error("Error fetching data:",t),r.error(i("notifyAdmin.errors.loadData"))}finally{fe(!1),$(!1)}},[o,u]);d.useEffect(()=>{x()},[x]);const he=async()=>{const s=u||(o==null?void 0:o.id);if(s){if(!y){r.error(i("notifyAdmin.errors.selectNotifier"));return}if(f.length===0){r.error(i("notifyAdmin.errors.selectAdmin"));return}p(!0);try{if(l){const{error:t}=await c.from("admin_notify_configs").update({notifier_instance_id:y,admin_instance_ids:f}).eq("id",l.id);if(t)throw t}else{const{data:t,error:n}=await c.from("admin_notify_configs").insert({user_id:s,notifier_instance_id:y,admin_instance_ids:f}).select().single();if(n)throw n;K(t)}r.success(i("notifyAdmin.toasts.configSaved")),x()}catch(t){console.error("Error saving config:",t),r.error(t.message||i("notifyAdmin.errors.saveConfig"))}finally{p(!1)}}},ue=async()=>{if(!l){r.error(i("notifyAdmin.errors.saveMainConfigFirst"));return}if(!v){r.error(i("notifyAdmin.errors.selectInstance"));return}const s=u||(o==null?void 0:o.id);if(!s)return;const t=T.find(n=>n.instance_id===v);p(!0);try{if(t){const{error:n}=await c.from("admin_notify_lead_limits").update({daily_limit:b,is_active:!0}).eq("id",t.id);if(n)throw n;r.success(i("notifyAdmin.toasts.limitUpdated"))}else{const{error:n}=await c.from("admin_notify_lead_limits").insert({user_id:s,config_id:l.id,instance_id:v,daily_limit:b,is_active:!0});if(n)throw n;r.success(i("notifyAdmin.toasts.limitAdded"))}g(!1),_(""),w(30),P(null),x()}catch(n){console.error("Error adding/updating lead limit:",n),r.error(n.message||i("notifyAdmin.errors.addLimit"))}finally{p(!1)}},ge=s=>{P(s),_(s.instance_id),w(s.daily_limit),g(!0)},je=async(s,t)=>{try{const{error:n}=await c.from("admin_notify_lead_limits").update({is_active:!t}).eq("id",s);if(n)throw n;x()}catch(n){console.error("Error toggling lead limit:",n),r.error(i("notifyAdmin.errors.updateLimit"))}},pe=async s=>{try{const{error:t}=await c.from("admin_notify_lead_limits").delete().eq("id",s);if(t)throw t;r.success(i("notifyAdmin.toasts.limitRemoved")),x()}catch(t){console.error("Error deleting lead limit:",t),r.error(i("notifyAdmin.errors.removeLimit"))}},ye=async s=>{if(!l){r.error(i("notifyAdmin.errors.saveMainConfigFirst"));return}const t=u||(o==null?void 0:o.id);if(!t)return;const n=Q.find(a=>a.instance_id===s);try{if(n){const{error:a}=await c.from("admin_notify_instance_monitor").update({is_active:!n.is_active}).eq("id",n.id);if(a)throw a}else{const{error:a}=await c.from("admin_notify_instance_monitor").insert({user_id:t,config_id:l.id,instance_id:s,is_active:!0});if(a)throw a}x()}catch(a){console.error("Error toggling instance monitor:",a),r.error(i("notifyAdmin.errors.updateMonitor"))}},Ne=async s=>{if(!l){r.error(i("notifyAdmin.errors.saveMainConfigFirst"));return}const t=u||(o==null?void 0:o.id);if(!t)return;const n=Y.find(a=>a.instance_id===s);try{if(n){const{error:a}=await c.from("admin_notify_sales_monitor").update({is_active:!n.is_active}).eq("id",n.id);if(a)throw a}else{const{error:a}=await c.from("admin_notify_sales_monitor").insert({user_id:t,config_id:l.id,instance_id:s,is_active:!0});if(a)throw a}x()}catch(a){console.error("Error toggling sales monitor:",a),r.error(i("notifyAdmin.errors.updateMonitor"))}},A=s=>{const t=G.find(n=>n.id===s);return t?t.phone_number?M(t.phone_number):t.label||t.instance_name:i("notifyAdmin.unknownNumber")},ve=s=>{s&&!f.includes(s)&&q([...f,s])},_e=s=>{q(f.filter(t=>t!==s))},h=G.filter(s=>s.status==="connected"),se=h,ie=h.filter(s=>
1!f.includes(s.id));return me?e.jsx("div",{className:"min-h-screen bg-background flex items-center justify-center",children:e.jsxs("div",{className:"text-center space-y-4",children:[e.jsx(J,{className:"h-12 w-12 animate-spin text-primary mx-auto"}),e.jsx("p",{className:"text-muted-foreground",children:i("notifyAdmin.loadingConfig")})]})}):e.jsxs("div",{className:"min-h-screen bg-background",children:[e.jsx(Se,{}),e.jsx("div",{className:"h-14 md:h-16"}),e.jsxs("div",{className:"container mx-auto px-4 py-8 max-w-6xl relative",children:[e.jsx("div",{className:"absolute inset-0 bg-background/60 backdrop-blur-md z-50 flex flex-col items-center justify-center rounded-lg",children:e.jsxs("div",{className:"text-center space-y-4",children:[e.jsx("div",{className:"p-4 rounded-full bg-muted inline-block",children:e.jsx(B,{className:"h-12 w-12 text-muted-foreground"})}),e.jsx("h2",{className:"text-2xl font-bold text-foreground",children:i("notifyAdmin.comingSoon.title")}),e.jsx("p",{className:"text-muted-foreground max-w-md",children:i("notifyAdmin.comingSoon.description")}),e.jsxs(m,{variant:"outline",onClick:()=>E("/inbox"),children:[e.jsx(te,{className:"h-4 w-4 mr-2"}),i("notifyAdmin.comingSoon.backToInbox")]})]})}),e.jsxs("div",{className:"flex items-center justify-between mb-8",children:[e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsx(m,{variant:"ghost",size:"icon",onClick:()=>E("/inbox"),children:e.jsx(te,{className:"h-5 w-5"})}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"p-2 rounded-lg bg-gradient-to-r from-amber-400 to-orange-500",children:e.jsx(De,{className:"h-6 w-6 text-white"})}),e.jsxs("div",{children:[e.jsx("h1",{className:"text-2xl font-bold",children:i("notifyAdmin.title")}),e.jsx("p",{className:"text-muted-foreground",children:i("notifyAdmin.subtitle")})]})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs(m,{variant:"outline",onClick:()=>{$(!0),x()},disabled:Z,children:[e.jsx(Oe,{className:ne("h-4 w-4 mr-2",Z&&"animate-spin")}),i("common:actions.refresh")]}),e.jsxs(m,{onClick:()=>E("/inbox/notify-admin/add-number"),children:[e.jsx(X,{className:"h-4 w-4 mr-2"}),i("notifyAdmin.newNumber")]})]})]}),e.jsxs(C,{className:"mb-8",children:[e.jsxs(L,{children:[e.jsxs(k,{className:"flex items-center gap-2",children:[e.jsx(Ie,{className:"h-5 w-5"}),i("notifyAdmin.mainConfig.title")]}),e.jsx(S,{children:i("notifyAdmin.mainConfig.description")})]}),e.jsxs(D,{children:[e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-6",children:[e.jsxs("div",{className:"space-y-3",children:[e.jsxs(I,{className:"flex items-center gap-2",children:[e.jsx(Ve,{className:"h-4 w-4"}),i("notifyAdmin.mainConfig.notifierLabel")]}),e.jsx("p",{className:"text-sm text-muted-foreground",children:i("notifyAdmin.mainConfig.notifierDescription")}),e.jsxs(F,{value:y,onValueChange:ee,children:[e.jsx(z,{children:e.jsx(R,{placeholder:i("notifyAdmin.mainConfig.selectNumberPlaceholder")})}),e.jsx(H,{children:h.map(s=>e.jsx(U,{value:s.id,children:s.phone_number?M(s.phone_number):s.label||s.instance_name},s.id))})]})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs(I,{className:"flex items-center gap-2",children:[e.jsx(Me,{className:"h-4 w-4"}),i("notifyAdmin.mainConfig.adminLabel")]}),e.jsx("p",{className:"text-sm text-muted-foreground",children:i("notifyAdmin.mainConfig.adminDescription")}),e.jsxs(F,{value:"",onValueChange:ve,children:[e.jsx(z,{children:e.jsx(R,{placeholder:i("notifyAdmin.mainConfig.selectToAddPlaceholder")})}),e.jsx(H,{children:ie.length===0?e.jsx("div",{className:"p-2 text-sm text-muted-foreground text-center",children:i("notifyAdmin.mainConfig.allAdded")}):ie.map(s=>e.jsx(U,{value:s.id,children:s.phone_number?M(s.phone_number):s.label||s.instance_name},s.id))})]}),f.length>0&&e.jsx("div",{className:"flex flex-wrap gap-2 mt-2",children:f.map(s=>e.jsxs(O,{variant:"secondary",className:"flex items-center gap-1 py-1 px-2",children:[e.jsx(Ee,{className:"h-3 w-3"}),A(s),e.jsx("button",{onClick:()=>_e(s),className:"ml-1 hover:text-destructive transition-colors",children:e.jsx(Te,{className:"h-3 w-3"})})]},s))})]})]}),e.jsx("div",{className:"mt-6 flex justify-end",children:e.jsxs(m,{onClick:he,disabled:j,children:[j?e.jsx(J,{className:"h-4 w-4 mr-2 animate-spin"}):e.jsx(ae,{className:"h-4 w-4 mr-2"}),i("notifyAdmin.mainConfig.save")]})})]})]}),e.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-3 gap-6",children:[e.jsxs(C,{children:[e.jsxs(L,{children:[e.jsxs(k,{className:"flex items-center gap-2 text-lg",children:[e.jsx(We,{className:"h-5 w-5 text-blue-500"}),i("notifyAdmin.leadLimit.title")]}),e.jsx(S,{children:i("notifyAdmin.leadLimit.description")})]}),e.jsxs(D,{className:"space-y-4",children:[e.jsxs("div",{className:"bg-muted/50 p-3 rounded-lg flex items-start gap-2",children:[e.jsx(V,{className:"h-4 w-4 text-blue-500 mt-0.5 flex-shrink-0"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:i("notifyAdmin.leadLimit.resetInfo")})]}),T.length>0?e.jsx("div",{className:"space-y-3",children:T.map(s=>e.jsxs("div",{className:ne("flex items-center justify-between p-3 rounded-lg border",s.is_active?"bg-card":"bg-muted/30 opacity-60"),children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(W,{checked:s.is_active,onCheckedChange:()=>je(s.id,s.is_active),className:"data-[state=checked]:bg-green-500 data-[state=unchecked]:bg-red-500"}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium",children:A(s.instance_id)}),e.jsx("p",{className:"text-xs text-muted-foreground",children:i("notifyAdmin.leadLimit.limitLine",{count:s.daily_limit})})]})]}),e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(m,{variant:"ghost",size:"icon",className:"h-8 w-8 text-muted-foreground hover:text-foreground",onClick:()=>ge(s),children:e.jsx(Je,{className:"h-4 w-4"})}),e.jsx(m,{variant:"ghost",size:"icon",className:"h-8 w-8 text-destructive",onClick:()=>pe(s.id),children:e.jsx(qe,{className:"h-4 w-4"})})]})]},s.id))}):e.jsx("p",{className:"text-sm text-muted-foreground text-center py-4",children:i("notifyAdmin.leadLimit.noneConfigured")}),e.jsxs(m,{variant:"outline",className:"w-full",onClick:()=>{P(null),_(""),w(30),g(!0)},disabled:!l||se.length===0,children:[e.jsx(X,{className:"h-4 w-4 mr-2"}),i("notifyAdmin.leadLimit.addNumber")]})]})]}),e.jsxs(C,{className:"relative overflow-hidden",children:[e.jsxs("div",{className:"absolute inset-0 bg-background/80 backdrop-blur-sm z-10 flex flex-col items-center justify-center",children:[e.jsx(B,{className:"h-8 w-8 text-muted-foreground mb-2"}),e.jsx("p",{className:"text-sm font-medium text-muted-foreground",children:i("notifyAdmin.comingSoonBadge")})]}),e.jsxs(L,{children:[e.jsxs(k,{className:"flex items-center gap-2 text-lg",children:[e.jsx(Xe,{className:"h-5 w-5 text-red-500"}),i("notifyAdmin.instanceDisconnected.title")]}),e.jsxs(S,{children:[i("notifyAdmin.instanceDisconnected.descriptionBefore")," ",e.jsx(O,{variant:"outline",className:"text-xs",children:"#status"})," ",i("notifyAdmin.instanceDisconnected.descriptionAfter")]})]}),e.jsxs(D,{className:"space-y-4",children:[e.jsxs("div",{className:"bg-muted/50 p-3 rounded-lg flex items-start gap-2",children:[e.jsx(V,{className:"h-4 w-4 text-orange-500 mt-0.5 flex-shrink-0"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:i("notifyAdmin.instanceDisconnected.infoText")})]}),h.length>0?e.jsx("div",{className:"space-y-2 max-h-48 overflow-y-auto",children:h.map(s=>{const t=Q.find(a=>a.instance_id===s.id),n=(t==null?void 0:t.is_active)??!1;return e.jsxs("div",{className:"flex items-center justify-between p-2 rounded-lg hover:bg-muted/50",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Ge,{className:"h-4 w-4 text-green-500"}),e.jsx("span",{className:"text-sm",children:A(s.id)})]}),e.jsx(W,{checked:n,onCheckedChange:()=>ye(s.id),disabled:!l,className:"data-[state=checked]:bg-green-500 data-[state=unchecked]:bg-red-500"})]},s.id)})}):e.jsx("p",{className:"text-sm text-muted-foreground text-center py-4",children:i("notifyAdmin.noNumberConnected")})]})]}),e.jsxs(C,{className:"relative overflow-hidden",children:[e.jsxs("div",{className:"absolute inset-0 bg-background/80 backdrop-blur-sm z-10 flex flex-col items-center justify-center",children:[e.jsx(B,{className:"h-8 w-8 text-muted-foreground mb-2"}),e.jsx("p",{className:"text-sm font-medium text-muted-foreground",children:i("notifyAdmin.comingSoonBadge")})]}),e.jsxs(L,{children:[e.jsxs(k,{className:"flex items-center gap-2 text-lg",children:[e.jsx(re,{className:"h-5 w-5 text-green-500"}),i("notifyAdmin.salesMonitor.title")]}),e.jsxs(S,{children:[i("notifyAdmin.salesMonitor.descriptionBefore")," ",e.jsx(O,{variant:"outline",className:"text-xs",children:"#vendas"})," ",i("notifyAdmin.salesMonitor.descriptionAfter")]})]}),e.jsxs(D,{className:"space-y-4",children:[e.jsxs("div",{className:"bg-muted/50 p-3 rounded-lg flex items-start gap-2",children:[e.jsx(V,{className:"h-4 w-4 text-green-500 mt-0.5 flex-shrink-0"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:i("notifyAdmin.salesMonitor.infoText")})]}),h.length>0?e.jsx("div",{className:"space-y-2 max-h-48 overflow-y-auto",children:h.map(s=>{const t=Y.find(a=>a.instance_id===s.id),n=(t==null?void 0:t.is_active)??!1;return e.jsxs("div",{className:"flex items-center justify-between p-2 rounded-lg hover:bg-muted/50",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(re,{className:"h-4 w-4 text-muted-foreground"}),e.jsx("span",{className:"text-sm",children:A(s.id)})]}),e.jsx(W,{checked:n,onCheckedChange:()=>Ne(s.id),disabled:!l,className:"data-[state=checked]:bg-green-500 data-[state=unchecked]:bg-red-500"})]},s.id)})}):e.jsx("p",{className:"text-sm text-muted-foreground text-center py-4",children:i("notifyAdmin.noNumberConnected")})]})]})]})]}),e.jsx(Pe,{open:xe,onOpenChange:g,children:e.jsxs(Be,{children:[e.jsxs(Fe,{children:[e.jsx(ze,{children:i(N?"notifyAdmin.limitDialog.editTitle":"notifyAdmin.limitDialog.addTitle")}),e.jsx(Re,{children:i("notifyAdmin.limitDialog.description")})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(I,{children:i("notifyAdmin.limitDialog.instanceLabel")}),e.jsxs(F,{value:v,onValueChange:_,disabled:!!N,children:[e.jsx(z,{children:e.jsx(R,{placeholder:i("notifyAdmin.mainConfig.selectNumberPlaceholder")})}),e.jsx(H,{children:se.map(s=>e.jsx(U,{value:s.id,children:s.phone_number?M(s.phone_number):s.label||s.instance_name},s.id))})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(I,{children:i("notifyAdmin.limitDialog.dailyLimitLabel")}),e.jsx(He,{type:"number",min:1,value:b,onChange:s=>w(parseInt(s.target.value)||30)}),e.jsx("p",{className:"text-xs text-muted-foreground",children:i("notifyAdmin.limitDialog.notifyHint",{count:b})})]})]}),e.jsxs(Ue,{children:[e.jsx(m,{variant:"outline",onClick:()=>g(!1),children:i("common:actions.cancel")}),e.jsxs(m,{onClick:ue,disabled:j,children:[j?e.jsx(J,{className:"h-4 w-4 mr-2 animate-spin"}):N?e.jsx(ae,{className:"h-4 w-4 mr-2"}):e.jsx(X,{className:"h-4 w-4 mr-2"}),i(N?"common:actions.save":"common:actions.add")]})]})]})})]})}export{ls 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.