feat: add related todos functionality in task editing

- Implemented `RelatedTodos` component in `EditTaskForm` to display and manage related todos for a task.
- Updated `TasksClient` to fetch daily checkboxes related to a task.
- Enhanced `TasksService` with a method to retrieve related daily checkboxes from the database.
- Added functionality to create new todos linked to tasks in the daily actions.
- Marked the task for displaying related todos in the task editing interface as complete in TODO.md.
This commit is contained in:
Julien Froidefond
2025-09-18 15:26:07 +02:00
parent 729a04d557
commit 02f59caf08
7 changed files with 345 additions and 5 deletions

View File

@@ -1,7 +1,7 @@
'use server';
import { dailyService } from '@/services/daily';
import { UpdateDailyCheckboxData, DailyCheckbox } from '@/lib/types';
import { UpdateDailyCheckboxData, DailyCheckbox, CreateDailyCheckboxData } from '@/lib/types';
import { revalidatePath } from 'next/cache';
/**
@@ -198,6 +198,40 @@ export async function deleteCheckbox(checkboxId: string): Promise<{
}
}
/**
* Ajoute un todo lié à une tâche
*/
export async function addTodoToTask(taskId: string, text: string, date?: Date): Promise<{
success: boolean;
data?: DailyCheckbox;
error?: string;
}> {
try {
const targetDate = date || new Date();
targetDate.setHours(0, 0, 0, 0);
const checkboxData: CreateDailyCheckboxData = {
date: targetDate,
text: text.trim(),
type: 'task',
taskId: taskId,
isChecked: false
};
const checkbox = await dailyService.addCheckbox(checkboxData);
revalidatePath('/daily');
revalidatePath('/kanban');
return { success: true, data: checkbox };
} catch (error) {
console.error('Erreur addTodoToTask:', error);
return {
success: false,
error: error instanceof Error ? error.message : 'Erreur inconnue'
};
}
}
/**
* Réorganise les checkboxes d'une date
*/

View File

@@ -0,0 +1,28 @@
import { NextRequest, NextResponse } from 'next/server';
import { tasksService } from '@/services/tasks';
export async function GET(
request: NextRequest,
{ params }: { params: Promise<{ id: string }> }
) {
try {
const { id } = await params;
if (!id) {
return NextResponse.json(
{ error: 'ID de tâche requis' },
{ status: 400 }
);
}
const checkboxes = await tasksService.getTaskRelatedCheckboxes(id);
return NextResponse.json({ data: checkboxes });
} catch (error) {
console.error('Erreur lors de la récupération des checkboxes:', error);
return NextResponse.json(
{ error: 'Erreur lors de la récupération des checkboxes' },
{ status: 500 }
);
}
}