From b5d53ef0f1f99482a4964554b1b1ac3acfd9d647 Mon Sep 17 00:00:00 2001 From: Julien Froidefond Date: Mon, 22 Sep 2025 08:51:59 +0200 Subject: [PATCH] feat: add "Move to Today" functionality for pending tasks - Implemented a new button in the `PendingTasksSection` to move unchecked tasks to today's date. - Created `moveCheckboxToToday` action in `daily.ts` to handle the logic for moving tasks. - Updated `DailyPageClient` and `PendingTasksSection` to integrate the new functionality and refresh the daily view after moving tasks. - Marked the feature as completed in `TODO.md`. --- TODO.md | 1 + src/actions/daily.ts | 22 +++++++++ src/app/daily/DailyPageClient.tsx | 4 +- src/components/daily/PendingTasksSection.tsx | 52 ++++++++++++++++---- src/lib/types.ts | 1 + src/services/daily.ts | 45 +++++++++++++++++ 6 files changed, 114 insertions(+), 11 deletions(-) diff --git a/TODO.md b/TODO.md index 68c7674..3e6230a 100644 --- a/TODO.md +++ b/TODO.md @@ -53,6 +53,7 @@ - [x] Filtrage par date (7/14/30 jours), catégorie (tâches/réunions), ancienneté - [x] Action "Archiver" pour les tâches ni résolues ni à faire - [x] Section repliable dans la page Daily (sous les sections Hier/Aujourd'hui) + - [x] **Bouton "Déplacer à aujourd'hui"** pour les tâches non résolues - [x] Indicateurs visuels d'ancienneté (couleurs vert→rouge) - [x] Actions par tâche : Cocher, Archiver, Supprimer - [x] **Statut "Archivé" basique** diff --git a/src/actions/daily.ts b/src/actions/daily.ts index 2f3789f..bd43263 100644 --- a/src/actions/daily.ts +++ b/src/actions/daily.ts @@ -256,3 +256,25 @@ export async function reorderCheckboxes(dailyId: string, checkboxIds: string[]): }; } } + +/** + * Déplace une checkbox non cochée à aujourd'hui + */ +export async function moveCheckboxToToday(checkboxId: string): Promise<{ + success: boolean; + data?: DailyCheckbox; + error?: string; +}> { + try { + const updatedCheckbox = await dailyService.moveCheckboxToToday(checkboxId); + + revalidatePath('/daily'); + return { success: true, data: updatedCheckbox }; + } catch (error) { + console.error('Erreur moveCheckboxToToday:', error); + return { + success: false, + error: error instanceof Error ? error.message : 'Erreur inconnue' + }; + } +} diff --git a/src/app/daily/DailyPageClient.tsx b/src/app/daily/DailyPageClient.tsx index ca7ee90..ca4aae7 100644 --- a/src/app/daily/DailyPageClient.tsx +++ b/src/app/daily/DailyPageClient.tsx @@ -42,7 +42,8 @@ export function DailyPageClient({ goToPreviousDay, goToNextDay, goToToday, - setDate + setDate, + refreshDailySilent } = useDaily(initialDate, initialDailyView); const [dailyDates, setDailyDates] = useState(initialDailyDates); @@ -294,6 +295,7 @@ export function DailyPageClient({ diff --git a/src/components/daily/PendingTasksSection.tsx b/src/components/daily/PendingTasksSection.tsx index b8e5b60..07637be 100644 --- a/src/components/daily/PendingTasksSection.tsx +++ b/src/components/daily/PendingTasksSection.tsx @@ -1,26 +1,30 @@ 'use client'; -import { useState, useEffect, useCallback } from 'react'; +import { useState, useEffect, useCallback, useTransition } from 'react'; import { Card, CardHeader, CardContent } from '@/components/ui/Card'; import { Button } from '@/components/ui/Button'; import { DailyCheckbox, DailyCheckboxType } from '@/lib/types'; import { dailyClient } from '@/clients/daily-client'; import { formatDateShort, getDaysAgo } from '@/lib/date-utils'; +import { moveCheckboxToToday } from '@/actions/daily'; interface PendingTasksSectionProps { onToggleCheckbox: (checkboxId: string) => Promise; onDeleteCheckbox: (checkboxId: string) => Promise; + onRefreshDaily?: () => Promise; // Pour rafraîchir la vue daily principale refreshTrigger?: number; // Pour forcer le refresh depuis le parent } export function PendingTasksSection({ onToggleCheckbox, onDeleteCheckbox, + onRefreshDaily, refreshTrigger }: PendingTasksSectionProps) { const [isCollapsed, setIsCollapsed] = useState(true); const [pendingTasks, setPendingTasks] = useState([]); const [loading, setLoading] = useState(false); + const [isPending, startTransition] = useTransition(); const [filters, setFilters] = useState({ maxDays: 7, type: 'all' as 'all' | DailyCheckboxType, @@ -74,6 +78,22 @@ export function PendingTasksSection({ await loadPendingTasks(); // Recharger la liste }; + // Gérer le déplacement d'une tâche à aujourd'hui + const handleMoveToToday = (checkboxId: string) => { + startTransition(async () => { + const result = await moveCheckboxToToday(checkboxId); + + if (result.success) { + await loadPendingTasks(); // Recharger la liste des tâches en attente + if (onRefreshDaily) { + await onRefreshDaily(); // Rafraîchir la vue daily principale + } + } else { + console.error('Erreur lors du déplacement vers aujourd\'hui:', result.error); + } + }); + }; + // Obtenir la couleur selon l'ancienneté const getAgeColor = (date: Date) => { const days = getDaysAgo(date); @@ -207,15 +227,27 @@ export function PendingTasksSection({ {/* Actions */}
{!isArchived && ( - + <> + + + )}