2 lines
9.3 KiB
JavaScript
2 lines
9.3 KiB
JavaScript
import{r as R,j as e,i as T,S as c,B as d,T as i,a as u,t as D,C as U,d as V,U as W,b as q,D as G,f as z,c as J,e as K,g as Q}from"./index-DdJWTZFy.js";import{d as X}from"./Refresh-DEoCZISD.js";import{S as C,d as Y,a as Z,b as ee,c as P}from"./StatusChip-VSepiSqW.js";import{P as k,G as h}from"./PageHeader-CdP5B6Qy.js";import{E as S}from"./EmptyState-CQsHTCg9.js";import{B as E}from"./Button-Bcwcjqrt.js";import{A as te}from"./Alert-CzmzDPlp.js";import{T as re,a as se,b as ae,c as F,d as o,e as ne}from"./TableRow-CEoQ4SIZ.js";import{L as ie}from"./LinearProgress-C8QvFQwb.js";import{C as le}from"./Link-Dp34e72e.js";var I={},oe=T;Object.defineProperty(I,"__esModule",{value:!0});var B=I.default=void 0,ce=oe(R()),de=e;B=I.default=(0,ce.default)((0,de.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 L={},xe=T;Object.defineProperty(L,"__esModule",{value:!0});var N=L.default=void 0,ue=xe(R()),he=e;N=L.default=(0,ue.default)((0,he.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 A={},me=T;Object.defineProperty(A,"__esModule",{value:!0});var H=A.default=void 0,ge=me(R()),je=e;H=A.default=(0,ge.default)((0,je.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 pe({data:s=[],size:n=180,thickness:x=26,centerLabel:g,centerValue:y}){const j=s.reduce((a,b)=>a+b.value,0)||1,m=(n-x)/2,v=2*Math.PI*m;let f=0;return e.jsxs(c,{direction:{xs:"column",sm:"row"},spacing:3,alignItems:"center",justifyContent:"center",sx:{flexWrap:"wrap"},children:[e.jsxs(d,{sx:{position:"relative",width:n,maxWidth:"100%",aspectRatio:"1 / 1"},children:[e.jsx("svg",{width:"100%",height:"100%",viewBox:`0 0 ${n} ${n}`,children:e.jsxs("g",{transform:`rotate(-90 ${n/2} ${n/2})`,children:[e.jsx("circle",{cx:n/2,cy:n/2,r:m,fill:"none",stroke:"#F0F0F0",strokeWidth:x}),s.map((a,b)=>{const p=a.value/j*v,$=e.jsx("circle",{cx:n/2,cy:n/2,r:m,fill:"none",stroke:a.color,strokeWidth:x,strokeDasharray:`${p} ${v-p}`,strokeDashoffset:-f,strokeLinecap:"butt"},b);return f+=p,$})]})}),e.jsxs(d,{sx:{position:"absolute",inset:0,display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center"},children:[e.jsx(i,{variant:"h3",sx:{fontWeight:700},children:y??j}),e.jsx(i,{variant:"caption",color:"text.secondary",children:g??"Total"})]})]}),e.jsx(c,{spacing:1.25,children:s.map(a=>e.jsxs(c,{direction:"row",spacing:1,alignItems:"center",children:[e.jsx(d,{sx:{width:10,height:10,borderRadius:"3px",bgcolor:a.color}}),e.jsx(i,{variant:"body2",color:"text.secondary",sx:{minWidth:80},children:a.label}),e.jsx(i,{variant:"subtitle2",children:a.value.toLocaleString("en-IN")})]},a.label))})]})}const fe={newclient:"#00A2AE",contacted:"#FFBF00",onboarded:"#00A854",lost:"#F04134"},be=s=>fe[String(s||"").toLowerCase()]||"#8C8C8C",w=["#C01227","#00A2AE","#00A854","#FFBF00","#9E0E20","#8C8C8C","#D6515C"];function _({icon:s,title:n,action:x,color:g="primary",noPadding:y=!1,children:j}){return e.jsxs(le,{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(c,{direction:"row",spacing:1.5,alignItems:"center",sx:{px:3,py:2,borderBottom:1,borderColor:"divider",background:m=>`linear-gradient(90deg, ${m.palette[g].lighter}66 0%, transparent 100%)`},children:[e.jsx(d,{sx:{width:40,height:40,borderRadius:2,flexShrink:0,display:"flex",alignItems:"center",justifyContent:"center",bgcolor:`${g}.lighter`,color:`${g}.main`,boxShadow:"inset 0 0 0 1px rgba(0,0,0,0.05)"},children:e.jsx(s,{fontSize:"small"})}),e.jsx(i,{variant:"h6",sx:{fontWeight:700,color:"grey.800",flexGrow:1,letterSpacing:"-0.3px"},children:n}),x]}),e.jsx(d,{sx:{p:y?0:3,flexGrow:1},children:j})]})}function Ie(){var O;const[s,n]=u.useState([]),[x,g]=u.useState([]),[y,j]=u.useState(!0),[m,v]=u.useState(null),f=()=>{j(!0),v(null),Promise.all([z(),J()]).then(([t,r])=>{n((t||[]).map(K)),g((r||[]).map(Q))}).catch(t=>v(t.message||"Failed to load dashboard data")).finally(()=>j(!1))};u.useEffect(()=>{f()},[]);const a=u.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]),b=u.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:D(r),value:l,color:be(r)}))},[s]),p=u.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]),$=((O=p[0])==null?void 0:O[1])||1,M=u.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"}),y?e.jsxs(e.Fragment,{children:[e.jsx(k,{title:"Dashboard",breadcrumbs:[{label:"Dashboard"}]}),e.jsx(d,{sx:{display:"flex",justifyContent:"center",py:12},children:e.jsx(U,{})})]}):e.jsxs(e.Fragment,{children:[e.jsx(k,{title:"Dashboard",breadcrumbs:[{label:"Dashboard"}],action:e.jsx(E,{variant:"outlined",startIcon:e.jsx(X,{}),onClick:f,children:"Refresh"})}),m&&e.jsx(te,{severity:"error",sx:{mb:2.5},action:e.jsx(E,{color:"inherit",size:"small",onClick:f,children:"Retry"}),children:m}),e.jsxs(h,{container:!0,spacing:3,children:[e.jsx(h,{item:!0,xs:12,sm:6,lg:3,children:e.jsx(C,{accent:!0,title:"Total Clients",value:a.total,icon:V,color:"primary",caption:"All registered"})}),e.jsx(h,{item:!0,xs:12,sm:6,lg:3,children:e.jsx(C,{accent:!0,title:"New Clients",value:a.newCount,icon:Y,color:"primary",caption:"Awaiting onboarding"})}),e.jsx(h,{item:!0,xs:12,sm:6,lg:3,children:e.jsx(C,{accent:!0,title:"Total Parcel Volume",value:a.parcels.toLocaleString("en-IN"),icon:Z,color:"primary",caption:"Across all clients"})}),e.jsx(h,{item:!0,xs:12,sm:6,lg:3,children:e.jsx(C,{accent:!0,title:"Active Contracts",value:a.contracts,icon:ee,color:"primary",caption:"Currently running"})}),e.jsx(h,{item:!0,xs:12,lg:8,children:e.jsx(_,{icon:B,title:"Recent Clients",color:"primary",noPadding:!0,children:M.length===0?e.jsx(S,{title:"No clients yet",caption:"Add a client to see it here."}):e.jsx(re,{children:e.jsxs(se,{sx:{minWidth:600},children:[e.jsx(ae,{children:e.jsxs(F,{sx:{"& th":{bgcolor:"grey.50",fontWeight:700,color:"grey.700",textTransform:"uppercase",fontSize:"0.72rem",letterSpacing:.4}},children:[e.jsx(o,{children:"Client"}),e.jsx(o,{children:"Type"}),e.jsx(o,{children:"Location"}),e.jsx(o,{align:"right",children:"Parcels"}),e.jsx(o,{children:"Status"})]})}),e.jsx(ne,{children:M.map(t=>e.jsxs(F,{hover:!0,children:[e.jsx(o,{children:e.jsxs(c,{direction:"row",spacing:1.25,alignItems:"center",children:[e.jsx(W,{name:t.name,size:32}),e.jsx(i,{variant:"body2",sx:{fontWeight:600,color:"grey.800"},children:t.name})]})}),e.jsx(o,{children:e.jsx(i,{variant:"body2",children:D(t.businessType)||"—"})}),e.jsx(o,{children:e.jsxs(i,{variant:"body2",children:[t.city||"—",t.businessState?`, ${t.businessState}`:""]})}),e.jsx(o,{align:"right",sx:{fontWeight:600},children:t.parcelVolume.toLocaleString("en-IN")}),e.jsx(o,{children:e.jsx(P,{status:t.status})})]},t.id))})]})})})}),e.jsx(h,{item:!0,xs:12,lg:4,children:e.jsx(_,{icon:N,title:"Clients by Status",color:"primary",children:e.jsx(d,{sx:{py:1.5},children:b.length===0?e.jsx(S,{title:"No data"}):e.jsx(pe,{data:b,centerValue:a.total,centerLabel:"Clients"})})})}),e.jsx(h,{item:!0,xs:12,lg:8,children:e.jsx(_,{icon:H,title:"Clients by Business Type",color:"primary",children:p.length===0?e.jsx(S,{title:"No data"}):e.jsx(c,{spacing:2.25,children:p.map(([t,r],l)=>e.jsxs(d,{children:[e.jsxs(c,{direction:"row",justifyContent:"space-between",alignItems:"center",sx:{mb:.75},children:[e.jsxs(c,{direction:"row",spacing:1,alignItems:"center",children:[e.jsx(d,{sx:{width:10,height:10,borderRadius:"3px",bgcolor:w[l%w.length]}}),e.jsx(i,{variant:"body2",sx:{fontWeight:600,color:"grey.800"},children:D(t)})]}),e.jsxs(i,{variant:"body2",color:"text.secondary",children:[r," · ",Math.round(r/s.length*100),"%"]})]}),e.jsx(ie,{variant:"determinate",value:r/$*100,sx:{height:8,borderRadius:4,bgcolor:"grey.100","& .MuiLinearProgress-bar":{borderRadius:4,backgroundColor:w[l%w.length]}}})]},t))})})}),e.jsx(h,{item:!0,xs:12,lg:4,children:e.jsx(_,{icon:q,title:`App Users · ${x.length}`,color:"primary",children:x.length===0?e.jsx(S,{title:"No team users"}):e.jsx(c,{divider:e.jsx(G,{}),spacing:0,children:x.slice(0,6).map(t=>e.jsxs(c,{direction:"row",spacing:1.5,alignItems:"center",sx:{py:1.25},children:[e.jsx(W,{name:t.name,size:36}),e.jsxs(d,{sx:{flexGrow:1,minWidth:0},children:[e.jsx(i,{variant:"subtitle2",sx:{fontWeight:600},children:t.name}),e.jsx(i,{variant:"caption",color:"text.secondary",noWrap:!0,sx:{display:"block"},children:t.email})]}),e.jsx(P,{status:t.role})]},t.id))})})})]})]})}export{Ie as default};
|