- Added `cancelled` and `freeze` statuses to `TasksResponse`, `HomePageClientProps`, and `useTasks` for comprehensive task tracking. - Updated task forms to dynamically load statuses using `getAllStatuses`, enhancing maintainability and reducing hardcoded values. - Refactored Kanban components to utilize centralized status configuration, improving consistency across the application. - Adjusted visibility toggle and swimlanes to reflect new status options, ensuring a seamless user experience.
53 lines
1.4 KiB
TypeScript
53 lines
1.4 KiB
TypeScript
import { useState, useEffect } from 'react';
|
|
import { TaskStatus } from '@/lib/types';
|
|
import { userPreferencesService } from '@/services/user-preferences';
|
|
import { getAllStatuses } from '@/lib/status-config';
|
|
|
|
export function useColumnVisibility() {
|
|
const [hiddenStatuses, setHiddenStatuses] = useState<Set<TaskStatus>>(new Set());
|
|
|
|
// Charger les préférences au montage
|
|
useEffect(() => {
|
|
const saved = userPreferencesService.getColumnVisibility();
|
|
setHiddenStatuses(new Set(saved.hiddenStatuses));
|
|
}, []);
|
|
|
|
const toggleStatusVisibility = (status: TaskStatus) => {
|
|
setHiddenStatuses(prev => {
|
|
const newSet = new Set(prev);
|
|
if (newSet.has(status)) {
|
|
newSet.delete(status);
|
|
} else {
|
|
newSet.add(status);
|
|
}
|
|
|
|
// Sauvegarder dans localStorage
|
|
userPreferencesService.saveColumnVisibility({
|
|
hiddenStatuses: Array.from(newSet)
|
|
});
|
|
|
|
return newSet;
|
|
});
|
|
};
|
|
|
|
const getVisibleStatuses = <T extends { id: TaskStatus }>(statuses: T[]): T[] => {
|
|
return statuses.filter(status => !hiddenStatuses.has(status.id));
|
|
};
|
|
|
|
const isStatusVisible = (status: TaskStatus): boolean => {
|
|
return !hiddenStatuses.has(status);
|
|
};
|
|
|
|
const getAllAvailableStatuses = () => {
|
|
return getAllStatuses();
|
|
};
|
|
|
|
return {
|
|
hiddenStatuses,
|
|
toggleStatusVisibility,
|
|
getVisibleStatuses,
|
|
isStatusVisible,
|
|
getAllAvailableStatuses
|
|
};
|
|
}
|