refactor(frontend): Replace console.log with logger utility - Sprint 3 Story 1
Replace all console.log/warn/error statements with unified logger utility. Changes: - Replaced console in lib/hooks/use-stories.ts - Replaced console in lib/signalr/SignalRContext.tsx - Replaced console in lib/hooks/useProjectHub.ts - Replaced console in lib/hooks/use-tasks.ts - Replaced console in lib/hooks/useNotificationHub.ts - Replaced console in lib/hooks/use-projects.ts - Replaced console in app/(dashboard)/projects/[id]/kanban/page.tsx Logger respects NODE_ENV (debug disabled in production). 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -3,19 +3,20 @@ import { storiesApi } from '@/lib/api/pm';
|
||||
import { epicsApi } from '@/lib/api/pm';
|
||||
import type { Story, CreateStoryDto, UpdateStoryDto, WorkItemStatus } from '@/types/project';
|
||||
import { toast } from 'sonner';
|
||||
import { logger } from '@/lib/utils/logger';
|
||||
|
||||
// ==================== Query Hooks ====================
|
||||
export function useStories(epicId?: string) {
|
||||
return useQuery<Story[]>({
|
||||
queryKey: ['stories', epicId],
|
||||
queryFn: async () => {
|
||||
console.log('[useStories] Fetching stories...', { epicId });
|
||||
logger.debug('[useStories] Fetching stories...', { epicId });
|
||||
try {
|
||||
const result = await storiesApi.list(epicId);
|
||||
console.log('[useStories] Fetch successful:', result);
|
||||
logger.debug('[useStories] Fetch successful:', result);
|
||||
return result;
|
||||
} catch (error) {
|
||||
console.error('[useStories] Fetch failed:', error);
|
||||
logger.error('[useStories] Fetch failed:', error);
|
||||
throw error;
|
||||
}
|
||||
},
|
||||
@@ -33,12 +34,12 @@ export function useProjectStories(projectId?: string) {
|
||||
throw new Error('projectId is required');
|
||||
}
|
||||
|
||||
console.log('[useProjectStories] Fetching all stories for project...', { projectId });
|
||||
logger.debug('[useProjectStories] Fetching all stories for project...', { projectId });
|
||||
|
||||
try {
|
||||
// First fetch all epics for the project
|
||||
const epics = await epicsApi.list(projectId);
|
||||
console.log('[useProjectStories] Epics fetched:', epics.length);
|
||||
logger.debug('[useProjectStories] Epics fetched:', epics.length);
|
||||
|
||||
// Then fetch stories for each epic
|
||||
const storiesPromises = epics.map((epic) => storiesApi.list(epic.id));
|
||||
@@ -46,11 +47,11 @@ export function useProjectStories(projectId?: string) {
|
||||
|
||||
// Flatten the array of arrays into a single array
|
||||
const allStories = storiesArrays.flat();
|
||||
console.log('[useProjectStories] Total stories fetched:', allStories.length);
|
||||
logger.debug('[useProjectStories] Total stories fetched:', allStories.length);
|
||||
|
||||
return allStories;
|
||||
} catch (error) {
|
||||
console.error('[useProjectStories] Fetch failed:', error);
|
||||
logger.error('[useProjectStories] Fetch failed:', error);
|
||||
throw error;
|
||||
}
|
||||
},
|
||||
@@ -84,7 +85,7 @@ export function useCreateStory() {
|
||||
toast.success('Story created successfully!');
|
||||
},
|
||||
onError: (error: any) => {
|
||||
console.error('[useCreateStory] Error:', error);
|
||||
logger.error('[useCreateStory] Error:', error);
|
||||
toast.error(error.response?.data?.detail || 'Failed to create story');
|
||||
},
|
||||
});
|
||||
@@ -109,7 +110,7 @@ export function useUpdateStory() {
|
||||
return { previousStory };
|
||||
},
|
||||
onError: (error: any, variables, context) => {
|
||||
console.error('[useUpdateStory] Error:', error);
|
||||
logger.error('[useUpdateStory] Error:', error);
|
||||
|
||||
if (context?.previousStory) {
|
||||
queryClient.setQueryData(['stories', variables.id], context.previousStory);
|
||||
@@ -138,7 +139,7 @@ export function useDeleteStory() {
|
||||
toast.success('Story deleted successfully!');
|
||||
},
|
||||
onError: (error: any) => {
|
||||
console.error('[useDeleteStory] Error:', error);
|
||||
logger.error('[useDeleteStory] Error:', error);
|
||||
toast.error(error.response?.data?.detail || 'Failed to delete story');
|
||||
},
|
||||
});
|
||||
@@ -163,7 +164,7 @@ export function useChangeStoryStatus() {
|
||||
return { previousStory };
|
||||
},
|
||||
onError: (error: any, variables, context) => {
|
||||
console.error('[useChangeStoryStatus] Error:', error);
|
||||
logger.error('[useChangeStoryStatus] Error:', error);
|
||||
|
||||
if (context?.previousStory) {
|
||||
queryClient.setQueryData(['stories', variables.id], context.previousStory);
|
||||
@@ -193,7 +194,7 @@ export function useAssignStory() {
|
||||
toast.success('Story assigned successfully!');
|
||||
},
|
||||
onError: (error: any) => {
|
||||
console.error('[useAssignStory] Error:', error);
|
||||
logger.error('[useAssignStory] Error:', error);
|
||||
toast.error(error.response?.data?.detail || 'Failed to assign story');
|
||||
},
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user