Files
turftracker/frontend/dist/assets/Dashboard-DJdwRlmp.js
2026-04-09 13:19:47 -05:00

2 lines
9.8 KiB
JavaScript

import{u as me,r as a,F as U,a as B,b as C,c as xe,j as e,L as pe,d as he,e as o,f as ge,g as ue,h as ye,i as p,p as je,m as Ne,w as fe}from"./index-9FS9bw8D.js";const ve=()=>{var w,v,b,A,$,R;const{user:m}=me(),[V,h]=a.useState(!0),[g,u]=a.useState(null),[r,Y]=a.useState(null),[d,G]=a.useState(null),[K,Q]=a.useState([]),[y,J]=a.useState([]),[n,j]=a.useState(null),[N,O]=a.useState(null),X=[{name:"Add Property",href:"/properties",icon:U,description:"Set up a new lawn area",color:"bg-blue-500"},{name:"Plan Application",href:"/applications?new=plan",icon:B,description:"Schedule a treatment",color:"bg-green-500"},{name:"Add Equipment",href:"/equipment",icon:C,description:"Register new equipment",color:"bg-purple-500"},{name:"Log Application",href:"/applications?action=log",icon:he,description:"Record completed work",color:"bg-orange-500"}],f=a.useMemo(()=>{if(!(d!=null&&d.monthlyBreakdown))return 0;const s=new Date().getMonth()+1,l=d.monthlyBreakdown.find(i=>i.month===s);return l?l.applications:0},[d]),Z=a.useMemo(()=>[{name:"Properties",value:String((r==null?void 0:r.totalProperties)??0),change:"",changeType:"neutral",icon:U},{name:"This Month's Applications",value:String(f??0),change:"",changeType:"neutral",icon:B},{name:"Equipment Items",value:String((r==null?void 0:r.totalEquipment)??0),change:"",changeType:"neutral",icon:C},{name:"Lawn Sections",value:String((r==null?void 0:r.totalSections)??0),change:"",changeType:"neutral",icon:xe}],[r,f]),ee=a.useMemo(()=>y.slice(0,5).map(s=>{var l;return{id:s.id,title:(l=s.productDetails)!=null&&l.length?`Apply ${s.productDetails.map(i=>i.productName).join(", ")}`:s.equipment_name?`Run ${s.equipment_name}`:"Planned application",property:`${s.property_name}${s.section_names?" - "+s.section_names:""}`,date:s.plannedDate?new Date(s.plannedDate).toLocaleString():"",priority:(()=>{if(!s.plannedDate)return"low";const i=(new Date(s.plannedDate)-new Date)/(1e3*60*60*24);return i<=2?"high":i<=7?"medium":"low"})()}}),[y]);return a.useEffect(()=>{let s=!0;return(async()=>{var i,S,D,P,L,T,_,F,M,E,q,k,I,W,z;try{h(!0),u(null);const[c,se,te]=await Promise.all([ye.getStats(),p.getStats({year:new Date().getFullYear()}),je.getAll()]);if(!s)return;Y(((S=(i=c.data)==null?void 0:i.data)==null?void 0:S.stats)||null),G(((D=se.data)==null?void 0:D.data)||null);const ae=await p.getPlans({upcoming:!0,status:"planned"});if(!s)return;const re=((L=(P=ae.data)==null?void 0:P.data)==null?void 0:L.plans)||[];J(re);const[ne,ie]=await Promise.all([p.getLogs({limit:5}),Ne.getLogs({limit:5})]);if(!s)return;const le=(((_=(T=ne.data)==null?void 0:T.data)==null?void 0:_.logs)||[]).map(t=>({id:`app-${t.id}`,type:"application",title:`Application on ${t.sectionName||"section"}`,property:t.propertyName,date:t.applicationDate||t.createdAt,status:"completed"})),ce=(((M=(F=ie.data)==null?void 0:F.data)==null?void 0:M.logs)||[]).map(t=>({id:`mow-${t.id}`,type:"mowing",title:`Mowed ${t.section_names||t.property_name||""}`.trim(),property:t.property_name,date:t.session_date||t.created_at,status:"completed"})),de=[...le,...ce].filter(t=>t.date).sort((t,oe)=>new Date(oe.date)-new Date(t.date)).slice(0,5).map(t=>({...t,dateText:new Date(t.date).toLocaleString()}));Q(de);const H=((q=(E=te.data)==null?void 0:E.data)==null?void 0:q.properties)||[],x=H.find(t=>t.latitude&&t.longitude)||H[0];if(O(x||null),x)try{const t=await fe.getCurrent(x.id);if(!s)return;j(((I=(k=t.data)==null?void 0:k.data)==null?void 0:I.weather)||null)}catch{j(null)}}catch(c){if(!s)return;u(((z=(W=c==null?void 0:c.response)==null?void 0:W.data)==null?void 0:z.message)||c.message||"Failed to load dashboard")}finally{s&&h(!1)}})(),()=>{s=!1}},[]),e.jsxs("div",{className:"p-6 max-w-7xl mx-auto",children:[e.jsxs("div",{className:"mb-8",children:[e.jsxs("h1",{className:"text-3xl font-bold text-gray-900",children:["Welcome back, ",m==null?void 0:m.firstName,"!"]}),e.jsx("p",{className:"mt-2 text-gray-600",children:"Here's what's happening with your lawn care today."})]}),g&&e.jsx("div",{className:"mb-6 rounded-md bg-red-50 p-4 text-sm text-red-800 border border-red-100",children:g}),V&&e.jsxs("div",{className:"mb-6 flex items-center gap-3 text-gray-600",children:[e.jsx(pe,{size:"sm"})," Loading dashboard…"]}),e.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-6 mb-8",children:Z.map(s=>e.jsx("div",{className:"card",children:e.jsxs("div",{className:"flex items-center",children:[e.jsx("div",{className:"flex-shrink-0",children:e.jsx(s.icon,{className:"h-8 w-8 text-gray-400"})}),e.jsxs("div",{className:"ml-4 flex-1",children:[e.jsx("p",{className:"text-sm font-medium text-gray-500",children:s.name}),e.jsxs("div",{className:"flex items-baseline",children:[e.jsx("p",{className:"text-2xl font-semibold text-gray-900",children:s.value}),s.change&&e.jsx("span",{className:`ml-2 text-sm font-medium ${s.changeType==="positive"?"text-green-600":s.changeType==="negative"?"text-red-600":"text-gray-500"}`,children:s.change})]})]})]})},s.name))}),e.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-3 gap-8",children:[e.jsx("div",{className:"lg:col-span-1",children:e.jsxs("div",{className:"card",children:[e.jsxs("div",{className:"card-header",children:[e.jsx("h3",{className:"text-lg font-medium text-gray-900",children:"Quick Actions"}),e.jsx("p",{className:"text-sm text-gray-500",children:"Get started with common tasks"})]}),e.jsx("div",{className:"space-y-3",children:X.map(s=>e.jsxs(o,{to:s.href,className:"flex items-center p-3 rounded-lg border border-gray-200 hover:border-gray-300 hover:shadow-sm transition-all duration-200",children:[e.jsx("div",{className:`flex-shrink-0 p-2 rounded-lg ${s.color}`,children:e.jsx(s.icon,{className:"h-5 w-5 text-white"})}),e.jsxs("div",{className:"ml-3 flex-1",children:[e.jsx("p",{className:"text-sm font-medium text-gray-900",children:s.name}),e.jsx("p",{className:"text-xs text-gray-500",children:s.description})]}),e.jsx(ge,{className:"h-4 w-4 text-gray-400"})]},s.name))})]})}),e.jsxs("div",{className:"lg:col-span-2 space-y-8",children:[e.jsxs("div",{className:"card",children:[e.jsxs("div",{className:"card-header",children:[e.jsx("h3",{className:"text-lg font-medium text-gray-900",children:"Recent Activity"}),e.jsx(o,{to:"/history",className:"text-sm text-primary-600 hover:text-primary-500",children:"View all"})]}),e.jsx("div",{className:"space-y-4",children:K.map(s=>e.jsxs("div",{className:"flex items-start space-x-3",children:[e.jsx("div",{className:`flex-shrink-0 p-1 rounded-full ${s.status==="completed"?"bg-green-100":"bg-blue-100"}`,children:e.jsx("div",{className:`h-2 w-2 rounded-full ${s.status==="completed"?"bg-green-600":"bg-blue-600"}`})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("p",{className:"text-sm text-gray-900",children:s.title}),s.property&&e.jsx("p",{className:"text-xs text-gray-500",children:s.property}),e.jsx("p",{className:"text-xs text-gray-400",children:s.dateText})]})]},s.id))})]}),e.jsxs("div",{className:"card",children:[e.jsxs("div",{className:"card-header",children:[e.jsx("h3",{className:"text-lg font-medium text-gray-900",children:"Upcoming Tasks"}),e.jsx(o,{to:"/applications",className:"text-sm text-primary-600 hover:text-primary-500",children:"View all"})]}),e.jsx("div",{className:"space-y-4",children:ee.map(s=>e.jsx("div",{className:"border border-gray-200 rounded-lg p-4",children:e.jsxs("div",{className:"flex items-start justify-between",children:[e.jsxs("div",{className:"flex-1",children:[e.jsx("h4",{className:"text-sm font-medium text-gray-900",children:s.title}),e.jsx("p",{className:"text-xs text-gray-500 mt-1",children:s.property}),e.jsx("div",{className:"flex items-center mt-2 space-x-4",children:e.jsx("span",{className:"text-xs text-gray-500",children:s.date})})]}),e.jsx("span",{className:`inline-flex items-center px-2 py-1 rounded-full text-xs font-medium ${s.priority==="high"?"bg-red-100 text-red-800":s.priority==="medium"?"bg-yellow-100 text-yellow-800":"bg-green-100 text-green-800"}`,children:s.priority})]})},s.id))})]})]})]}),e.jsx("div",{className:"mt-8",children:e.jsxs("div",{className:"card",children:[e.jsxs("div",{className:"flex items-center justify-between mb-4",children:[e.jsx("h3",{className:"text-lg font-medium text-gray-900",children:"Today's Weather"}),e.jsx(o,{to:"/weather",className:"text-sm text-primary-600 hover:text-primary-500",children:"Detailed forecast"})]}),!N&&e.jsx("div",{className:"text-sm text-gray-600",children:"Add a property with coordinates to see local weather."}),N&&!n&&e.jsx("div",{className:"text-sm text-gray-600",children:"Weather unavailable. Configure WEATHER_API_KEY to enable."}),n&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-3 gap-6",children:[e.jsxs("div",{className:"flex items-center space-x-3",children:[(w=n.current)!=null&&w.icon?e.jsx("img",{alt:"icon",className:"h-10 w-10",src:`/api/weather/icon/${n.current.icon}?size=2x`}):e.jsx(ue,{className:"h-8 w-8 text-blue-500"}),e.jsxs("div",{children:[e.jsxs("p",{className:"text-2xl font-semibold text-gray-900",children:[Math.round((v=n.current)==null?void 0:v.temperature),"°F"]}),e.jsx("p",{className:"text-sm text-gray-500 capitalize",children:(b=n.current)==null?void 0:b.conditions})]})]}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("span",{className:"text-sm text-gray-500",children:"Wind:"}),e.jsxs("span",{className:"text-sm font-medium text-gray-900",children:[Math.round(((A=n.current)==null?void 0:A.windSpeed)||0)," mph"]})]}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("span",{className:"text-sm text-gray-500",children:"Humidity:"}),e.jsxs("span",{className:"text-sm font-medium text-gray-900",children:[Math.round((($=n.current)==null?void 0:$.humidity)||0),"%"]})]})]}),e.jsx("div",{className:"mt-4 p-3 bg-green-50 rounded-lg",children:e.jsx("p",{className:"text-sm text-green-800",children:`Location: ${(R=n.location)==null?void 0:R.propertyName}`})})]})]})})]})};export{ve as default};