PageSourceSearch

https://smackah.com/assets/UserAnalyticsPanel-C9vrtwp_.js

js smackah.com collected 2026-10-10 00:46:26 UTC 15,208 bytes, 7 lines download raw bytes

vendor: 4,403 bytes, lines 1-7
1import{r as u,j as e,v as g,s as D,aL as X,cc as se,cw as _e,w as Ce,e as Se,S as De,F as ke,I as Te,J as Le,K as Ee,C as v,a as N,U as te,bi as Ue,cG as Ae,l as I,m as $,n as K,aj as q,N as Re}from"./index-DbUPl3PC.js";import{R as Me,T as Oe,X as re,Y as ae,E as Ie,z as ne}from"./generateCategoricalChart-COugthD5.js";import{U as $e}from"./user-minus-C1dm5ScV.js";import{L as Ke}from"./LineChart-DWlBNnEG.js";import{C as He}from"./CartesianGrid-D77_WPGl.js";import{L as Ye}from"./Line-Fog43Xca.js";import{B as ze}from"./BarChart-mhCxd1RG.js";import{P as le,a as ce}from"./PieChart-By4RkLRp.js";import{s as k}from"./subDays-B65VCXYn.js";import{s as H}from"./startOfMonth-CrdLFd27.js";import{s as oe}from"./subMonths-DBGAbjOj.js";import{e as We}from"./eachMonthOfInterval-1wOXA1g4.js";import{i as Be}from"./isWithinInterval-BZ5FGmyW.js";import{e as Ge,a as Fe}from"./eachHourOfInterval-Dw-eruQx.js";import"./index-Dh4i1-J3.js";import"./addMonths-CmPNeP6k.js";const Ve={light:"",dark:".dark"},de=u.createContext(null);function ue(){const h=u.useContext(de);if(!h)throw new Error("useChart must be used within a <ChartContainer />");return h}const T=u.forwardRef(({id:h,className:t,children:r,config:i,...d},j)=>{const l=u.useId(),x=`chart-${h||l.replace(/:/g,"")}`;return e.jsx(de.Provider,{value:{config:i},children:e.jsxs("div",{"data-chart":x,ref:j,className:g("flex aspect-video justify-center text-xs [&_.recharts-cartesian-axis-tick_text]:fill-muted-foreground [&_.recharts-cartesian-grid_line[stroke='#ccc']]:stroke-border/50 [&_.recharts-curve.recharts-tooltip-cursor]:stroke-border [&_.recharts-dot[stroke='#fff']]:stroke-transparent [&_.recharts-layer]:outline-none [&_.recharts-polar-grid_[stroke='#ccc']]:stroke-border [&_.recharts-radial-bar-background-sector]:fill-muted [&_.recharts-rectangle.recharts-tooltip-cursor]:fill-muted [&_.recharts-reference-line_[stroke='#ccc']]:stroke-border [&_.recharts-sector[stroke='#fff']]:stroke-transparent [&_.recharts-sector]:outline-none [&_.recharts-surface]:outline-none",t),...d,children:[e.jsx(Xe,{id:x,config:i}),e.jsx(Me,{children:r})]})})});T.displayName="Chart";const Xe=({id:h,config:t})=>{const r=Object.entries(t).filter(([i,d])=>d.theme||d.color);return r.length?e.jsx("style",{dangerouslySetInnerHTML:{__html:Object.entries(Ve).map(([i,d])=>`
2${d} [data-chart=${h}] {
3${r.map(([j,l])=>{var f;const x=((f=l.theme)==null?void 0:f[i])||l.color;return x?`  --color-${j}: ${x};`:null}).join(`
4`)}
5}
6`).join(`
7`)}}):null},Y=Oe,L=u.forwardRef(({active:h,payload:t,className:r,indicator:i="dot",hideLabel:d=!1,hideIndicator:j=!1,label:l,labelFormatter:x,labelClassName:f,formatter:m,color:W,nameKey:B,labelKey:C},S)=>{const{config:y}=ue(),E=u.useMemo(()=>{var o;if(d||!(t!=null&&t.length))return null;const[c]=t,_=`${C||c.dataKey||c.name||"value"}`,p=J(y,c,_),s=!C&&typeof l=="string"?((o=y[l])==null?void 0:o.label)||l:p==null?void 0:p.label;return x?e.jsx("div",{className:g("font-medium",f),children:x(s,t)}):s?e.jsx("div",{className:g("font-medium",f),children:s}):null},[l,x,t,d,f,y,C]);if(!h||!(t!=null&&t.length))return null;const b=t.length===1&&i!=="dot";return e.jsxs("div",{ref:S,className:g("grid min-w-[8rem] items-start gap-1.5 rounded-lg border border-border/50 bg-background px-2.5 py-1.5 text-xs shadow-xl",r),children:[b?null:E,e.jsx("div",{className:"grid gap-1.5",children:t.map((c,_)=>{const p=`${B||c.name||c.dataKey||"value"}`,s=J(y,c,p),o=W||c.payload.fill||c.color;return e.jsx("div",{className:g("flex w-full flex-wrap items-stretch gap-2 [&>svg]:h-2.5 [&>svg]:w-2.5 [&>svg]:text-muted-foreground",i==="dot"&&"items-center"),children:m&&(c==null?void 0:c.value)!==void 0&&c.name?m(c.value,c.name,c,_,c.payload):e.jsxs(e.Fragment,{children:[s!=null&&s.icon?e.jsx(s.icon,{}):!j&&e.jsx("div",{className:g("shrink-0 rounded-[2px] border-[--color-border] bg-[--color-bg]",{"h-2.5 w-2.5":i==="dot","w-1":i==="line","w-0 border-[1.5px] border-dashed bg-transparent":i==="dashed","my-0.5":b&&i==="dashed"}),style:{"--color-bg":o,"--color-border":o}}),e.jsxs("div",{className:g("flex flex-1 justify-between leading-none",b?"items-end":"items-center"),children:[e.jsxs("div",{className:"grid gap-1.5",children:[b?E:null,e.jsx("span",{className:"text-muted-foreground",children:(s==null?void 0:s.label)||c.name})]}),c.value&&e.jsx("span",{className:"font-mono font-medium tabular-nums text-foreground",children:c.value.toLocaleStr
7ing()})]})]})},c.dataKey)})})]})});L.displayName="ChartTooltip";const qe=u.forwardRef(({className:h,hideIcon:t=!1,payload:r,verticalAlign:i="bottom",nameKey:d},j)=>{const{config:l}=ue();return r!=null&&r.length?e.jsx("div",{ref:j,className:g("flex items-center justify-center gap-4",i==="top"?"pb-3":"pt-3",h),children:r.map(x=>{const f=`${d||x.dataKey||"value"}`,m=J(l,x,f);return e.jsxs("div",{className:g("flex items-center gap-1.5 [&>svg]:h-3 [&>svg]:w-3 [&>svg]:text-muted-foreground"),children:[m!=null&&m.icon&&!t?e.jsx(m.icon,{}):e.jsx("div",{className:"h-2 w-2 shrink-0 rounded-[2px]",style:{backgroundColor:x.color}}),m==null?void 0:m.label]},x.value)})}):null});qe.displayName="ChartLegend";function J(h,t,r){if(typeof t!="object"||t===null)return;const i="payload"in t&&typeof t.payload=="object"&&t.payload!==null?t.payload:void 0;let d=r;return r in t&&typeof t[r]=="string"?d=t[r]:i&&r in i&&typeof i[r]=="string"&&(d=i[r]),d in h?h[d]:h[r]}const z={users:{label:"Users",color:"hsl(var(--primary))"},active:{label:"Active",color:"hsl(var(--success))"},archived:{label:"Archived",color:"hsl(var(--muted-foreground))"}},ie=[{value:"today",label:"Today"},{value:"last7",label:"Last 7 days"},{value:"last30",label:"Last 30 days"},{value:"last90",label:"Last 90 days"},{value:"thisMonth",label:"This month"},{value:"thisYear",label:"This year"}];function ms(){var p;const[h,t]=u.useState(!0),[r,i]=u.useState("thisYear"),[d,j]=u.useState([]),[l,x]=u.useState({total:0,active:0,archived:0,suspended:0,newLast30Days:0,withTransactions:0,withoutTransactions:0}),[f,m]=u.useState([]),[W,B]=u.useState([]);u.useEffect(()=>{C()},[]);const C=async()=>{var s,o,w;t(!0);try{const{data:n,error:U}=await D.from("profiles").select("user_id, status, created_at");if(U)throw U;j(n||[]);const A=(n==null?void 0:n.length)||0,R=(n==null?void 0:n.filter(a=>a.status==="active").length)||0,M=(n==null?void 0:n.filter(a=>a.status==="archived").length)||0,he=(n==null?void 0:n.filter(a=>a.status==="suspended").length)||0,xe=k(new Date,30),me=(n==null?void 0:n.filter(a=>a.created_at&&new Date(a.created_at)>=xe).length)||0,{data:G,error:P}=await D.from("user_roles").select("role");if(P)throw P;const F={};G==null||G.forEach(a=>{F[a.role]=(F[a.role]||0)+1});const fe=Object.entries(F).map(([a,V])=>({role:a.charAt(0).toUpperCase()+a.slice(1),count:V})),Je=(n==null?void 0:n.map(a=>a.user_id))||[],[je,ge,pe]=await Promise.all([D.from("registrations").select("user_id").not("user_id","is",null),D.from("donations").select("user_id").not("user_id","is",null),D.from("sponsor_payments").select("user_id").not("user_id","is",null)]),O=new Set;(s=je.data)==null||s.forEach(a=>a.user_id&&O.add(a.user_id)),(o=ge.data)==null||o.forEach(a=>a.user_id&&O.add(a.user_id)),(w=pe.data)==null||w.forEach(a=>a.user_id&&O.add(a.user_id));const Q=O.size,ve=A-Q,Ne=H(oe(new Date,5)),we=We({start:Ne,end:new Date}).map(a=>{const V=H(a),ye=H(oe(a,-1)),be=(n==null?void 0:n.filter(Z=>{if(!Z.created_at)return!1;const ee=new Date(Z.created_at);return ee>=V&&ee<ye}).length)||0;return{month:X(a,"MMM yyyy"),count:be}});x({total:A,active:R,archived:M,suspended:he,newLast30Days:me,withTransactions:Q,withoutTransactions:ve}),m(fe),B(we)}catch(n){console.error("Error fetching user analytics:",n)}finally{t(!1)}},S=u.useMemo(()=>{const s=new Date,o=se(s);switch(r){case"today":return{start:o,end:s};case"last7":return{start:k(o,6),end:s};case"last30":return{start:k(o,29),end:s};case"last90":return{start:k(o,89),end:s};case"thisMonth":return{start:H(s),end:s};case"thisYear":return{start:_e(s),end:s};default:return{start:k(o,29),end:s}}},[r]),y=u.useMemo(()=>d.filter(s=>{if(!s.created_at)return!1;const o=new Date(s.created_at);return Be(o,{start:S.start,end:S.end})}).length,[d,S]),E=u.useMemo(()=>{if(r!=="today")return[];const s=new Date;return Ge({start:se(s),end:s}).map(w=>{const n=w,U=Fe(w,1),A=d.filter(R=>{if(!R.created_at)return!1;const M=new Date(R.created_at);return M>=n&&M<U}).length;return{time:X(w,"ha"),fullTime:X(w,"h:mm a"),count:A}})},[r,d]),b=r==="today"?E:W;if(h)return e.jsx("div",{className:"flex items-center justify-center py-12",children:e.jsx(Ce,{className:"w-8 h-8 animate-spin text-primary"})});const c=[{name:"Active",value:l.active,fill:"hsl(var(--success))"},{name:"Archived",value:l.archived,fill:"hsl(var(--muted-foreground))"},{name:"Suspended",value:l.suspended,fill:"hsl(var(--destructive))"}].filter(s=>s.value>0),_=[{name:"With Orders",value:l.withTransactions,fill:"hsl(var(--primary))"},{name:"No Orders",value:l.withoutTransactions,fill:"hsl(var(--muted))"}];return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"flex flex-col sm:flex-row sm:items-center sm:justify-between gap-4",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"text-xl font-heading font-bold text-foreground",children:"User Analytics"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Overview of user growth, engagement, and distribution"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Se,{className:"h-4 w-4 text-muted-foreground"}),e.jsxs(De,{value:r,onValueChange:s=>i(s),children:[e.jsx(ke,{className:"w-[160px]",children:e.jsx(Te,{placeholder:"Select range"})}),e.jsx(Le,{children:ie.map(s=>e.jsx(Ee,{value:s.value,children:s.label},s.value))})]})]})]}),e.jsxs("div",{className:"grid grid-cols-2 lg:grid-cols-4 gap-4",children:[e.jsx(v,{children:e.jsx(N,{className:"pt-6",children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"w-10 h-10 rounded-lg bg-primary/10 flex items-center justify-center",children:e.jsx(te,{className:"w-5 h-5 text-primary"})}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:"Total Users"}),e.jsx("p",{className:"text-2xl font-bold",children:l.total})]})]})})}),e.jsx(v,{children:e.jsx(N,{className:"pt-6",children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"w-10 h-10 rounded-lg bg-success/10 flex items-center justify-center",children:e.jsx(Ue,{className:"w-5 h-5 text-success"})}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:"Active Users"}),e.jsx("p",{className:"text-2xl font-bold",children:l.active})]})]})})}),e.jsx(v,{children:e.jsx(N,{className:"pt-6",children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"w-10 h-10 rounded-lg bg-secondary/10 flex items-center justify-center",children:e.jsx(Ae,{className:"w-5 h-5 text-secondary"})}),e.jsxs("div",{children:[e.jsxs("p",{className:"text-sm text-muted-foreground",children:["New (",((p=ie.find(s=>
7s.value===r))==null?void 0:p.label)||"Last 30 days",")"]}),e.jsx("p",{className:"text-2xl font-bold",children:y})]})]})})}),e.jsx(v,{children:e.jsx(N,{className:"pt-6",children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"w-10 h-10 rounded-lg bg-muted flex items-center justify-center",children:e.jsx($e,{className:"w-5 h-5 text-muted-foreground"})}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:"Archived"}),e.jsx("p",{className:"text-2xl font-bold",children:l.archived})]})]})})})]}),e.jsxs("div",{className:"grid lg:grid-cols-2 gap-6",children:[e.jsxs(v,{children:[e.jsxs(I,{children:[e.jsx($,{className:"text-base",children:"User Growth"}),e.jsx(K,{children:r==="today"?"Hourly signups today":"New signups per month (last 6 months)"})]}),e.jsx(N,{children:e.jsx(T,{config:z,className:"h-[250px] w-full",children:e.jsxs(Ke,{data:b,children:[e.jsx(He,{strokeDasharray:"3 3",className:"stroke-muted"}),e.jsx(re,{dataKey:r==="today"?"time":"month",tick:{fontSize:12},tickLine:!1,axisLine:!1}),e.jsx(ae,{tick:{fontSize:12},tickLine:!1,axisLine:!1,allowDecimals:!1}),e.jsx(Y,{content:e.jsx(L,{})}),e.jsx(Ye,{type:"monotone",dataKey:"count",stroke:"hsl(var(--primary))",strokeWidth:2,dot:{fill:"hsl(var(--primary))"},name:"New Users"})]})})})]}),e.jsxs(v,{children:[e.jsxs(I,{children:[e.jsx($,{className:"text-base",children:"Role Distribution"}),e.jsx(K,{children:"Users by assigned role"})]}),e.jsx(N,{children:e.jsx(T,{config:z,className:"h-[250px] w-full",children:e.jsxs(ze,{data:f,layout:"vertical",children:[e.jsx(re,{type:"number",allowDecimals:!1}),e.jsx(ae,{type:"category",dataKey:"role",width:80,tick:{fontSize:12}}),e.jsx(Y,{content:e.jsx(L,{})}),e.jsx(Ie,{dataKey:"count",fill:"hsl(var(--primary))",radius:[0,4,4,0],name:"Users"})]})})})]})]}),e.jsxs("div",{className:"grid lg:grid-cols-2 gap-6",children:[e.jsxs(v,{children:[e.jsxs(I,{children:[e.jsx($,{className:"text-base",children:"User Status"}),e.jsx(K,{children:"Distribution by account status"})]}),e.jsx(N,{children:e.jsxs("div",{className:"flex items-center gap-8",children:[e.jsx(T,{config:z,className:"h-[180px] w-[180px]",children:e.jsxs(le,{children:[e.jsx(ce,{data:c,cx:"50%",cy:"50%",innerRadius:50,outerRadius:80,paddingAngle:2,dataKey:"value",children:c.map((s,o)=>e.jsx(ne,{fill:s.fill},`cell-${o}`))}),e.jsx(Y,{content:e.jsx(L,{})})]})}),e.jsx("div",{className:"space-y-2",children:c.map((s,o)=>e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"w-3 h-3 rounded-full",style:{backgroundColor:s.fill}}),e.jsx("span",{className:"text-sm text-muted-foreground",children:s.name}),e.jsx(q,{variant:"secondary",className:"ml-auto",children:s.value})]},s.name))})]})})]}),e.jsxs(v,{children:[e.jsxs(I,{children:[e.jsx($,{className:"text-base",children:"User Engagement"}),e.jsx(K,{children:"Users with vs without orders"})]}),e.jsx(N,{children:e.jsxs("div",{className:"flex items-center gap-8",children:[e.jsx(T,{config:z,className:"h-[180px] w-[180px]",children:e.jsxs(le,{children:[e.jsx(ce,{data:_,cx:"50%",cy:"50%",innerRadius:50,outerRadius:80,paddingAngle:2,dataKey:"value",children:_.map((s,o)=>e.jsx(ne,{fill:s.fill},`cell-${o}`))}),e.jsx(Y,{content:e.jsx(L,{})})]})}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Re,{className:"w-4 h-4 text-primary"}),e.jsx("span",{className:"text-sm text-muted-foreground",children:"With Orders"}),e.jsx(q,{variant:"default",className:"ml-auto",children:l.withTransactions})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(te,{className:"w-4 h-4 text-muted-foreground"}),e.jsx("span",{className:"text-sm text-muted-foreground",children:"No Orders"}),e.jsx(q,{variant:"secondary",className:"ml-auto",children:l.withoutTransactions})]}),e.jsx("div",{className:"pt-2 border-t",children:e.jsxs("p",{className:"text-xs text-muted-foreground",children:["Engagement rate: ",e.jsxs("span",{className:"font-medium text-foreground",children:[l.total>0?(l.withTransactions/l.total*100).toFixed(1):0,"%"]})]})})]})]})})]})]})]})}export{ms as UserAnalyticsPanel};

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.