PageSourceSearch

https://bytesvibe.com/assets/Dashboard-uQnY_OQI.js

js bytesvibe.com collected 2026-10-04 01:33:58 UTC 10,372 bytes, 1 lines download raw bytes

1import{j as e}from"./ui-pZ967-NS.js";import{u as n,o as j,B as T,s as q,h as A,d as S}from"./blog-BCH5Rkw1.js";import{L as N}from"./vendor-COMpnQoB.js";import{C as g,a as b,b as _,d as w}from"./tools-Dnd2ifXP.js";import{aH as R,i as z,aU as L,h as U,F as W,W as B,aL as I,at as P,aO as O,M as H,aV as V,aN as $,A as G}from"./utils-B5_VV7Cb.js";import{u as M}from"./useUnseen-B8YeqMpu.js";import{R as Q,A as X,C as Y,X as E,Y as J,T as Z,a as ee}from"./AreaChart-CkXPyUT9.js";import"./index-Dh4i1-J3.js";function se(){const{data:h,isLoading:p}=n({queryKey:["dashboard-tasks-widget"],queryFn:async()=>{const{data:a,error:i}=await q.from("tasks").select("id, title, status, priority, due_at, completed_at").eq("is_archived",!1).order("due_at",{ascending:!0,nullsFirst:!1}).limit(200);if(i)throw i;return a??[]}}),l=h??[],c=new Date,m=new Date(c);m.setHours(23,59,59,999);const v=a=>a.status!=="completed"&&a.status!=="cancelled",D=l.filter(a=>v(a)&&a.due_at&&new Date(a.due_at)<c).slice(0,5),F=l.filter(a=>v(a)&&a.due_at&&new Date(a.due_at)>=c&&new Date(a.due_at)<=m).slice(0,5),K=l.filter(a=>v(a)&&a.due_at&&new Date(a.due_at)>m).slice(0,5),C=l.filter(a=>a.status==="completed").slice(0,5),f=(a,i,k,u)=>e.jsxs("div",{children:[e.jsxs("div",{className:`flex items-center gap-2 text-xs font-semibold uppercase tracking-wide mb-1 ${u??"text-muted-foreground"}`,children:[k,a,e.jsx(T,{variant:"secondary",className:"ml-auto",children:i.length})]}),i.length===0?e.jsx("p",{className:"text-xs text-muted-foreground py-1",children:"None."}):e.jsx("ul",{className:"space-y-1",children:i.map(y=>e.jsx("li",{children:e.jsxs(N,{to:"/admin/tasks",className:"flex items-center justify-between gap-2 rounded px-2 py-1 text-sm hover:bg-muted/50",children:[e.jsx("span",{className:"truncate",children:y.title}),y.due_at&&e.jsx("span",{className:"text-[10px] text-muted-foreground shrink-0",children:new Date(y.due_at).toLocaleDateString()})]})},y.id))})]});return e.jsxs(g,{children:[e.jsxs(b,{className:"flex-row items-center justify-between space-y-0",children:[e.jsxs(_,{className:"text-base flex items-center gap-2",children:[e.jsx(R,{className:"h-4 w-4"})," Tasks"]}),e.jsx(N,{to:"/admin/tasks",className:"text-xs text-primary hover:underline",children:"Open center →"})]}),e.jsx(w,{className:"grid gap-4 md:grid-cols-2",children:p?e.jsx(j,{className:"h-32 w-full md:col-span-2"}):e.jsxs(e.Fragment,{children:[f("Overdue",D,e.jsx(z,{className:"h-3.5 w-3.5"}),"text-red-600"),f("Due today",F,e.jsx(L,{className:"h-3.5 w-3.5"}),"text-amber-600"),f("Upcoming",K,e.jsx(L,{className:"h-3.5 w-3.5"})),f("Recently completed",C,e.jsx(U,{className:"h-3.5 w-3.5"}),"text-emerald-600")]})})]})}function x(h,p){return async()=>{let l=q.from(h).select("*",{count:"exact",head:!0});p&&(l=p(l));const{count:c,error:m}=await l;if(m)throw m;return c??0}}function ce(){const{user:h,roles:p}=A(),{unseen:l}=M(),c=s=>new Date(Date.now()-s*864e5).toISOString(),m=n({queryKey:["kpi","posts"],queryFn:x("blog_posts",s=>s.eq("status","published"))}),v=n({queryKey:["kpi","services"],queryFn:x("services")}),D=n({queryKey:["kpi","projects"],queryFn:x("projects")}),F=n({queryKey:["kpi","views-today"],queryFn:x("page_views",s=>s.gte("created_at",new Date(new Date().setHours(0,0,0,0)).toISOString()))}),K=n({queryKey:["kpi","testimonials"],queryFn:x("testimonials")}),C=n({queryKey:["kpi","orders7"],queryFn:x("service_orders",s=>s.gte("created_at",c(7)))}),f=n({queryKey:["kpi","unread"],queryFn:x("contact_submissions",s=>s.eq("is_read",!1))}),a=n({queryKey:["kpi","users"],queryFn:x("profiles")}),i=n({queryKey:["dashboard-recent-leads"],queryFn:async()=>{const{data:s,error:r}=await q.from("leads").select("id, name, email, service_interest, status, created_at").order("created_at",{ascending:!1}).limit(8);if(r)throw r;return s}}),k=n({queryKey:["dashboard-leads-trend"],queryFn:async()=>{const{data:s,error:r}=await q.from("leads").select("created_at").gte("created_at",c(30));if(r)throw r;const o={};for(let t=29;t>=0;t--){const d=new Date(Date.now()-t*864e5);o[d.toISOString().slice(0,10)]=0}for(const t of s??[]){const d=t.created_at.slice(0,10);d in o&&(o[d]+=1)}return Object.entries(o).map(([t,d])=>({day:t.slice(5),count:d}))}}),u=n({queryKey:["dashboard-top-pages"],queryFn:async()=>{const{data:s,error:r}=await q.from("page_views").select("path").gte("created_at",c(30)).limit(1e4);if(r)throw r;const o={};for(const t of s??[])o[t.path]=(o[t.path]??0)+1;return Object.entries(o).sort((t,d)=>d[1]-t[1]).slice(0,8).map(([t,d])=>({path:t,count:d}))}}),y=[{label:"Published posts",value:m.data,icon:W,to:"/admin/blog"},{label:"Services",value:v.data,icon:B,to:"/admin/services"},{label:"Portfolio items",value:D.data,icon:I,to:"/admin/portfolio"},{label:"Testimonials",value:K.data,icon:P,to:"/admin/testimonials"},{label:"New orders (7d)",value:C.data,icon:O,to:"/admin/orders",accent:!0,unseenKey:"orders"},{label:"Unread contacts",value:f.data,icon:H,to:"/admin/contacts",accent:!0,unseenKey:"contacts"},{label:"Views today",value:F.data,icon:V,to:"/admin/analytics"},{label:"Registered users",value:a.data,icon:$,to:"/admin/users"}];return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"text-2xl font-semibold",children:"Welcome back"}),e.jsxs("p",{className:"text-muted-foreground text-sm",children:["Signed in as ",h==null?void 0:h.email,p.length>
10&&e.jsxs(e.Fragment,{children:[" · roles: ",p.join(", ")]})]})]}),e.jsx("div",{className:"grid gap-4 sm:grid-cols-2 lg:grid-cols-4",children:y.map(s=>{const r=s.unseenKey?l[s.unseenKey]:!1;return e.jsx(N,{to:s.to,className:"group",children:e.jsxs(g,{className:`relative transition hover:border-primary/40 hover:shadow-sm ${r?"border-red-500/50":""}`,children:[r&&e.jsxs("span",{className:"absolute top-2 right-2 flex h-2.5 w-2.5",children:[e.jsx("span",{className:"animate-ping absolute inline-flex h-full w-full rounded-full bg-red-500 opacity-75"}),e.jsx("span",{className:"relative inline-flex rounded-full h-2.5 w-2.5 bg-red-500"})]}),e.jsxs(b,{className:"pb-2 flex-row items-center justify-between space-y-0",children:[e.jsx(_,{className:"text-xs font-medium text-muted-foreground uppercase tracking-wide",children:s.label}),e.jsx(s.icon,{className:`h-4 w-4 ${s.accent?"text-primary":"text-muted-foreground"}`})]}),e.jsx(w,{children:s.value==null?e.jsx(j,{className:"h-9 w-16"}):e.jsx("div",{className:"text-3xl font-semibold",children:s.value})})]})},s.label)})}),e.jsx(g,{className:"relative overflow-hidden border-primary/30 bg-gradient-to-br from-primary/10 via-primary/5 to-transparent",children:e.jsxs(w,{className:"flex flex-col sm:flex-row items-start sm:items-center justify-between gap-4 p-5",children:[e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx("div",{className:"rounded-xl bg-primary/15 text-primary p-2.5",children:e.jsx(O,{className:"h-5 w-5"})}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-semibold",children:"Need to place an order for a customer?"}),e.jsx("p",{className:"text-xs text-muted-foreground mt-0.5",children:"Walk a client through the multi-step order wizard and capture every detail."})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(N,{to:"/admin/orders",children:e.jsx(S,{variant:"outline",size:"sm",children:"View orders"})}),e.jsx(N,{to:"/order",target:"_blank",rel:"noopener",children:e.jsxs(S,{size:"sm",children:["Place an order ",e.jsx(G,{className:"h-4 w-4 ml-1"})]})})]})]})}),e.jsxs("div",{className:"grid gap-4 lg:grid-cols-3",children:[e.jsxs(g,{className:"lg:col-span-2",children:[e.jsx(b,{children:e.jsx(_,{className:"text-base",children:"Leads — last 30 days"})}),e.jsx(w,{className:"h-[260px]",children:k.isLoading?e.jsx(j,{className:"h-full w-full"}):e.jsx(Q,{width:"100%",height:"100%",children:e.jsxs(X,{data:k.data??[],children:[e.jsx("defs",{children:e.jsxs("linearGradient",{id:"leadsFill",x1:"0",y1:"0",x2:"0",y2:"1",children:[e.jsx("stop",{offset:"0%",stopColor:"hsl(var(--primary))",stopOpacity:.4}),e.jsx("stop",{offset:"100%",stopColor:"hsl(var(--primary))",stopOpacity:0})]})}),e.jsx(Y,{strokeDasharray:"3 3",stroke:"hsl(var(--border))"}),e.jsx(E,{dataKey:"day",stroke:"hsl(var(--muted-foreground))",fontSize:11}),e.jsx(J,{allowDecimals:!1,stroke:"hsl(var(--muted-foreground))",fontSize:11}),e.jsx(Z,{contentStyle:{background:"hsl(var(--popover))",border:"1px solid hsl(var(--border))",borderRadius:8,fontSize:12}}),e.jsx(ee,{type:"monotone",dataKey:"count",stroke:"hsl(var(--primary))",fill:"url(#leadsFill)",strokeWidth:2})]})})})]}),e.jsx(se,{}),e.jsxs(g,{children:[e.jsx(b,{children:e.jsx(_,{className:"text-base",children:"Recent leads"})}),e.jsxs(w,{className:"space-y-3",children:[i.isLoading&&e.jsxs(e.Fragment,{children:[e.jsx(j,{className:"h-10 w-full"}),e.jsx(j,{className:"h-10 w-full"}),e.jsx(j,{className:"h-10 w-full"})]}),(i.data??[]).length===0&&!i.isLoading&&e.jsx("p",{className:"text-sm text-muted-foreground",children:"No leads yet."}),(i.data??[]).map(s=>e.jsxs(N,{to:"/admin/leads",className:"flex items-center justify-between gap-2 rounded-md border p-2 hover:bg-muted/50",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"text-sm font-medium truncate",children:s.name??s.email??"Unknown"}),e.jsx("div",{className:"text-xs text-muted-foreground truncate",children:s.email})]}),e.jsx(T,{variant:"outline",className:"capitalize text-xs",children:s.status??"new"})]},s.id))]})]})]}),e.jsxs(g,{children:[e.jsx(b,{children:e.jsx(_,{className:"text-base",children:"Top pages — last 30 days"})}),e.jsxs(w,{children:[u.isLoading&&e.jsx(j,{className:"h-32 w-full"}),!u.isLoading&&(u.data??[]).length===0&&e.jsx("p",{className:"text-sm text-muted-foreground",children:"No page views recorded yet. Visit the public site in another tab to start collecting."}),(u.data??[]).length>0&&e.jsx("div",{className:"space-y-1",children:(u.data??[]).map(s=>{const r=u.data[0].count,o=s.count/r*100;return e.jsxs("div",{className:"flex items-center gap-3 text-sm",children:[e.jsx("div",{className:"w-1/2 truncate font-mono text-xs",children:s.path}),e.jsx("div",{className:"flex-1 bg-muted rounded h-2 overflow-hidden",children:e.jsx("div",{className:"h-full bg-primary",style:{width:`${o}%`}})}),e.jsx("div",{className:"w-12 text-right tabular-nums text-muted-foreground",children:s.count})]},s.path)})})]})]})]})}export{ce 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.