name: comercialrs-kanban-auto-refresh
description: Fix Kanban board not auto-refreshing when new tasks are created via Supabase realtime in ComercialRS
category: devops
ComercialRS — Kanban Auto-Refresh Bug
Problem
Kanban board (Tasks.tsx / KanbanBoard.tsx) doesn't update when new tasks are created via WhatsApp/Uazapi webhook. User must press F5 to see new meetings.
Root Cause
KanbanBoard maintains internal state: useState(externalTasks). A useEffect syncs when externalTasks changes:
`typescript
useEffect(() => {
setTasks(externalTasks);
}, [externalTasks]);
`
The problem: when AppDataContext receives a realtime INSERT from Supabase, it calls setAllTasks(prev => [...prev, newTask]). React may reuse the same array reference if the context state was already stable, so the useEffect never fires.
Fix
Track task IDs to force re-sync when content changes (not just reference):
`typescript
const [lastTaskIds, setLastTaskIds] = useState(() => externalTasks.map(t => t.id).join(','));
useEffect(() => {
const newIds = externalTasks.map(t => t.id).join(',');
if (newIds !== lastTaskIds) {
setLastTaskIds(newIds);
setTasks(externalTasks);
}
}, [externalTasks, lastTaskIds]);
`
Files Modified
- -
/src/components/tasks/KanbanBoard.tsx - - Remove
useAuthimport if it was only for role check - - Remove
session,userId,userRoledeclarations that depended on it - - Build breaks (unused variable error) if you remove the hook call but keep the destructured vars
Deploy Steps
1. cd /tmp/comercialrs/comercialrs-main
2. npm install (if needed)
3. npm run build
4. sshpass -p 'Marcia19671951@' rsync -av --delete dist/ root@31.97.243.106:/var/www/comercialrs/dist/
5. Also sync root files: sshpass -p 'Marcia19671951@' rsync -av dist/index.html dist/favicon.ico dist/robots.txt root@31.97.243.106:/var/www/comercialrs/
Cronograma (Gantt) filter — all users see ALL meetings
The ganttTasks useMemo should return allActiveTasks without any createdBy filter for all roles:
`tsx
// src/pages/Gantt.tsx
const ganttTasks = useMemo(() => allActiveTasks, [allActiveTasks]);
`
When removing per-role logic, also remove the unused imports/variables from Gantt.tsx:
Kanban Auto-Refresh Bug
Kanban board (Tasks.tsx / KanbanBoard.tsx) doesn't update when new tasks are created via WhatsApp webhook. User must press F5.
Root Cause
Supabase realtime updates arrive via AppDataContext subscription. The KanbanBoard's local state copy needs explicit ID-based comparison to catch additions from realtime INSERT events that may not change the array reference.