refactor: unify date handling with utility functions
- Replaced direct date manipulations with utility functions like `getToday`, `parseDate`, and `createDateFromParts` across various components and services for consistency. - Updated date initialization in `JiraAnalyticsService`, `BackupService`, and `DailyClient` to improve clarity and maintainability. - Enhanced date parsing in forms and API routes to ensure proper handling of date strings.
This commit is contained in:
@@ -8,6 +8,7 @@ import { TagInput } from '@/components/ui/TagInput';
|
||||
import { TaskPriority, TaskStatus } from '@/lib/types';
|
||||
import { CreateTaskData } from '@/clients/tasks-client';
|
||||
import { getAllStatuses, getAllPriorities } from '@/lib/status-config';
|
||||
import { formatDateForDateTimeInput, parseDateTimeInput } from '@/lib/date-utils';
|
||||
|
||||
interface CreateTaskFormProps {
|
||||
isOpen: boolean;
|
||||
@@ -151,10 +152,10 @@ export function CreateTaskForm({ isOpen, onClose, onSubmit, loading = false }: C
|
||||
<Input
|
||||
label="Date d'échéance"
|
||||
type="datetime-local"
|
||||
value={formData.dueDate ? new Date(formData.dueDate.getTime() - formData.dueDate.getTimezoneOffset() * 60000).toISOString().slice(0, 16) : ''}
|
||||
value={formData.dueDate ? formatDateForDateTimeInput(formData.dueDate) : ''}
|
||||
onChange={(e) => setFormData((prev: CreateTaskData) => ({
|
||||
...prev,
|
||||
dueDate: e.target.value ? new Date(e.target.value) : undefined
|
||||
dueDate: e.target.value ? parseDateTimeInput(e.target.value) : undefined
|
||||
}))}
|
||||
disabled={loading}
|
||||
/>
|
||||
|
||||
@@ -11,6 +11,7 @@ import { Task, TaskPriority, TaskStatus } from '@/lib/types';
|
||||
import { useUserPreferences } from '@/contexts/UserPreferencesContext';
|
||||
// UpdateTaskData removed - using Server Actions directly
|
||||
import { getAllStatuses, getAllPriorities } from '@/lib/status-config';
|
||||
import { formatDateForDateTimeInput, parseDateTimeInput } from '@/lib/date-utils';
|
||||
|
||||
interface EditTaskFormProps {
|
||||
isOpen: boolean;
|
||||
@@ -56,7 +57,7 @@ export function EditTaskForm({ isOpen, onClose, onSubmit, task, loading = false
|
||||
status: task.status,
|
||||
priority: task.priority,
|
||||
tags: task.tags || [],
|
||||
dueDate: task.dueDate ? new Date(task.dueDate) : undefined
|
||||
dueDate: task.dueDate
|
||||
});
|
||||
}
|
||||
}, [task]);
|
||||
@@ -181,10 +182,10 @@ export function EditTaskForm({ isOpen, onClose, onSubmit, task, loading = false
|
||||
<Input
|
||||
label="Date d'échéance"
|
||||
type="datetime-local"
|
||||
value={formData.dueDate ? new Date(formData.dueDate.getTime() - formData.dueDate.getTimezoneOffset() * 60000).toISOString().slice(0, 16) : ''}
|
||||
value={formData.dueDate ? formatDateForDateTimeInput(formData.dueDate) : ''}
|
||||
onChange={(e) => setFormData(prev => ({
|
||||
...prev,
|
||||
dueDate: e.target.value ? new Date(e.target.value) : undefined
|
||||
dueDate: e.target.value ? parseDateTimeInput(e.target.value) : undefined
|
||||
}))}
|
||||
disabled={loading}
|
||||
/>
|
||||
|
||||
@@ -6,6 +6,7 @@ import { TagInput } from '@/components/ui/TagInput';
|
||||
import { TaskStatus, TaskPriority } from '@/lib/types';
|
||||
import { CreateTaskData } from '@/clients/tasks-client';
|
||||
import { getAllPriorities } from '@/lib/status-config';
|
||||
import { formatDateForDateTimeInput, parseDateTimeInput } from '@/lib/date-utils';
|
||||
|
||||
interface QuickAddTaskProps {
|
||||
status: TaskStatus;
|
||||
@@ -189,10 +190,10 @@ export function QuickAddTask({ status, onSubmit, onCancel, swimlaneContext }: Qu
|
||||
<div className="flex items-center justify-between text-xs min-w-0">
|
||||
<input
|
||||
type="datetime-local"
|
||||
value={formData.dueDate ? new Date(formData.dueDate.getTime() - formData.dueDate.getTimezoneOffset() * 60000).toISOString().slice(0, 16) : ''}
|
||||
value={formData.dueDate ? formatDateForDateTimeInput(formData.dueDate) : ''}
|
||||
onChange={(e) => setFormData(prev => ({
|
||||
...prev,
|
||||
dueDate: e.target.value ? new Date(e.target.value) : undefined
|
||||
dueDate: e.target.value ? parseDateTimeInput(e.target.value) : undefined
|
||||
}))}
|
||||
onFocus={() => setActiveField('date')}
|
||||
disabled={isSubmitting}
|
||||
|
||||
@@ -194,7 +194,7 @@ export default function BackupSettingsPageClient({ initialData }: BackupSettings
|
||||
|
||||
const formatDate = (date: string | Date): string => {
|
||||
// Format cohérent serveur/client pour éviter les erreurs d'hydratation
|
||||
const d = typeof date === 'string' ? new Date(date) : date;
|
||||
const d = typeof date === 'string' ? parseDate(date) : date;
|
||||
return formatDateForDisplay(d, 'DISPLAY_MEDIUM');
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user