PageSourceSearch

https://digitalacumen.ai/assets/index-DdY9_CfP.js

js digitalacumen.ai collected 2026-10-05 14:00:21 UTC 19,327 bytes, 1 lines download raw bytes

1import{j as e,c as w,F as K,ah as Q,S as W,ai as fe,f as A,r as ge,P as T,J as X,aj as g,l as Ne,M as pe,q as be}from"./vendor-ui-Zajf7W1K.js";import{u as ve,a as o,L as h}from"./vendor-react-DI5zCDLm.js";import{s as u,f as ye,B as j}from"./index-DarZMwSf.js";import{a as we}from"./data-Dr58gT14.js";import{C as a,a as r,b as l,d as i,c as x}from"./card-NKJpIF3T.js";import{S as Y}from"./StarRating-D_z_ZTzW.js";import{B as L}from"./badge-_57-REGX.js";import"./vendor-supabase-9Pe7CZ8l.js";import"./secure-queries-BYZ2A1ZT.js";function Me(){const Z=ve(),[ee,se]=o.useState(0),[te,ae]=o.useState(0),[d,re]=o.useState(0),[c,le]=o.useState({starter:0,professional:0,enterprise:0}),[m,ie]=o.useState({totalEvents:0,criticalEvents:0,highEvents:0,unresolvedEvents:0,recentEvents:[],suspiciousIPs:[]}),[N,ne]=o.useState(null),[p,ce]=o.useState(null),[de,S]=o.useState(!0),[I,B]=o.useState(null);o.useEffect(()=>{oe()},[Z]);async function oe(){try{console.log("Checking admin access...");const{data:{user:s}}=await u.auth.getUser();if(!s)throw new Error("Not authenticated");if(!await ye())throw new Error("Unauthorized: Admin access required");console.log("Admin access verified successfully"),await xe()}catch(s){console.error("Admin access check failed:",s),B(s instanceof Error?s.message:"Failed to verify admin access"),S(!1)}}async function xe(){try{console.log("Loading dashboard data...");const{data:{user:s}}=await u.auth.getUser(),b=s?.id;if(!b)throw new Error("No authenticated user found");const{data:{session:z}}=await u.auth.getSession();if(!z)throw new Error("No active session");const[E,k,C,_,P,U,D]=await Promise.allSettled([u.from("profiles").select("*"),u.functions.invoke("admin-get-all-user-details",{method:"POST",body:JSON.stringify({admin:!0})}),u.from("reports").select("*"),u.from("credit_purchases").select("*"),u.from("security_events").select("*").order("created_at",{ascending:!1}).limit(100),we().catch(()=>null),u.functions.invoke("admin-get-referral-stats",{method:"GET",headers:{Authorization:`Bearer ${z.access_token}`}}).catch(()=>null)]);let M=[];E.status==="fulfilled"&&E.value.data&&(M=E.value.data),k.status==="fulfilled"&&k.value.data?.users&&(M=k.value.data.users);const me=M.filter(f=>f.id!==b);se(me.length);let V=[];C.status==="fulfilled"&&C.value.data&&(V=C.value.data);const he=V.filter(f=>f.user_id!==b&&!f.title.includes("Premium Digital Strategy Report"));ae(he.length);let q=0,G=0,H=0,J=0;if(_.status==="fulfilled"&&_.value.data){const f=_.value.data;for(const R of f)try{const n=R.package_id,y=R.amount;if(typeof y=="number"&&y>0){const v=y/100;q+=v,n==="starter"||n==="basic"?G+=v:n==="professional"?H+=v:n==="enterprise"&&(J+=v)}}catch(n){console.error("Error processing credit purchase:",n)}}if(re(q),le({starter:G,professional:H,enterprise:J}),P.status==="fulfilled"&&P.value.data){const f=P.value.data,R=new Date(Date.now()-1440*60*1e3),n=f.filter(t=>new Date(t.created_at)>R),y=n.filter(t=>t.severity==="critical").length,v=n.filter(t=>t.severity==="high").length,ue=n.filter(t=>!t.resolved).length,F={};n.forEach(t=>{t.ip_address&&t.ip_address!=="unknown"&&(F[t.ip_address]=(F[t.ip_address]||0)+1)});const je=Object.entries(F).filter(([,t])=>t>=5).map(([t,$])=>({ip:t,count:$})).sort((t,$)=>$.count-t.count).slice(0,5);ie({totalEvents:n.length,criticalEvents:y,highEvents:v,unresolvedEvents:ue,recentEvents:n.slice(0,10),suspiciousIPs:je})}U.status==="fulfilled"&&U.value&&ne(U.value),D.status==="fulfilled"&&D.value?.data?.success&&ce(D.value.data.stats),console.log("Dashboard data loaded successfully"),S(!1)}catch(s){console.error("Error loading dashboard data:",s),B(s instanceof Error?s.message:"Failed to load dashboard data"),S(!1)}}const O=s=>{switch(s){case"critical":return"bg-red-100 text-red-800 border-red-200";case"high":return"bg-orange-100 text-orange-800 border-orange-200";case"medium":return"bg-yellow-100 text-yellow-800 border-yellow-200";case"low":return"bg-blue-100 text-blue-800 border-blue-200";default:return"bg-gray-100 text-gray-800 border-gray-200"}};return de?e.jsx("div",{className:"min-h-screen bg-gray-50 py-12",children:e.jsx("div",{className:"container mx-auto px-4",children:e.jsx("div",{className:"text-center",children:"Loading dashboard data..."})})}):I?e.jsx("div",{className:"min-h-screen bg-gray-50 py-12",children:e.jsxs("div",{className:"container mx-auto px-4",children:[e.jsx("div",{className:"text-center text-red-600 mb-4",children:I}),e.jsx("div",{className:"text-center",children:e.jsx(j,{asChild:!0,children:e.jsx(h,{to:"/dashboard",children:"Go to Dashboard"})})})]})}):e.jsx("main",{className:"min-h-screen bg-gray-50 py-12",children:e.jsxs("div",{className:"container mx-auto px-4",children:[e.jsxs("div",{className:"mb-8",children:[e.jsx("h1",{className:"text-3xl font-bold",children:"Admin Dashboard"}),e.jsx("p",{className:"text-gray-600",children:"Overview of users, revenue, and security"})]}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-4 gap-6 mb-8",children:[e.jsxs(a,{children:[e.jsxs(r,{className:"flex flex-row items-center justify-between pb-2",children:[e.jsx(l,{className:"text-sm font-medium text-gray-500",children:"Total Users"}),e.jsx(w,{className:"h-4 w-4 text-gray-500"})]}),e.jsxs(i,{children:[e.jsx("div",{className:"text-2xl font-bold",children:ee}),e.jsx("p",{className:"text-xs text-gray-500",children:"Registered accounts"})]})]}),e.jsxs(a,{children:[e.jsxs(r,{className:"flex flex-row items-center justify-between pb-2",children:[e.jsx(l,{className:"text-sm font-medium text-gray-500",children:"Total Reports"}),e.jsx(K,{className:"h-4 w-4 text-gray-500"})]}),e.jsxs(i,{children:[e.jsx("div",{className:"text-2xl font-bold",children:te}),e.jsx("p",{className:"text-xs text-gray-500",children:"Generated by users"})]})]}),e.jsxs(a,{children:[e.jsxs(r,{className:"flex flex-row items-center justify-between pb-2",children:[e.jsx(l,{className:"text-sm font-medium text-gray-500",children:"Total Revenue"}),e.jsx(Q,{className:"h-4 w-4 text-gray-500"})]}),e.jsxs(i,{children:[e.jsxs("div",{className:"text-2xl font-bold",children:["$",d.toLocaleStr
1ing()]}),e.jsx("p",{className:"text-xs text-gray-500",children:"From credit purchases"})]})]}),e.jsxs(a,{children:[e.jsxs(r,{className:"flex flex-row items-center justify-between pb-2",children:[e.jsx(l,{className:"text-sm font-medium text-gray-500",children:"Security Events"}),e.jsx(W,{className:"h-4 w-4 text-gray-500"})]}),e.jsxs(i,{children:[e.jsx("div",{className:"text-2xl font-bold",children:m.totalEvents}),e.jsx("p",{className:"text-xs text-gray-500",children:"Last 24 hours"})]})]})]}),e.jsx("div",{className:"grid grid-cols-1 lg:grid-cols-2 gap-6 mb-8",children:e.jsxs(a,{className:"lg:col-span-2 border-2 border-blue-200 bg-blue-50/30",children:[e.jsxs(r,{children:[e.jsxs(l,{className:"text-xl flex items-center",children:[e.jsx(W,{className:"h-5 w-5 mr-2 text-blue-600"}),"Security Overview"]}),e.jsx(x,{children:"Real-time security monitoring and threat detection"})]}),e.jsxs(i,{children:[e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-4 gap-4 mb-6",children:[e.jsxs("div",{className:"bg-white rounded-lg p-4 border border-gray-200",children:[e.jsxs("div",{className:"flex items-center justify-between mb-2",children:[e.jsx("h3",{className:"text-sm font-medium text-gray-500",children:"Total Events"}),e.jsx(fe,{className:"h-4 w-4 text-gray-500"})]}),e.jsx("p",{className:"text-2xl font-bold",children:m.totalEvents}),e.jsx("p",{className:"text-xs text-gray-500 mt-1",children:"Last 24 hours"})]}),e.jsxs("div",{className:"bg-red-50 rounded-lg p-4 border border-red-200",children:[e.jsxs("div",{className:"flex items-center justify-between mb-2",children:[e.jsx("h3",{className:"text-sm font-medium text-red-700",children:"Critical"}),e.jsx(A,{className:"h-4 w-4 text-red-600"})]}),e.jsx("p",{className:"text-2xl font-bold text-red-600",children:m.criticalEvents}),e.jsx("p",{className:"text-xs text-red-600 mt-1",children:"Immediate attention"})]}),e.jsxs("div",{className:"bg-orange-50 rounded-lg p-4 border border-orange-200",children:[e.jsxs("div",{className:"flex items-center justify-between mb-2",children:[e.jsx("h3",{className:"text-sm font-medium text-orange-700",children:"High Priority"}),e.jsx(A,{className:"h-4 w-4 text-orange-600"})]}),e.jsx("p",{className:"text-2xl font-bold text-orange-600",children:m.highEvents}),e.jsx("p",{className:"text-xs text-orange-600 mt-1",children:"Review required"})]}),e.jsxs("div",{className:"bg-yellow-50 rounded-lg p-4 border border-yellow-200",children:[e.jsxs("div",{className:"flex items-center justify-between mb-2",children:[e.jsx("h3",{className:"text-sm font-medium text-yellow-700",children:"Unresolved"}),e.jsx(ge,{className:"h-4 w-4 text-yellow-600"})]}),e.jsx("p",{className:"text-2xl font-bold text-yellow-600",children:m.unresolvedEvents}),e.jsx("p",{className:"text-xs text-yellow-600 mt-1",children:"Needs resolution"})]})]}),m.suspiciousIPs.length>0&&e.jsxs("div",{className:"bg-red-50 border border-red-200 rounded-lg p-4 mb-4",children:[e.jsxs("h4",{className:"font-semibold text-red-800 mb-3 flex items-center",children:[e.jsx(A,{className:"h-4 w-4 mr-2"}),"Suspicious IP Addresses (5+ events)"]}),e.jsx("div",{className:"space-y-2",children:m.suspiciousIPs.map(({ip:s,count:b})=>e.jsxs("div",{className:"flex justify-between items-center bg-white rounded px-3 py-2",children:[e.jsx("code",{className:"text-sm font-mono text-red-700",children:s}),e.jsxs(L,{variant:"destructive",children:[b," events"]})]},s))})]}),e.jsxs("div",{className:"bg-white border border-gray-200 rounded-lg p-4",children:[e.jsx("h4",{className:"font-semibold text-gray-800 mb-3",children:"Recent Security Events"}),m.recentEvents.length>0?e.jsx("div",{className:"space-y-2 max-h-64 overflow-y-auto",children:m.recentEvents.map(s=>e.jsxs("div",{className:`flex justify-between items-center px-3 py-2 rounded border ${O(s.severity)}`,children:[e.jsxs("div",{className:"flex-1",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-sm font-medium",children:s.event_type.replace(/_/g," ")}),e.jsx(L,{variant:s.resolved?"default":"destructive",className:"text-xs",children:s.resolved?"Resolved":"Active"})]}),e.jsxs("div",{className:"text-xs mt-1 opacity-75",children:[new Date(s.created_at).toLocaleStr
1ing()," • ",s.ip_address||"Unknown IP"]})]}),e.jsx(L,{className:O(s.severity),children:s.severity.toUpperCase()})]},s.id))}):e.jsx("p",{className:"text-sm text-gray-500 text-center py-4",children:"No security events in the last 24 hours"})]})]})]})}),e.jsx("div",{className:"grid grid-cols-1 lg:grid-cols-2 gap-6 mb-8",children:e.jsxs(a,{className:"lg:col-span-2",children:[e.jsxs(r,{children:[e.jsx(l,{className:"text-xl",children:"Revenue by Package"}),e.jsx(x,{children:"Breakdown of revenue from actual credit purchases"})]}),e.jsxs(i,{children:[e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-3 gap-6",children:[e.jsxs("div",{className:"bg-blue-50 rounded-lg p-4",children:[e.jsxs("div",{className:"flex items-center justify-between mb-2",children:[e.jsx("h3",{className:"font-semibold",children:"Starter"}),e.jsx(T,{className:"h-4 w-4 text-blue-500"})]}),e.jsxs("p",{className:"text-2xl font-bold text-blue-600",children:["$",c.starter.toLocaleString()]}),e.jsxs("p",{className:"text-xs text-blue-600 mt-1",children:[d>0?Math.round(c.starter/d*100):0,"% of total revenue"]})]}),e.jsxs("div",{className:"bg-purple-50 rounded-lg p-4",children:[e.jsxs("div",{className:"flex items-center justify-between mb-2",children:[e.jsx("h3",{className:"font-semibold",children:"Professional"}),e.jsx(T,{className:"h-4 w-4 text-purple-500"})]}),e.jsxs("p",{className:"text-2xl font-bold text-purple-600",children:["$",c.professional.toLocaleString()]}),e.jsxs("p",{className:"text-xs text-purple-600 mt-1",children:[d>0?Math.round(c.professional/d*100):0,"% of total revenue"]})]}),e.jsxs("div",{className:"bg-green-50 rounded-lg p-4",children:[e.jsxs("div",{className:"flex items-center justify-between mb-2",children:[e.jsx("h3",{className:"font-semibold",children:"Enterprise"}),e.jsx(T,{className:"h-4 w-4 text-green-500"})]}),e.jsxs("p",{className:"text-2xl font-bold text-green-600",children:["$",c.enterprise.toLocaleString()]}),e.jsxs("p",{className:"text-xs text-green-600 mt-1",children:[d>0?Math.round(c.enterprise/d*100):0,"% of total revenue"]})]})]}),e.jsxs("div",{className:"mt-8",children:[e.jsx("h3",{className:"text-sm font-medium text-gray-500 mb-2",children:"Revenue Distribution"}),e.jsx("div",{className:"w-full h-4 bg-gray-200 rounded-full overflow-hidden",children:d>0?e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"h-full bg-blue-500 float-left",style:{width:`${c.starter/d*100}%`},title:`Starter: $${c.starter}`}),e.jsx("div",{className:"h-full bg-purple-500 float-left",style:{width:`${c.professional/d*100}%`},title:`Professional: $${c.professional}`}),e.jsx("div",{className:"h-full bg-green-500 float-left",style:{width:`${c.enterprise/d*100}%`},title:`Enterprise: $${c.enterprise}`})]}):e.jsx("div",{className:"h-full bg-gray-300 w-full"})}),e.jsxs("div",{className:"flex justify-between mt-2 text-xs text-gray-500",children:[e.jsx("div",{children:"Starter"}),e.jsx("div",{children:"Professional"}),e.jsx("div",{children:"Enterprise"})]})]})]})]})}),e.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-2 gap-6 mb-8",children:[e.jsxs(a,{children:[e.jsxs(r,{children:[e.jsxs(l,{className:"flex items-center",children:[e.jsx(X,{className:"h-5 w-5 mr-2"}),"Feedback Summary"]}),e.jsx(x,{children:"User feedback and ratings"})]}),e.jsx(i,{children:N?e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("span",{className:"font-medium",children:"Overall Rating:"}),e.jsxs("div",{className:"flex items-center",children:[e.jsx("span",{className:"text-lg font-bold mr-2",children:N.overallRating.toFixed(1)}),e.jsx(Y,{rating:N.overallRating,readOnly:!0,size:16})]})]}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("span",{className:"font-medium",children:"Total Feedback:"}),e.jsx("span",{className:"text-lg font-bold",children:N.totalFeedback})]}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("span",{className:"font-medium",children:"Reports with Feedback:"}),e.jsx("span",{className:"text-lg font-bold",children:N.reportRatings.length})]}),N.reportRatings.length>0&&e.jsxs("div",{className:"mt-4",children:[e.jsx("h4",{className:"font-medium mb-2",children:"Top Rated Reports:"}),e.jsx("div",{className:"space-y-2",children:N.reportRatings.slice(0,3).map(s=>e.jsxs("div",{className:"flex justify-between items-center",children:[e.jsx("span",{className:"text-sm truncate max-w-[200px]",children:s.report_title}),e.jsxs("div",{className:"flex items-center",children:[e.jsx("span",{className:"text-sm font-bold mr-2",children:s.average_rating.toFixed(1)}),e.jsx(Y,{rating:s.average_rating,readOnly:!0,size:12})]})]},s.report_id))})]}),e.jsx(j,{variant:"outline",className:"w-full mt-4",asChild:!0,children:e.jsxs(h,{to:"/admin/feedback",children:["View Detailed Feedback",e.jsx(g,{className:"ml-2 h-4 w-4"})]})})]}):e.jsx("div",{className:"text-center py-4",children:e.jsx("p",{className:"text-gray-500",children:"No feedback data available yet"})})})]}),p&&e.jsxs(a,{children:[e.jsxs(r,{children:[e.jsxs(l,{className:"flex items-center",children:[e.jsx(w,{className:"h-5 w-5 mr-2"}),"Referral Program"]}),e.jsx(x,{children:"Performance metrics for referrals"})]}),e.jsx(i,{children:e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"bg-blue-50 rounded-lg p-4",children:[e.jsxs("div",{className:"flex items-center justify-between mb-2",children:[e.jsx("h3",{className:"text-sm font-medium",children:"Total Referrals"}),e.jsx(w,{className:"h-4 w-4 text-blue-500"})]}),e.jsx("p",{className:"text-2xl font-bold text-blue-600",children:p.total_referrals})]}),e.jsxs("div",{className:"bg-green-50 rounded-lg p-4",children:[e.jsxs("div",{className:"flex items-center justify-between mb-2",children:[e.jsx("h3",{className:"text-sm font-medium",children:"Paid Conversions"}),e.jsx(Q,{className:"h-4 w-4 text-green-500"})]}),e.jsx("p",{className:"text-2xl font-bold text-green-600",children:p.paid_referrals}),e.jsx("p",{className:"text-xs text-green-600 mt-1",children:p.total_referrals>0?`${Math.round(p.paid_referrals/p.total_referrals*100)}% conversion`:"0% conversion"})]}),e.jsxs("div",{className:"bg-purple-50 rounded-lg p-4",children:[e.jsxs("div",{className:"flex items-center justify-between mb-2",children:[e.jsx("h3",{className:"text-sm font-medium",children:"Referral Revenue"}),e.jsx(Ne,{className:"h-4 w-4 text-purple-500"})]}),e.jsxs("p",{className:"text-2xl font-bold text-purple-600",children:["$",p.total_revenue]})]}),e.jsx(j,{variant:"outline",className:"w-full mt-4",asChild:!0,children:e.jsxs(h,{to:"/admin/referrals",children:["Manage Referrals",e.jsx(g,{className:"ml-2 h-4 w-4"})]})})]})})]})]}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-3 gap-6",children:[e.jsxs(a,{children:[e.jsxs(r,{children:[e.jsxs(l,{className:"flex items-center",children:[e.jsx(w,{className:"h-5 w-5 mr-2"}),"Manage Users"]}),e.jsx(x,{children:"View and manage user accounts"})]}),e.jsx(i,{children:e.jsx(j,{asChild:!0,className:"w-full",children:e.jsxs(h,{to:"/admin/users",children:["Manage Users",e.jsx(g,{className:"ml-2 h-4 w-4"})]})})})]}),e.jsxs(a,{children:[e.jsxs(r,{children:[e.jsxs(l,{className:"flex items-center",children:[e.jsx(K,{className:"h-5 w-5 mr-2"}),"Manage Reports"]}),e.jsx(x,{children:"View and manage all reports"})]}),e.jsx(i,{children:e.jsx(j,{asChild:!0,className:"w-full",children:e.jsxs(h,{to:"/admin/reports",children:["Manage Reports",e.jsx(g,{className:"ml-2 h-4 w-4"})]})})})]}),e.jsxs(a,{children:[e.jsxs(r,{children:[e.jsxs(l,{className:"flex items-center",children:[e.jsx(X,{className:"h-5 w-5 mr-2"}),"Manage Feedback"]}),e.jsx(x,{children:"View and analyze user feedback"})]}),e.jsx(i,{children:e.jsx(j,{asChild:!0,className:"w-full",children:e.jsxs(h,{to:"/admin/feedback",children:["Manage Feedback",e.jsx(g,{className:"ml-2 h-4 w-4"})]})})})]}),e.jsxs(a,{children:[e.jsxs(r,{children:[e.jsxs(l,{className:"flex items-center",children:[e.jsx(pe,{className:"h-5 w-5 mr-2"}),"Manage News"]}),e.jsx(x,{children:"Create and manage news items"})]}),e.jsx(i,{children:e.jsx(j,{asChild:!0,className:"w-full",children:e.jsxs(h,{to:"/admin/news",children:["Manage News",e.jsx(g,{className:"ml-2 h-4 w-4"})]})})})]}),e.jsxs(a,{children:[e.jsxs(r,{children:[e.jsxs(l,{className:"flex items-center",children:[e.jsx(be,{className:"h-5 w-5 mr-2"}
1),"Verification Emails"]}),e.jsx(x,{children:"Send verification emails to users"})]}),e.jsx(i,{children:e.jsx(j,{asChild:!0,className:"w-full",children:e.jsxs(h,{to:"/admin/verification-emails",children:["Send Emails",e.jsx(g,{className:"ml-2 h-4 w-4"})]})})})]}),e.jsxs(a,{children:[e.jsxs(r,{children:[e.jsxs(l,{className:"flex items-center",children:[e.jsx(w,{className:"h-5 w-5 mr-2"}),"Cleanup Users"]}),e.jsx(x,{children:"Clean up orphaned users"})]}),e.jsx(i,{children:e.jsx(j,{asChild:!0,className:"w-full",children:e.jsxs(h,{to:"/admin/cleanup-users",children:["Cleanup Users",e.jsx(g,{className:"ml-2 h-4 w-4"})]})})})]})]})]})})}export{Me 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.