Enable duplicating closed projects with new planned end dates

Update project restarting logic to create a duplicate of a closed project, assign it a new ID, reset its status to 'planning', and set a new planned end date. The original project remains closed.

Replit-Commit-Author: Agent
Replit-Commit-Session-Id: ceced2fc-aa46-458d-ba87-ddd4b7bb1518
Replit-Commit-Checkpoint-Type: intermediate_checkpoint
Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/659922a9-0087-461c-90dd-6d9a58b81d4d/ceced2fc-aa46-458d-ba87-ddd4b7bb1518/P2PZNJ9
This commit is contained in:
paul-nothaft
2025-09-11 21:54:25 +00:00
parent 4d0d750042
commit d08429e74b
+20 -9
View File
@@ -229,23 +229,34 @@ export default function ProjectTemplate({
const handleConfirmRestart = () => {
if (restartingProject && newEndDate) {
const restartedProject: Project = {
// Create a new project as a duplicate/copy of the closed project
const newProjectId = Date.now().toString();
const duplicatedProject: Project = {
...restartingProject,
status: 'planning',
startDate: new Date(),
endDate: newEndDate,
tasks: clearHistory ? [] : restartingProject.tasks.map(task => ({ ...task, status: 'todo' as const }))
id: newProjectId, // New unique ID
status: 'planning', // Start as planning
startDate: new Date(), // Set new start date
endDate: undefined, // Clear end date since it's active again
plannedEndDate: newEndDate, // Set the new planned end date
createdAt: new Date(), // Set new creation date
tasks: clearHistory
? []
: restartingProject.tasks.map(task => ({
...task,
id: `${newProjectId}-task-${Date.now()}-${Math.random().toString(36).substr(2, 9)}`, // Generate new task ID
status: 'todo' as const // Reset all tasks to todo status
}))
};
setProjects(projects.map(p =>
p.id === restartingProject.id ? restartedProject : p
));
// Add the new project to the projects array without removing the original
setProjects([...projects, duplicatedProject]);
setIsRestartProjectOpen(false);
setRestartingProject(null);
setNewEndDate(undefined);
setClearHistory(false);
console.log('Project restarted:', restartedProject.name, 'Clear history:', clearHistory);
console.log('Project duplicated:', duplicatedProject.name, 'with', duplicatedProject.tasks.length, 'tasks. Original project remains closed.');
}
};