This commit is contained in:
Jake Kasper
2025-09-03 10:19:42 -04:00
parent 30875cb125
commit 1c6ab9e569

View File

@@ -13,12 +13,18 @@ const Mowing = () => {
const [showPlanModal, setShowPlanModal] = useState(false); const [showPlanModal, setShowPlanModal] = useState(false);
const [execPlan, setExecPlan] = useState(null); const [execPlan, setExecPlan] = useState(null);
const [viewSession, setViewSession] = useState(null); const [viewSession, setViewSession] = useState(null);
const [sessions, setSessions] = useState([]);
const fetchPlans = async () => { const fetchPlans = async () => {
try { try {
setLoading(true); setLoading(true);
const r = await mowingAPI.getPlans(); const r = await mowingAPI.getPlans();
setPlans(r.data.data.plans || []); setPlans(r.data.data.plans || []);
// load recent sessions (not rendered as a list; used for View button)
try {
const s = await mowingAPI.getLogs();
setSessions(s.data?.data?.logs || []);
} catch {}
} catch (e) { } catch (e) {
toast.error('Failed to load mowing plans'); toast.error('Failed to load mowing plans');
} finally { } finally {
@@ -74,6 +80,18 @@ const Mowing = () => {
<p className="text-sm font-medium text-gray-900">{p.planned_date ? new Date(p.planned_date).toLocaleDateString() : 'No date'}</p> <p className="text-sm font-medium text-gray-900">{p.planned_date ? new Date(p.planned_date).toLocaleDateString() : 'No date'}</p>
<p className="text-xs text-gray-500">Last updated {new Date(p.updated_at || p.created_at).toLocaleDateString()}</p> <p className="text-xs text-gray-500">Last updated {new Date(p.updated_at || p.created_at).toLocaleDateString()}</p>
<div className="flex gap-2 mt-2 justify-end"> <div className="flex gap-2 mt-2 justify-end">
<button
className="p-1 text-indigo-600 hover:text-indigo-800 hover:bg-indigo-50 rounded"
title="View recent session"
onClick={() => {
const list = (sessions || []).filter(s => s.property_id === p.property_id);
if (!list.length) { toast.error('No sessions yet for this property'); return; }
const last = [...list].sort((a,b)=> new Date((b.created_at || b.session_date || 0)) - new Date((a.created_at || a.session_date || 0)))[0];
setViewSession(last);
}}
>
<EyeIcon className="h-4 w-4" />
</button>
{p.status === 'planned' && ( {p.status === 'planned' && (
<button className="p-1 text-green-600 hover:text-green-800 hover:bg-green-50 rounded" title="Execute" onClick={()=> setExecPlan(p)}> <button className="p-1 text-green-600 hover:text-green-800 hover:bg-green-50 rounded" title="Execute" onClick={()=> setExecPlan(p)}>
<PlayIcon className="h-4 w-4" /> <PlayIcon className="h-4 w-4" />