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[]
|
||||
|
||||
Reference in New Issue
Block a user