2 lines
9.7 KiB
JavaScript
2 lines
9.7 KiB
JavaScript
import{r as I,j as e,i as D,S as c,B as d,T as i,a as u,C as z,d as q,U as k,b as G,D as Z,f as P,c as E}from"./index-f5ufbVS4.js";import{d as J,E as C,T as K,a as Q,b as W,c as o,e as X}from"./EmptyState-BPdKVv2W.js";import{S,d as Y,a as ee,b as te,c as F}from"./StatusChip-Dl60lQE0.js";import{P as N,A as re,G as h}from"./PageHeader-DHYHaw0X.js";import{B as U}from"./Button-BaZR7WeN.js";import{L as se}from"./LinearProgress-E2XIe7tJ.js";import{C as ae}from"./Link-Cy8xcTJL.js";var L={},ne=D;Object.defineProperty(L,"__esModule",{value:!0});var B=L.default=void 0,ie=ne(I()),le=e;B=L.default=(0,ie.default)((0,le.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 R={},oe=D;Object.defineProperty(R,"__esModule",{value:!0});var H=R.default=void 0,ce=oe(I()),de=e;H=R.default=(0,ce.default)((0,de.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={},xe=D;Object.defineProperty(A,"__esModule",{value:!0});var V=A.default=void 0,ue=xe(I()),he=e;V=A.default=(0,ue.default)((0,he.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 ge({data:r=[],size:s=180,thickness:x=26,centerLabel:m,centerValue:y}){const p=r.reduce((n,b)=>n+b.value,0)||1,g=(s-x)/2,v=2*Math.PI*g;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:s,maxWidth:"100%",aspectRatio:"1 / 1"},children:[e.jsx("svg",{width:"100%",height:"100%",viewBox:`0 0 ${s} ${s}`,children:e.jsxs("g",{transform:`rotate(-90 ${s/2} ${s/2})`,children:[e.jsx("circle",{cx:s/2,cy:s/2,r:g,fill:"none",stroke:"#F0F0F0",strokeWidth:x}),r.map((n,b)=>{const j=n.value/p*v,$=e.jsx("circle",{cx:s/2,cy:s/2,r:g,fill:"none",stroke:n.color,strokeWidth:x,strokeDasharray:`${j} ${v-j}`,strokeDashoffset:-f,strokeLinecap:"butt"},b);return f+=j,$})]})}),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??p}),e.jsx(i,{variant:"caption",color:"text.secondary",children:m??"Total"})]})]}),e.jsx(c,{spacing:1.25,children:r.map(n=>e.jsxs(c,{direction:"row",spacing:1,alignItems:"center",children:[e.jsx(d,{sx:{width:10,height:10,borderRadius:"3px",bgcolor:n.color}}),e.jsx(i,{variant:"body2",color:"text.secondary",sx:{minWidth:80},children:n.label}),e.jsx(i,{variant:"subtitle2",children:n.value.toLocaleString("en-IN")})]},n.label))})]})}const T=r=>String(r||"").replace(/[_-]+/g," ").replace(/([a-z\d])([A-Z])/g,"$1 $2").replace(/\b\w/g,s=>s.toUpperCase()).trim(),me={newclient:"#00A2AE",contacted:"#FFBF00",onboarded:"#00A854",lost:"#F04134"},pe=r=>me[String(r||"").toLowerCase()]||"#8C8C8C",w=["#C01227","#00A2AE","#00A854","#FFBF00","#9E0E20","#8C8C8C","#D6515C"],je=r=>"CLI-"+String(r).replace(/[^a-zA-Z0-9]/g,"").toUpperCase().substring(0,6).padStart(6,"0");function fe(r){const s=r.payload||{};return{id:r.id,logicalId:je(r.id),name:s.name||"—",businessType:s.businessType||"",city:s.city||"",businessState:s.businessState||"",status:s.status||"unknown",parcelVolume:Number(s.parcelVolume)||0,activeContracts:Number(s.activeContracts)||0,lastUpdated:s.lastUpdated||""}}function be(r){const s=r.payload||{};return{id:r.id,name:s.name||"—",email:s.email||"",role:s.role||"unknown"}}function _({icon:r,title:s,action:x,color:m="primary",noPadding:y=!1,children:p}){return e.jsxs(ae,{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:g=>`linear-gradient(90deg, ${g.palette[m].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:`${m}.lighter`,color:`${m}.main`,boxShadow:"inset 0 0 0 1px rgba(0,0,0,0.05)"},children:e.jsx(r,{fontSize:"small"})}),e.jsx(i,{variant:"h6",sx:{fontWeight:700,color:"grey.800",flexGrow:1,letterSpacing:"-0.3px"},children:s}),x]}),e.jsx(d,{sx:{p:y?0:3,flexGrow:1},children:p})]})}function Te(){var M;const[r,s]=u.useState([]),[x,m]=u.useState([]),[y,p]=u.useState(!0),[g,v]=u.useState(null),f=()=>{p(!0),v(null),Promise.all([P(E.clients),P(E.teamUsers)]).then(([t,a])=>{s(t.map(fe)),m(a.map(be))}).catch(t=>v(t.message||"Failed to load dashboard data")).finally(()=>p(!1))};u.useEffect(()=>{f()},[]);const n=u.useMemo(()=>({total:r.length,newCount:r.filter(t=>t.status==="newClient").length,parcels:r.reduce((t,a)=>t+a.parcelVolume,0),contracts:r.reduce((t,a)=>t+a.activeContracts,0)}),[r]),b=u.useMemo(()=>{const t={};return r.forEach(a=>{t[a.status]=(t[a.status]||0)+1}),Object.entries(t).sort((a,l)=>l[1]-a[1]).map(([a,l])=>({label:T(a),value:l,color:pe(a)}))},[r]),j=u.useMemo(()=>{const t={};return r.forEach(a=>{const l=a.businessType||"other";t[l]=(t[l]||0)+1}),Object.entries(t).sort((a,l)=>l[1]-a[1])},[r]),$=((M=j[0])==null?void 0:M[1])||1,O=u.useMemo(()=>[...r].sort((t,a)=>String(a.lastUpdated).localeCompare(String(t.lastUpdated))).slice(0,6),[r]);return new Date().toLocaleDateString("en-IN",{weekday:"long",day:"numeric",month:"long",year:"numeric"}),y?e.jsxs(e.Fragment,{children:[e.jsx(N,{title:"Dashboard",breadcrumbs:[{label:"Dashboard"}]}),e.jsx(d,{sx:{display:"flex",justifyContent:"center",py:12},children:e.jsx(z,{})})]}):e.jsxs(e.Fragment,{children:[e.jsx(N,{title:"Dashboard",breadcrumbs:[{label:"Dashboard"}],action:e.jsx(U,{variant:"outlined",startIcon:e.jsx(J,{}),onClick:f,children:"Refresh"})}),g&&e.jsx(re,{severity:"error",sx:{mb:2.5},action:e.jsx(U,{color:"inherit",size:"small",onClick:f,children:"Retry"}),children:g}),e.jsxs(h,{container:!0,spacing:3,children:[e.jsx(h,{item:!0,xs:12,sm:6,lg:3,children:e.jsx(S,{accent:!0,title:"Total Clients",value:n.total,icon:q,color:"primary",caption:"All registered"})}),e.jsx(h,{item:!0,xs:12,sm:6,lg:3,children:e.jsx(S,{accent:!0,title:"New Clients",value:n.newCount,icon:Y,color:"primary",caption:"Awaiting onboarding"})}),e.jsx(h,{item:!0,xs:12,sm:6,lg:3,children:e.jsx(S,{accent:!0,title:"Total Parcel Volume",value:n.parcels.toLocaleString("en-IN"),icon:ee,color:"primary",caption:"Across all clients"})}),e.jsx(h,{item:!0,xs:12,sm:6,lg:3,children:e.jsx(S,{accent:!0,title:"Active Contracts",value:n.contracts,icon:te,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:O.length===0?e.jsx(C,{title:"No clients yet",caption:"Add a client to see it here."}):e.jsxs(K,{children:[e.jsx(Q,{children:e.jsxs(W,{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(X,{children:O.map(t=>e.jsxs(W,{hover:!0,children:[e.jsx(o,{children:e.jsxs(c,{direction:"row",spacing:1.25,alignItems:"center",children:[e.jsx(k,{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:T(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(F,{status:t.status})})]},t.id))})]})})}),e.jsx(h,{item:!0,xs:12,lg:4,children:e.jsx(_,{icon:H,title:"Clients by Status",color:"primary",children:e.jsx(d,{sx:{py:1.5},children:b.length===0?e.jsx(C,{title:"No data"}):e.jsx(ge,{data:b,centerValue:n.total,centerLabel:"Clients"})})})}),e.jsx(h,{item:!0,xs:12,lg:8,children:e.jsx(_,{icon:V,title:"Clients by Business Type",color:"primary",children:j.length===0?e.jsx(C,{title:"No data"}):e.jsx(c,{spacing:2.25,children:j.map(([t,a],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:T(t)})]}),e.jsxs(i,{variant:"body2",color:"text.secondary",children:[a," · ",Math.round(a/r.length*100),"%"]})]}),e.jsx(se,{variant:"determinate",value:a/$*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:G,title:`App Users · ${x.length}`,color:"primary",children:x.length===0?e.jsx(C,{title:"No team users"}):e.jsx(c,{divider:e.jsx(Z,{}),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(k,{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(F,{status:t.role})]},t.id))})})})]})]})}export{Te as default};
|