import { useState, useEffect } from 'react'; import { Plus, MoveRight, Sprout, Leaf, Flower, Archive, Scale, ClipboardList, Bug, Search, RefreshCw } from 'lucide-react'; import { Batch, batchesApi } from '../lib/batchesApi'; import { useToast } from '../context/ToastContext'; import BatchTransitionModal from '../components/BatchTransitionModal'; import WeightLogModal from '../components/WeightLogModal'; import CreateTaskModal from '../components/tasks/CreateTaskModal'; import IPMScheduleModal from '../components/IPMScheduleModal'; import ScoutingModal from '../components/ipm/ScoutingModal'; import { SkeletonCard } from '../components/ui/Skeleton'; import { PullToRefresh } from '../components/ui/PullToRefresh'; import { QuickLogBar } from '../components/touchpoints/QuickLogButtons'; const STAGE_GROUPS = [ { id: 'CLONE_IN', label: 'Clones', icon: Sprout, color: 'text-blue-500 bg-blue-50 border-blue-100' }, { id: 'VEGETATIVE', label: 'Veg', icon: Leaf, color: 'text-emerald-500 bg-emerald-50 border-emerald-100' }, { id: 'FLOWERING', label: 'Flower', icon: Flower, color: 'text-purple-500 bg-purple-50 border-purple-100' }, { id: 'DRYING', label: 'Drying', icon: Archive, color: 'text-amber-500 bg-amber-50 border-amber-100' }, { id: 'CURING', label: 'Curing', icon: Archive, color: 'text-orange-500 bg-orange-50 border-orange-100' }, { id: 'FINISHED', label: 'Finished', icon: Archive, color: 'text-slate-500 bg-slate-50 border-slate-100' }, ]; export default function BatchesPage() { const { addToast } = useToast(); const [batches, setBatches] = useState([]); const [loading, setLoading] = useState(true); const [selectedBatch, setSelectedBatch] = useState(null); const [weightLogBatch, setWeightLogBatch] = useState(null); const [createTaskBatch, setCreateTaskBatch] = useState(null); const [ipmBatch, setIpmBatch] = useState(null); const [scoutingBatch, setScoutingBatch] = useState(null); useEffect(() => { fetchBatches(); }, []); const fetchBatches = async (showToast = false) => { setLoading(true); try { const data = await batchesApi.getAll(); setBatches(data); if (showToast) addToast('Batches refreshed', 'info'); } catch (e) { console.error(e); addToast('Failed to load batches', 'error'); } finally { setLoading(false); } }; // Group batches by stage const groupedBatches = STAGE_GROUPS.map(group => ({ ...group, items: batches.filter(b => b.stage === group.id) })).filter(group => group.items.length > 0); const handlePullRefresh = async () => { await fetchBatches(true); }; return (

Batches

{loading ? 'Loading...' : `${batches.length} active batches`}

{loading ? (
{Array.from({ length: 6 }).map((_, i) => )}
) : groupedBatches.length === 0 ? (

No active batches

Get started by creating your first batch.

) : ( groupedBatches.map(group => (

{group.label}

{group.items.length}
{group.items.map(batch => (

{batch.name}

{batch.strain}
{/* Show Scale button for Harvest+ stages */} {['HARVEST', 'DRYING', 'CURING', 'FINISHED'].includes(batch.stage) && ( )}
Room {batch.room?.name || 'Unassigned'}
Plants {batch.plantCount}
{/* Quick Log Bar */}
fetchBatches()} compact />
))}
)) )}
{selectedBatch && ( setSelectedBatch(null)} onSuccess={() => { fetchBatches(); setSelectedBatch(null); }} /> )} {weightLogBatch && ( setWeightLogBatch(null)} onSuccess={() => { fetchBatches(); setWeightLogBatch(null); }} /> )} {createTaskBatch && ( setCreateTaskBatch(null)} onSuccess={() => { // Optional: show toast setCreateTaskBatch(null); }} /> )} {ipmBatch && ( setIpmBatch(null)} /> )} {scoutingBatch && ( setScoutingBatch(null)} onSuccess={() => { // Optional: show toast }} /> )}
); }