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>
182 lines
5.4 KiB
TypeScript
182 lines
5.4 KiB
TypeScript
'use client';
|
|
|
|
import { useCallback } from 'react';
|
|
import { useForm } from 'react-hook-form';
|
|
import { zodResolver } from '@hookform/resolvers/zod';
|
|
import * as z from 'zod';
|
|
import {
|
|
Dialog,
|
|
DialogContent,
|
|
DialogDescription,
|
|
DialogFooter,
|
|
DialogHeader,
|
|
DialogTitle,
|
|
} from '@/components/ui/dialog';
|
|
import {
|
|
Form,
|
|
FormControl,
|
|
FormDescription,
|
|
FormField,
|
|
FormItem,
|
|
FormLabel,
|
|
FormMessage,
|
|
} from '@/components/ui/form';
|
|
import { Input } from '@/components/ui/input';
|
|
import { Button } from '@/components/ui/button';
|
|
import { useCreateProject } from '@/lib/hooks/use-projects';
|
|
import { useAuthStore } from '@/stores/authStore';
|
|
import { toast } from 'sonner';
|
|
import { logger } from '@/lib/utils/logger';
|
|
import type { CreateProjectDto } from '@/types/project';
|
|
|
|
const projectSchema = z.object({
|
|
name: z.string().min(1, 'Project name is required').max(200, 'Project name cannot exceed 200 characters'),
|
|
description: z.string().max(2000, 'Description cannot exceed 2000 characters').optional(),
|
|
key: z
|
|
.string()
|
|
.min(2, 'Project key must be at least 2 characters')
|
|
.max(10, 'Project key cannot exceed 10 characters')
|
|
.regex(/^[A-Z]+$/, 'Project key must contain only uppercase letters'),
|
|
});
|
|
|
|
interface CreateProjectDialogProps {
|
|
open: boolean;
|
|
onOpenChange: (open: boolean) => void;
|
|
}
|
|
|
|
export function CreateProjectDialog({
|
|
open,
|
|
onOpenChange,
|
|
}: CreateProjectDialogProps) {
|
|
const createProject = useCreateProject();
|
|
const user = useAuthStore((state) => state.user);
|
|
|
|
const form = useForm<CreateProjectDto>({
|
|
resolver: zodResolver(projectSchema),
|
|
defaultValues: {
|
|
name: '',
|
|
description: '',
|
|
key: '',
|
|
},
|
|
});
|
|
|
|
const onSubmit = useCallback(
|
|
async (data: CreateProjectDto) => {
|
|
// Validate user is logged in
|
|
if (!user) {
|
|
toast.error('You must be logged in to create a project');
|
|
logger.error('Attempted to create project without authentication');
|
|
return;
|
|
}
|
|
|
|
try {
|
|
const projectData = {
|
|
...data,
|
|
ownerId: user.id,
|
|
};
|
|
|
|
logger.debug('Creating project', projectData);
|
|
await createProject.mutateAsync(projectData);
|
|
|
|
form.reset();
|
|
onOpenChange(false);
|
|
toast.success('Project created successfully');
|
|
} catch (error) {
|
|
logger.error('Failed to create project', error);
|
|
toast.error('Failed to create project. Please try again.');
|
|
}
|
|
},
|
|
[createProject, form, onOpenChange, user]
|
|
);
|
|
|
|
return (
|
|
<Dialog open={open} onOpenChange={onOpenChange}>
|
|
<DialogContent className="sm:max-w-[525px]">
|
|
<DialogHeader>
|
|
<DialogTitle>Create New Project</DialogTitle>
|
|
<DialogDescription>
|
|
Add a new project to organize your work. Click create when you're done.
|
|
</DialogDescription>
|
|
</DialogHeader>
|
|
|
|
<Form {...form}>
|
|
<form onSubmit={form.handleSubmit(onSubmit)} className="space-y-4">
|
|
<FormField
|
|
control={form.control}
|
|
name="name"
|
|
render={({ field }) => (
|
|
<FormItem>
|
|
<FormLabel>Project Name</FormLabel>
|
|
<FormControl>
|
|
<Input placeholder="My Awesome Project" {...field} />
|
|
</FormControl>
|
|
<FormDescription>
|
|
The name of your project.
|
|
</FormDescription>
|
|
<FormMessage />
|
|
</FormItem>
|
|
)}
|
|
/>
|
|
|
|
<FormField
|
|
control={form.control}
|
|
name="key"
|
|
render={({ field }) => (
|
|
<FormItem>
|
|
<FormLabel>Project Key</FormLabel>
|
|
<FormControl>
|
|
<Input
|
|
placeholder="MAP"
|
|
{...field}
|
|
onChange={(e) => {
|
|
field.onChange(e.target.value.toUpperCase());
|
|
}}
|
|
/>
|
|
</FormControl>
|
|
<FormDescription>
|
|
A unique identifier for the project (2-10 uppercase letters).
|
|
</FormDescription>
|
|
<FormMessage />
|
|
</FormItem>
|
|
)}
|
|
/>
|
|
|
|
<FormField
|
|
control={form.control}
|
|
name="description"
|
|
render={({ field }) => (
|
|
<FormItem>
|
|
<FormLabel>Description</FormLabel>
|
|
<FormControl>
|
|
<Input
|
|
placeholder="A brief description of the project..."
|
|
{...field}
|
|
/>
|
|
</FormControl>
|
|
<FormDescription>
|
|
Optional description for your project.
|
|
</FormDescription>
|
|
<FormMessage />
|
|
</FormItem>
|
|
)}
|
|
/>
|
|
|
|
<DialogFooter>
|
|
<Button
|
|
type="button"
|
|
variant="outline"
|
|
onClick={() => onOpenChange(false)}
|
|
>
|
|
Cancel
|
|
</Button>
|
|
<Button type="submit" disabled={createProject.isPending}>
|
|
{createProject.isPending ? 'Creating...' : 'Create Project'}
|
|
</Button>
|
|
</DialogFooter>
|
|
</form>
|
|
</Form>
|
|
</DialogContent>
|
|
</Dialog>
|
|
);
|
|
}
|