2 lines
9.9 KiB
JavaScript
2 lines
9.9 KiB
JavaScript
import{r as W,j as e,i as M,S as o,B as c,T as n,u as q,a as z,b as h,t as S,C as Q,d as J,U as I,D as E,c as K,f as X,e as Y,g as Z,h as ee}from"./index-D7LVXeIK.js";import{d as te}from"./Refresh-DA6RLQV4.js";import{d as re,a as se,b as ae,S as L}from"./StatusChip-B_YdJiMW.js";import{P as F,A as ne,G as m}from"./PageHeader-naLAT9xr.js";import{S as w,E as _}from"./EmptyState-B9FcYx_n.js";import{B}from"./Button-Bqp5awT1.js";import{T as ie,a as oe,b as le,c as N,d as ce}from"./TableRow-jBgitpDf.js";import{T as d}from"./TableCell-DreGbAeW.js";import{L as de}from"./LinearProgress-yV9HNsZU.js";import{C as xe}from"./Link-BEif5YS2.js";var A={},ue=M;Object.defineProperty(A,"__esModule",{value:!0});var H=A.default=void 0,he=ue(W()),me=e;H=A.default=(0,he.default)((0,me.jsx)("path",{d:"M13 3c-4.97 0-9 4.03-9 9H1l3.89 3.89.07.14L9 12H6c0-3.87 3.13-7 7-7s7 3.13 7 7-3.13 7-7 7c-1.93 0-3.68-.79-4.94-2.06l-1.42 1.42C8.27 19.99 10.51 21 13 21c4.97 0 9-4.03 9-9s-4.03-9-9-9m-1 5v5l4.25 2.52.77-1.28-3.52-2.09V8z"}),"HistoryOutlined");var k={},pe=M;Object.defineProperty(k,"__esModule",{value:!0});var U=k.default=void 0,je=pe(W()),ge=e;U=k.default=(0,je.default)((0,ge.jsx)("path",{d:"M13 5.08c3.06.44 5.48 2.86 5.92 5.92h3.03c-.47-4.72-4.23-8.48-8.95-8.95zM18.92 13c-.44 3.06-2.86 5.48-5.92 5.92v3.03c4.72-.47 8.48-4.23 8.95-8.95zM11 18.92c-3.39-.49-6-3.4-6-6.92s2.61-6.43 6-6.92V2.05c-5.05.5-9 4.76-9 9.95 0 5.19 3.95 9.45 9 9.95z"}),"DonutLargeOutlined");var O={},fe=M;Object.defineProperty(O,"__esModule",{value:!0});var V=O.default=void 0,be=fe(W()),ye=e;V=O.default=(0,be.default)((0,ye.jsx)("path",{d:"m12 2-5.5 9h11zm0 3.84L13.93 9h-3.87zM17.5 13c-2.49 0-4.5 2.01-4.5 4.5s2.01 4.5 4.5 4.5 4.5-2.01 4.5-4.5-2.01-4.5-4.5-4.5m0 7c-1.38 0-2.5-1.12-2.5-2.5s1.12-2.5 2.5-2.5 2.5 1.12 2.5 2.5-1.12 2.5-2.5 2.5M3 21.5h8v-8H3zm2-6h4v4H5z"}),"CategoryOutlined");function ve({data:x=[],size:a=180,thickness:s=26,centerLabel:p,centerValue:j}){const b=x.reduce((i,f)=>i+f.value,0)||1,g=(a-s)/2,y=2*Math.PI*g;let v=0;return e.jsxs(o,{direction:{xs:"column",sm:"row"},spacing:3,alignItems:"center",justifyContent:"center",sx:{flexWrap:"wrap"},children:[e.jsxs(c,{sx:{position:"relative",width:a,maxWidth:"100%",aspectRatio:"1 / 1"},children:[e.jsx("svg",{width:"100%",height:"100%",viewBox:`0 0 ${a} ${a}`,children:e.jsxs("g",{transform:`rotate(-90 ${a/2} ${a/2})`,children:[e.jsx("circle",{cx:a/2,cy:a/2,r:g,fill:"none",stroke:"#F0F0F0",strokeWidth:s}),x.map((i,f)=>{const u=i.value/b*y,C=e.jsx("circle",{cx:a/2,cy:a/2,r:g,fill:"none",stroke:i.color,strokeWidth:s,strokeDasharray:`${u} ${y-u}`,strokeDashoffset:-v,strokeLinecap:"butt"},f);return v+=u,C})]})}),e.jsxs(c,{sx:{position:"absolute",inset:0,display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center"},children:[e.jsx(n,{variant:"h3",sx:{fontWeight:700},children:j??b}),e.jsx(n,{variant:"caption",color:"text.secondary",children:p??"Total"})]})]}),e.jsx(o,{spacing:1.25,children:x.map(i=>e.jsxs(o,{direction:"row",spacing:1,alignItems:"center",children:[e.jsx(c,{sx:{width:10,height:10,borderRadius:"3px",bgcolor:i.color}}),e.jsx(n,{variant:"body2",color:"text.secondary",sx:{minWidth:80},children:i.label}),e.jsx(n,{variant:"subtitle2",children:i.value.toLocaleString("en-IN")})]},i.label))})]})}const Ce={newclient:"#00A2AE",contacted:"#FFBF00",onboarded:"#00A854",lost:"#F04134"},Se=x=>Ce[String(x||"").toLowerCase()]||"#8C8C8C",T=["#C01227","#00A2AE","#00A854","#FFBF00","#9E0E20","#8C8C8C","#D6515C"];function $({icon:x,title:a,action:s,color:p="primary",noPadding:j=!1,children:b}){return e.jsxs(xe,{sx:{height:"100%",display:"flex",flexDirection:"column",borderRadius:4,boxShadow:"0 10px 30px rgba(0,0,0,0.03)",border:"1px solid rgba(0,0,0,0.04)"},children:[e.jsxs(o,{direction:"row",spacing:1.5,alignItems:"center",sx:{px:{xs:2,sm:2.5},py:2,borderBottom:1,borderColor:"divider",background:g=>`linear-gradient(90deg, ${g.palette[p].lighter}66 0%, transparent 100%)`},children:[e.jsx(c,{sx:{width:40,height:40,borderRadius:2,flexShrink:0,display:"flex",alignItems:"center",justifyContent:"center",bgcolor:`${p}.lighter`,color:`${p}.main`,boxShadow:"inset 0 0 0 1px rgba(0,0,0,0.05)"},children:e.jsx(x,{fontSize:"small"})}),e.jsx(n,{variant:"h6",sx:{fontWeight:700,color:"grey.800",flexGrow:1,letterSpacing:"-0.3px"},children:a}),s]}),e.jsx(c,{sx:{p:j?0:{xs:2,sm:3},flexGrow:1},children:b})]})}function Ae(){var P;const x=q(),a=z(x.breakpoints.down("sm")),[s,p]=h.useState([]),[j,b]=h.useState([]),[g,y]=h.useState(!0),[v,i]=h.useState(null),f=()=>{y(!0),i(null),Promise.all([X(),Y()]).then(([t,r])=>{p((t||[]).map(Z)),b((r||[]).map(ee))}).catch(t=>i(t.message||"Failed to load dashboard data")).finally(()=>y(!1))};h.useEffect(()=>{f()},[]);const u=h.useMemo(()=>({total:s.length,newCount:s.filter(t=>t.status==="newClient").length,parcels:s.reduce((t,r)=>t+r.parcelVolume,0),contracts:s.reduce((t,r)=>t+r.activeContracts,0)}),[s]),C=h.useMemo(()=>{const t={};return s.forEach(r=>{t[r.status]=(t[r.status]||0)+1}),Object.entries(t).sort((r,l)=>l[1]-r[1]).map(([r,l])=>({label:S(r),value:l,color:Se(r)}))},[s]),D=h.useMemo(()=>{const t={};return s.forEach(r=>{const l=r.businessType||"other";t[l]=(t[l]||0)+1}),Object.entries(t).sort((r,l)=>l[1]-r[1])},[s]),G=((P=D[0])==null?void 0:P[1])||1,R=h.useMemo(()=>[...s].sort((t,r)=>String(r.lastUpdated).localeCompare(String(t.lastUpdated))).slice(0,6),[s]);return new Date().toLocaleDateString("en-IN",{weekday:"long",day:"numeric",month:"long",year:"numeric"}),g?e.jsxs(e.Fragment,{children:[e.jsx(F,{title:"Dashboard",breadcrumbs:[{label:"Dashboard"}]}),e.jsx(c,{sx:{display:"flex",justifyContent:"center",py:12},children:e.jsx(Q,{})})]}):e.jsxs(e.Fragment,{children:[e.jsx(F,{title:"Dashboard",breadcrumbs:[{label:"Dashboard"}],action:e.jsx(B,{variant:"outlined",startIcon:e.jsx(te,{}),onClick:f,children:"Refresh"})}),v&&e.jsx(ne,{severity:"error",sx:{mb:2.5},action:e.jsx(B,{color:"inherit",size:"small",onClick:f,children:"Retry"}),children:v}),e.jsxs(m,{container:!0,spacing:2.5,children:[e.jsx(m,{item:!0,xs:12,sm:6,lg:3,children:e.jsx(w,{accent:!0,title:"Total Clients",value:u.total,icon:J,color:"primary",caption:"All registered"})}),e.jsx(m,{item:!0,xs:12,sm:6,lg:3,children:e.jsx(w,{accent:!0,title:"New Clients",value:u.newCount,icon:re,color:"primary",caption:"Awaiting onboarding"})}),e.jsx(m,{item:!0,xs:12,sm:6,lg:3,children:e.jsx(w,{accent:!0,title:"Total Parcel Volume",value:u.parcels.toLocaleString("en-IN"),icon:se,color:"primary",caption:"Across all clients"})}),e.jsx(m,{item:!0,xs:12,sm:6,lg:3,children:e.jsx(w,{accent:!0,title:"Active Contracts",value:u.contracts,icon:ae,color:"primary",caption:"Currently running"})}),e.jsx(m,{item:!0,xs:12,lg:8,children:e.jsx($,{icon:H,title:"Recent Clients",color:"primary",noPadding:!0,children:R.length===0?e.jsx(_,{title:"No clients yet",caption:"Add a client to see it here."}):a?e.jsx(o,{divider:e.jsx(E,{}),children:R.map(t=>e.jsxs(o,{direction:"row",spacing:1.25,alignItems:"center",sx:{px:2,py:1.5},children:[e.jsx(I,{name:t.name,size:36}),e.jsxs(c,{sx:{minWidth:0,flexGrow:1},children:[e.jsx(n,{variant:"body2",sx:{fontWeight:600,color:"grey.800"},noWrap:!0,children:t.name}),e.jsxs(n,{variant:"caption",color:"text.secondary",noWrap:!0,sx:{display:"block"},children:[[S(t.businessType),t.city].filter(Boolean).join(" · ")||"—"," · ",t.parcelVolume.toLocaleString("en-IN")," parcels"]})]}),e.jsx(L,{status:t.status})]},t.id))}):e.jsx(ie,{children:e.jsxs(oe,{sx:{minWidth:600},children:[e.jsx(le,{children:e.jsxs(N,{sx:{"& th":{bgcolor:"grey.50",fontWeight:700,color:"grey.700",textTransform:"uppercase",fontSize:"0.72rem",letterSpacing:.4}},children:[e.jsx(d,{children:"Client"}),e.jsx(d,{children:"Type"}),e.jsx(d,{children:"Location"}),e.jsx(d,{align:"right",children:"Parcels"}),e.jsx(d,{children:"Status"})]})}),e.jsx(ce,{children:R.map(t=>e.jsxs(N,{hover:!0,children:[e.jsx(d,{children:e.jsxs(o,{direction:"row",spacing:1.25,alignItems:"center",children:[e.jsx(I,{name:t.name,size:32}),e.jsx(n,{variant:"body2",sx:{fontWeight:600,color:"grey.800"},children:t.name})]})}),e.jsx(d,{children:e.jsx(n,{variant:"body2",children:S(t.businessType)||"—"})}),e.jsx(d,{children:e.jsxs(n,{variant:"body2",children:[t.city||"—",t.businessState?`, ${t.businessState}`:""]})}),e.jsx(d,{align:"right",sx:{fontWeight:600},children:t.parcelVolume.toLocaleString("en-IN")}),e.jsx(d,{children:e.jsx(L,{status:t.status})})]},t.id))})]})})})}),e.jsx(m,{item:!0,xs:12,lg:4,children:e.jsx($,{icon:U,title:"Clients by Status",color:"primary",children:e.jsx(c,{sx:{py:1.5},children:C.length===0?e.jsx(_,{title:"No data"}):e.jsx(ve,{data:C,centerValue:u.total,centerLabel:"Clients"})})})}),e.jsx(m,{item:!0,xs:12,lg:8,children:e.jsx($,{icon:V,title:"Clients by Business Type",color:"primary",children:D.length===0?e.jsx(_,{title:"No data"}):e.jsx(o,{spacing:2,children:D.map(([t,r],l)=>e.jsxs(c,{children:[e.jsxs(o,{direction:"row",justifyContent:"space-between",alignItems:"center",sx:{mb:.75},children:[e.jsxs(o,{direction:"row",spacing:1,alignItems:"center",children:[e.jsx(c,{sx:{width:10,height:10,borderRadius:"3px",bgcolor:T[l%T.length]}}),e.jsx(n,{variant:"body2",sx:{fontWeight:600,color:"grey.800"},children:S(t)})]}),e.jsxs(n,{variant:"body2",color:"text.secondary",children:[r," · ",Math.round(r/s.length*100),"%"]})]}),e.jsx(de,{variant:"determinate",value:r/G*100,sx:{height:8,borderRadius:4,bgcolor:"grey.100","& .MuiLinearProgress-bar":{borderRadius:4,backgroundColor:T[l%T.length]}}})]},t))})})}),e.jsx(m,{item:!0,xs:12,lg:4,children:e.jsx($,{icon:K,title:`App Users · ${j.length}`,color:"primary",children:j.length===0?e.jsx(_,{title:"No team users"}):e.jsx(o,{divider:e.jsx(E,{}),spacing:0,children:j.slice(0,6).map(t=>e.jsxs(o,{direction:"row",spacing:1.5,alignItems:"center",sx:{py:1.5},children:[e.jsx(I,{name:t.name,size:36}),e.jsxs(c,{sx:{flexGrow:1,minWidth:0},children:[e.jsx(n,{variant:"subtitle2",sx:{fontWeight:600},children:t.name}),e.jsx(n,{variant:"caption",color:"text.secondary",noWrap:!0,sx:{display:"block"},children:t.email})]}),e.jsx(L,{status:t.role})]},t.id))})})})]})]})}export{Ae as default};
|