fix(frontend): Fix critical type safety issues from code review
Address all Critical and High Priority issues identified in frontend code review report: Critical Issues Fixed: - Created unified logger utility (lib/utils/logger.ts) to replace all console.log statements - Consolidated User type definitions - removed duplicate from authStore, using single source from types/user.ts - Eliminated 'any' types in API client - added proper generic types with AxiosRequestConfig - Fixed SignalR ConnectionManager - replaced 'any' with generic types <T> - Created API error types (lib/types/errors.ts) with ApiError and getErrorMessage helper - Fixed IssueCard component - removed all type assertions, created discriminated union types for Kanban items - Added React.memo to IssueCard for performance optimization - Added proper ARIA labels and accessibility attributes to IssueCard High Priority Issues Fixed: - Fixed hardcoded user ID in CreateProjectDialog - now uses actual user from authStore - Added useCallback to CreateProjectDialog onSubmit handler - Fixed error handlers in use-epics.ts - replaced 'any' with ApiError type - Updated all error handling to use logger and getErrorMessage Type Safety Improvements: - Created KanbanItem discriminated union (KanbanEpic | KanbanStory | KanbanTask) with proper type guards - Added 'never' types to prevent invalid property access - Fixed User interface to include all required fields (createdAt, updatedAt) - Maintained backward compatibility with LegacyKanbanBoard for existing code Files Changed: - lib/utils/logger.ts - New centralized logging utility - lib/types/errors.ts - New API error types and helpers - types/user.ts - Consolidated User type with TenantRole - types/kanban.ts - New discriminated union types for type-safe Kanban items - components/features/kanban/IssueCard.tsx - Type-safe with React.memo - components/features/projects/CreateProjectDialog.tsx - Fixed hardcoded user ID, added useCallback - lib/api/client.ts - Eliminated 'any', added proper generics - lib/signalr/ConnectionManager.ts - Replaced console.log, added generics - lib/hooks/use-epics.ts - Fixed error handler types - stores/authStore.ts - Removed duplicate User type - lib/hooks/useAuth.ts - Added createdAt field to User TypeScript compilation: ✅ All type checks passing (0 errors) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -2,19 +2,21 @@ import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query';
|
||||
import { epicsApi } from '@/lib/api/pm';
|
||||
import type { Epic, CreateEpicDto, UpdateEpicDto, WorkItemStatus } from '@/types/project';
|
||||
import { toast } from 'sonner';
|
||||
import { logger } from '@/lib/utils/logger';
|
||||
import { ApiError, getErrorMessage } from '@/lib/types/errors';
|
||||
|
||||
// ==================== Query Hooks ====================
|
||||
export function useEpics(projectId?: string) {
|
||||
return useQuery<Epic[]>({
|
||||
queryKey: ['epics', projectId],
|
||||
queryFn: async () => {
|
||||
console.log('[useEpics] Fetching epics...', { projectId });
|
||||
logger.debug('[useEpics] Fetching epics', { projectId });
|
||||
try {
|
||||
const result = await epicsApi.list(projectId);
|
||||
console.log('[useEpics] Fetch successful:', result);
|
||||
logger.debug('[useEpics] Fetch successful', result);
|
||||
return result;
|
||||
} catch (error) {
|
||||
console.error('[useEpics] Fetch failed:', error);
|
||||
logger.error('[useEpics] Fetch failed', error);
|
||||
throw error;
|
||||
}
|
||||
},
|
||||
@@ -46,9 +48,9 @@ export function useCreateEpic() {
|
||||
|
||||
toast.success('Epic created successfully!');
|
||||
},
|
||||
onError: (error: any) => {
|
||||
console.error('[useCreateEpic] Error:', error);
|
||||
toast.error(error.response?.data?.detail || 'Failed to create epic');
|
||||
onError: (error: ApiError) => {
|
||||
logger.error('[useCreateEpic] Error', error);
|
||||
toast.error(getErrorMessage(error));
|
||||
},
|
||||
});
|
||||
}
|
||||
@@ -74,15 +76,15 @@ export function useUpdateEpic() {
|
||||
|
||||
return { previousEpic };
|
||||
},
|
||||
onError: (error: any, variables, context) => {
|
||||
console.error('[useUpdateEpic] Error:', error);
|
||||
onError: (error: ApiError, variables, context) => {
|
||||
logger.error('[useUpdateEpic] Error', error);
|
||||
|
||||
// Rollback
|
||||
if (context?.previousEpic) {
|
||||
queryClient.setQueryData(['epics', variables.id], context.previousEpic);
|
||||
}
|
||||
|
||||
toast.error(error.response?.data?.detail || 'Failed to update epic');
|
||||
toast.error(getErrorMessage(error));
|
||||
},
|
||||
onSuccess: (updatedEpic) => {
|
||||
toast.success('Epic updated successfully!');
|
||||
@@ -104,9 +106,9 @@ export function useDeleteEpic() {
|
||||
queryClient.removeQueries({ queryKey: ['epics', id] });
|
||||
toast.success('Epic deleted successfully!');
|
||||
},
|
||||
onError: (error: any) => {
|
||||
console.error('[useDeleteEpic] Error:', error);
|
||||
toast.error(error.response?.data?.detail || 'Failed to delete epic');
|
||||
onError: (error: ApiError) => {
|
||||
logger.error('[useDeleteEpic] Error', error);
|
||||
toast.error(getErrorMessage(error));
|
||||
},
|
||||
});
|
||||
}
|
||||
@@ -129,14 +131,14 @@ export function useChangeEpicStatus() {
|
||||
|
||||
return { previousEpic };
|
||||
},
|
||||
onError: (error: any, variables, context) => {
|
||||
console.error('[useChangeEpicStatus] Error:', error);
|
||||
onError: (error: ApiError, variables, context) => {
|
||||
logger.error('[useChangeEpicStatus] Error', error);
|
||||
|
||||
if (context?.previousEpic) {
|
||||
queryClient.setQueryData(['epics', variables.id], context.previousEpic);
|
||||
}
|
||||
|
||||
toast.error(error.response?.data?.detail || 'Failed to change epic status');
|
||||
toast.error(getErrorMessage(error));
|
||||
},
|
||||
onSuccess: () => {
|
||||
toast.success('Epic status changed successfully!');
|
||||
@@ -159,9 +161,9 @@ export function useAssignEpic() {
|
||||
queryClient.invalidateQueries({ queryKey: ['epics'] });
|
||||
toast.success('Epic assigned successfully!');
|
||||
},
|
||||
onError: (error: any) => {
|
||||
console.error('[useAssignEpic] Error:', error);
|
||||
toast.error(error.response?.data?.detail || 'Failed to assign epic');
|
||||
onError: (error: ApiError) => {
|
||||
logger.error('[useAssignEpic] Error', error);
|
||||
toast.error(getErrorMessage(error));
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query';
|
||||
import { projectsApi } from '@/lib/api/projects';
|
||||
import type { KanbanBoard } from '@/types/kanban';
|
||||
import type { LegacyKanbanBoard } from '@/types/kanban';
|
||||
import { api } from '@/lib/api/client';
|
||||
|
||||
export function useKanbanBoard(projectId: string) {
|
||||
return useQuery<KanbanBoard>({
|
||||
return useQuery<LegacyKanbanBoard>({
|
||||
queryKey: ['projects', projectId, 'kanban'],
|
||||
queryFn: () => projectsApi.getKanban(projectId),
|
||||
enabled: !!projectId,
|
||||
|
||||
@@ -38,6 +38,8 @@ export function useLogin() {
|
||||
tenantName: data.user.tenantName,
|
||||
role: data.user.role,
|
||||
isEmailVerified: data.user.isEmailVerified,
|
||||
createdAt: data.user.createdAt || new Date().toISOString(),
|
||||
updatedAt: data.user.updatedAt,
|
||||
});
|
||||
|
||||
router.push('/dashboard');
|
||||
|
||||
Reference in New Issue
Block a user