FIX: Drill-down de categorias agora recarrega corretamente
- Adicionado selectedCategory nas dependências do useCallback - Criado useEffect separado para recarregar quando categoria muda - Removido loadData() dos handlers (agora feito pelo useEffect) Isso resolve o problema de estado assíncrono onde setSelectedCategory não atualizava antes de loadData() ser chamado.
This commit is contained in:
parent
bdfcc8f60b
commit
db87da95c1
@ -127,12 +127,19 @@ const Reports = () => {
|
|||||||
} finally {
|
} finally {
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
}
|
}
|
||||||
}, [activeTab, year, months]);
|
}, [activeTab, year, months, selectedCategory]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
loadData();
|
loadData();
|
||||||
}, [loadData]);
|
}, [loadData]);
|
||||||
|
|
||||||
|
// Recarrega dados quando categoria selecionada muda
|
||||||
|
useEffect(() => {
|
||||||
|
if (activeTab === 'category') {
|
||||||
|
loadData();
|
||||||
|
}
|
||||||
|
}, [selectedCategory]);
|
||||||
|
|
||||||
const tabs = [
|
const tabs = [
|
||||||
{ id: 'summary', label: t('reports.summary'), icon: 'bi-clipboard-data' },
|
{ id: 'summary', label: t('reports.summary'), icon: 'bi-clipboard-data' },
|
||||||
{ id: 'category', label: t('reports.byCategory'), icon: 'bi-pie-chart' },
|
{ id: 'category', label: t('reports.byCategory'), icon: 'bi-pie-chart' },
|
||||||
@ -447,12 +454,10 @@ const Reports = () => {
|
|||||||
|
|
||||||
const handleCategoryClick = (cat) => {
|
const handleCategoryClick = (cat) => {
|
||||||
setSelectedCategory(cat);
|
setSelectedCategory(cat);
|
||||||
loadData();
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleBackToCategories = () => {
|
const handleBackToCategories = () => {
|
||||||
setSelectedCategory(null);
|
setSelectedCategory(null);
|
||||||
loadData();
|
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user