upto phase 4 completed
This commit is contained in:
@@ -7,7 +7,10 @@
|
||||
* This provides consistent data for the WorkflowCompletionWidget
|
||||
* across all pages.
|
||||
*
|
||||
* IMPORTANT: Content table structure
|
||||
* IMPORTANT: Widget displays site-wide stats only (no sector filtering)
|
||||
* to ensure consistent counts across all pages.
|
||||
*
|
||||
* Content table structure:
|
||||
* - Tasks is separate table
|
||||
* - Content table has status field: 'draft', 'review', 'approved', 'published'
|
||||
* - Images is separate table linked to content
|
||||
@@ -31,7 +34,6 @@ import {
|
||||
fetchAPI,
|
||||
} from '../services/api';
|
||||
import { useSiteStore } from '../store/siteStore';
|
||||
import { useSectorStore } from '../store/sectorStore';
|
||||
|
||||
// Time filter options (in days)
|
||||
export type TimeFilter = 'today' | '7' | '30' | '90' | 'all';
|
||||
@@ -135,7 +137,7 @@ function getDateFilter(timeFilter: TimeFilter): string | undefined {
|
||||
export function useWorkflowStats(timeFilter: TimeFilter = 'all') {
|
||||
const [stats, setStats] = useState<WorkflowStats>(defaultStats);
|
||||
const { activeSite } = useSiteStore();
|
||||
const { activeSector } = useSectorStore();
|
||||
// Note: No sector filtering - widget shows site-wide stats for consistency
|
||||
|
||||
const loadStats = useCallback(async () => {
|
||||
// Don't load if no active site - wait for site to be set
|
||||
@@ -151,16 +153,15 @@ export function useWorkflowStats(timeFilter: TimeFilter = 'all') {
|
||||
const dateFilter = getDateFilter(timeFilter);
|
||||
const dateParam = dateFilter ? `&created_at__gte=${dateFilter.split('T')[0]}` : '';
|
||||
|
||||
// Build site/sector params for direct API calls
|
||||
// IMPORTANT: Widget should always show site-wide stats for consistency
|
||||
// Sector filtering removed to ensure widget shows same counts on all pages
|
||||
const siteParam = `&site_id=${activeSite.id}`;
|
||||
const sectorParam = activeSector?.id ? `§or_id=${activeSector.id}` : '';
|
||||
const baseParams = `${siteParam}${sectorParam}`;
|
||||
const baseParams = siteParam; // No sector filter for consistent widget display
|
||||
|
||||
// Build common filters for fetch* functions
|
||||
// Build common filters for fetch* functions (also no sector filter)
|
||||
const baseFilters = {
|
||||
page_size: 1,
|
||||
site_id: activeSite.id,
|
||||
...(activeSector?.id && { sector_id: activeSector.id }),
|
||||
};
|
||||
|
||||
// Fetch all stats in parallel for performance
|
||||
@@ -217,9 +218,10 @@ export function useWorkflowStats(timeFilter: TimeFilter = 'all') {
|
||||
? fetchAPI(`/v1/writer/images/?page_size=1${baseParams}${dateParam}`)
|
||||
: fetchImages({ ...baseFilters }),
|
||||
// Credits usage from billing summary endpoint - includes by_operation breakdown
|
||||
// Site-wide credits (no sector filter) - baseParams already has no sector
|
||||
dateFilter
|
||||
? fetchAPI(`/v1/billing/credits/usage/summary/?start_date=${dateFilter}`)
|
||||
: fetchAPI('/v1/billing/credits/usage/summary/').catch(() => ({
|
||||
? fetchAPI(`/v1/billing/credits/usage/summary/?start_date=${dateFilter}${baseParams}`)
|
||||
: fetchAPI(`/v1/billing/credits/usage/summary/?${baseParams.substring(1)}`).catch(() => ({
|
||||
data: { total_credits_used: 0, by_operation: {} }
|
||||
})),
|
||||
]);
|
||||
@@ -276,7 +278,7 @@ export function useWorkflowStats(timeFilter: TimeFilter = 'all') {
|
||||
error: error.message || 'Failed to load workflow stats',
|
||||
}));
|
||||
}
|
||||
}, [activeSite?.id, activeSector?.id, timeFilter]);
|
||||
}, [activeSite?.id, timeFilter]); // Removed activeSector - widget shows site-wide stats only
|
||||
|
||||
// Load stats on mount and when dependencies change
|
||||
useEffect(() => {
|
||||
|
||||
Reference in New Issue
Block a user