feat: remove a skill category empty
This commit is contained in:
@@ -11,6 +11,51 @@ interface SkillFormData {
|
||||
icon: string;
|
||||
}
|
||||
|
||||
// Hook pour gérer les catégories de skills
|
||||
export function useSkillCategoriesManagement(
|
||||
initialCategories: SkillCategory[]
|
||||
) {
|
||||
const [skillCategories, setSkillCategories] = useState(initialCategories);
|
||||
const { toast } = useToast();
|
||||
|
||||
const handleDeleteCategory = async (categoryName: string) => {
|
||||
try {
|
||||
// Trouver la catégorie par son nom
|
||||
const category = skillCategories.find((cat) => cat.name === categoryName);
|
||||
if (!category) {
|
||||
throw new Error("Catégorie non trouvée");
|
||||
}
|
||||
|
||||
await adminClient.deleteSkillCategory(category.id);
|
||||
|
||||
// Mettre à jour l'état local
|
||||
setSkillCategories((prevCategories) =>
|
||||
prevCategories.filter((cat) => cat.id !== category.id)
|
||||
);
|
||||
|
||||
toast({
|
||||
title: "Succès",
|
||||
description: `Catégorie "${categoryName}" supprimée avec succès`,
|
||||
});
|
||||
return true;
|
||||
} catch (error: any) {
|
||||
toast({
|
||||
title: "Erreur",
|
||||
description:
|
||||
error.message || "Erreur lors de la suppression de la catégorie",
|
||||
variant: "destructive",
|
||||
});
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
return {
|
||||
skillCategories,
|
||||
setSkillCategories,
|
||||
handleDeleteCategory,
|
||||
};
|
||||
}
|
||||
|
||||
export function useSkillsManagement(
|
||||
skillCategories: SkillCategory[],
|
||||
initialSkills?: any[]
|
||||
|
||||
@@ -6,6 +6,7 @@ interface UseTreeViewOptions<T> {
|
||||
groupBy: (item: T) => string;
|
||||
searchTerm: string;
|
||||
onSearchChange: (term: string) => void;
|
||||
availableCategories?: string[]; // Nouvelles catégories disponibles
|
||||
}
|
||||
|
||||
export function useTreeView<T>({
|
||||
@@ -14,6 +15,7 @@ export function useTreeView<T>({
|
||||
groupBy,
|
||||
searchTerm,
|
||||
onSearchChange,
|
||||
availableCategories = [],
|
||||
}: UseTreeViewOptions<T>) {
|
||||
// État pour les catégories ouvertes/fermées
|
||||
const [expandedCategories, setExpandedCategories] = useState<Set<string>>(
|
||||
@@ -33,7 +35,7 @@ export function useTreeView<T>({
|
||||
}, {} as Record<string, T[]>);
|
||||
|
||||
// Filtrer les données en fonction de la recherche
|
||||
return Object.entries(dataByCategory).reduce(
|
||||
const filteredCategories = Object.entries(dataByCategory).reduce(
|
||||
(acc, [category, categoryItems]) => {
|
||||
const filteredItems = categoryItems.filter((item) => {
|
||||
const matchesSearch = searchFields.some((field) => {
|
||||
@@ -53,7 +55,16 @@ export function useTreeView<T>({
|
||||
},
|
||||
{} as Record<string, T[]>
|
||||
);
|
||||
}, [data, searchFields, groupBy, searchTerm]);
|
||||
|
||||
// Ajouter les catégories vides qui sont dans availableCategories
|
||||
availableCategories.forEach(category => {
|
||||
if (!filteredCategories[category]) {
|
||||
filteredCategories[category] = [];
|
||||
}
|
||||
});
|
||||
|
||||
return filteredCategories;
|
||||
}, [data, searchFields, groupBy, searchTerm, availableCategories]);
|
||||
|
||||
// Fonctions pour gérer l'expansion des catégories
|
||||
const toggleCategory = useCallback((category: string) => {
|
||||
|
||||
Reference in New Issue
Block a user