- Added user tracking features to the projects module, including: - Database schema updates to track project creator and assignee. - API enhancements for user management and project filtering by user. - UI components for user assignment in project forms and listings. - New query functions for retrieving users and filtering projects. - Security integration with role-based access and authentication requirements. chore: Create utility scripts for database checks and project testing - Added scripts to check the structure of the projects table. - Created tests for project creation and user tracking functionality. - Implemented API tests to verify project retrieval and user assignment. fix: Update project creation and update functions to include user tracking - Modified createProject and updateProject functions to handle user IDs for creator and assignee. - Ensured that project updates reflect the correct user assignments and timestamps.
114 lines
2.6 KiB
JavaScript
114 lines
2.6 KiB
JavaScript
"use client";
|
|
|
|
import { useEffect, useState } from "react";
|
|
import { useParams } from "next/navigation";
|
|
import ProjectForm from "@/components/ProjectForm";
|
|
import PageContainer from "@/components/ui/PageContainer";
|
|
import PageHeader from "@/components/ui/PageHeader";
|
|
import Button from "@/components/ui/Button";
|
|
import Link from "next/link";
|
|
import { LoadingState } from "@/components/ui/States";
|
|
|
|
export default function EditProjectPage() {
|
|
const params = useParams();
|
|
const id = params.id;
|
|
const [project, setProject] = useState(null);
|
|
const [loading, setLoading] = useState(true);
|
|
const [error, setError] = useState(null);
|
|
|
|
useEffect(() => {
|
|
const fetchProject = async () => {
|
|
try {
|
|
const res = await fetch(`/api/projects/${id}`);
|
|
if (res.ok) {
|
|
const projectData = await res.json();
|
|
setProject(projectData);
|
|
} else {
|
|
setError("Project not found");
|
|
}
|
|
} catch (err) {
|
|
setError("Failed to load project");
|
|
} finally {
|
|
setLoading(false);
|
|
}
|
|
};
|
|
|
|
if (id) {
|
|
fetchProject();
|
|
}
|
|
}, [id]);
|
|
|
|
if (loading) {
|
|
return (
|
|
<PageContainer>
|
|
<LoadingState />
|
|
</PageContainer>
|
|
);
|
|
}
|
|
|
|
if (error || !project) {
|
|
return (
|
|
<PageContainer>
|
|
<div className="text-center py-12">
|
|
<p className="text-red-600 text-lg mb-4">Project not found.</p>
|
|
<Link href="/projects">
|
|
<Button variant="primary">Back to Projects</Button>
|
|
</Link>
|
|
</div>
|
|
</PageContainer>
|
|
);
|
|
}
|
|
|
|
return (
|
|
<PageContainer>
|
|
<PageHeader
|
|
title="Edit Project"
|
|
description={`Editing: ${project.project_name || "Untitled Project"}`}
|
|
action={
|
|
<div className="flex items-center gap-3">
|
|
<Link href={`/projects/${id}`}>
|
|
<Button variant="outline" size="sm">
|
|
<svg
|
|
className="w-4 h-4 mr-2"
|
|
fill="none"
|
|
stroke="currentColor"
|
|
viewBox="0 0 24 24"
|
|
>
|
|
<path
|
|
strokeLinecap="round"
|
|
strokeLinejoin="round"
|
|
strokeWidth={2}
|
|
d="M6 18L18 6M6 6l12 12"
|
|
/>
|
|
</svg>
|
|
Cancel
|
|
</Button>
|
|
</Link>
|
|
<Link href="/projects">
|
|
<Button variant="outline" size="sm">
|
|
<svg
|
|
className="w-4 h-4 mr-2"
|
|
fill="none"
|
|
stroke="currentColor"
|
|
viewBox="0 0 24 24"
|
|
>
|
|
<path
|
|
strokeLinecap="round"
|
|
strokeLinejoin="round"
|
|
strokeWidth={2}
|
|
d="M15 19l-7-7 7-7"
|
|
/>
|
|
</svg>
|
|
Back to Projects
|
|
</Button>
|
|
</Link>
|
|
</div>
|
|
}
|
|
/>
|
|
<div className="max-w-2xl">
|
|
<ProjectForm initialData={project} />
|
|
</div>
|
|
</PageContainer>
|
|
);
|
|
}
|