feat(frontend): Implement Project Detail Page with edit and archive functionality

Add complete project detail page with real-time updates via SignalR.

Changes:
- Updated project detail page with edit and archive buttons
- Created EditProjectDialog component for updating projects
- Created ArchiveProjectDialog component for archiving projects
- Integrated SignalR real-time updates (onProjectUpdated, onProjectArchived)
- Added SignalR connection status indicator
- Enhanced useProjectHub hook to support callback options
- Improved UI layout with two-column card grid
- Added toast notifications for user feedback

Features:
- View project details (name, description, status, timestamps)
- Edit project name and description
- Archive active projects
- Real-time updates when project is modified by other users
- Automatic redirect when project is archived

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Yaojia Wang
2025-11-04 10:40:58 +01:00
parent bdbb187ee4
commit 149bb9bd88
4 changed files with 365 additions and 46 deletions

View File

@@ -0,0 +1,81 @@
'use client';
import { useRouter } from 'next/navigation';
import { useDeleteProject } from '@/lib/hooks/use-projects';
import {
Dialog,
DialogContent,
DialogDescription,
DialogFooter,
DialogHeader,
DialogTitle,
} from '@/components/ui/dialog';
import { Button } from '@/components/ui/button';
import { toast } from 'sonner';
interface ArchiveProjectDialogProps {
projectId: string;
projectName: string;
open: boolean;
onOpenChange: (open: boolean) => void;
}
export function ArchiveProjectDialog({
projectId,
projectName,
open,
onOpenChange,
}: ArchiveProjectDialogProps) {
const router = useRouter();
const deleteProject = useDeleteProject();
const handleArchive = async () => {
try {
await deleteProject.mutateAsync(projectId);
toast.success('Project archived successfully');
router.push('/projects');
} catch (error) {
toast.error('Failed to archive project');
console.error('Archive error:', error);
}
};
return (
<Dialog open={open} onOpenChange={onOpenChange}>
<DialogContent className="sm:max-w-[425px]">
<DialogHeader>
<DialogTitle>Archive Project</DialogTitle>
<DialogDescription>
Are you sure you want to archive{' '}
<strong className="font-semibold">{projectName}</strong>?
</DialogDescription>
</DialogHeader>
<div className="py-4">
<p className="text-sm text-muted-foreground">
This action will mark the project as archived, but it can be
restored later. All associated issues and data will be preserved.
</p>
</div>
<DialogFooter>
<Button
type="button"
variant="outline"
onClick={() => onOpenChange(false)}
>
Cancel
</Button>
<Button
type="button"
variant="destructive"
onClick={handleArchive}
disabled={deleteProject.isPending}
>
{deleteProject.isPending ? 'Archiving...' : 'Archive Project'}
</Button>
</DialogFooter>
</DialogContent>
</Dialog>
);
}

View File

@@ -0,0 +1,139 @@
'use client';
import { useForm } from 'react-hook-form';
import { zodResolver } from '@hookform/resolvers/zod';
import * as z from 'zod';
import { useUpdateProject } from '@/lib/hooks/use-projects';
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 type { Project } from '@/types/project';
import { toast } from 'sonner';
const updateProjectSchema = 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'),
});
type UpdateProjectFormData = z.infer<typeof updateProjectSchema>;
interface EditProjectDialogProps {
project: Project;
open: boolean;
onOpenChange: (open: boolean) => void;
}
export function EditProjectDialog({
project,
open,
onOpenChange,
}: EditProjectDialogProps) {
const updateProject = useUpdateProject(project.id);
const form = useForm<UpdateProjectFormData>({
resolver: zodResolver(updateProjectSchema),
defaultValues: {
name: project.name,
description: project.description,
},
});
const onSubmit = async (data: UpdateProjectFormData) => {
try {
await updateProject.mutateAsync(data);
toast.success('Project updated successfully');
onOpenChange(false);
} catch (error) {
toast.error('Failed to update project');
console.error('Update error:', error);
}
};
return (
<Dialog open={open} onOpenChange={onOpenChange}>
<DialogContent className="sm:max-w-[525px]">
<DialogHeader>
<DialogTitle>Edit Project</DialogTitle>
<DialogDescription>
Update project details. Changes will be saved immediately.
</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="description"
render={({ field }) => (
<FormItem>
<FormLabel>Description</FormLabel>
<FormControl>
<Input
placeholder="A brief description of the project..."
{...field}
/>
</FormControl>
<FormDescription>
A brief description for your project.
</FormDescription>
<FormMessage />
</FormItem>
)}
/>
<DialogFooter>
<Button
type="button"
variant="outline"
onClick={() => onOpenChange(false)}
>
Cancel
</Button>
<Button type="submit" disabled={updateProject.isPending}>
{updateProject.isPending ? 'Saving...' : 'Save Changes'}
</Button>
</DialogFooter>
</form>
</Form>
</DialogContent>
</Dialog>
);
}