refactor: revew all design of services, clients, deadcode, ...
This commit is contained in:
@@ -1,11 +1,8 @@
|
||||
import { useState, useEffect } from "react";
|
||||
import { useToast } from "@/hooks/use-toast";
|
||||
import { Team as TeamType } from "@/lib/types";
|
||||
import { TeamStats } from "@/services/admin-service";
|
||||
import {
|
||||
AdminManagementService,
|
||||
Team,
|
||||
} from "@/services/admin-management-service";
|
||||
import { TeamStats } from "@/lib/admin-types";
|
||||
import { adminClient } from "@/clients";
|
||||
|
||||
interface TeamFormData {
|
||||
name: string;
|
||||
@@ -29,7 +26,7 @@ export function useTeamsManagement(
|
||||
// Charger les teams depuis l'API
|
||||
const fetchTeams = async () => {
|
||||
try {
|
||||
const teamsData = await AdminManagementService.getTeams();
|
||||
const teamsData = await adminClient.getTeams();
|
||||
// Note: on garde les teams existantes pour la compatibilité
|
||||
// Les nouvelles teams créées via l'API seront visibles après rafraîchissement
|
||||
} catch (error) {
|
||||
@@ -68,7 +65,7 @@ export function useTeamsManagement(
|
||||
|
||||
try {
|
||||
setIsSubmitting(true);
|
||||
const newTeam = await AdminManagementService.createTeam(teamFormData);
|
||||
const newTeam = await adminClient.createTeam(teamFormData);
|
||||
toast({
|
||||
title: "Succès",
|
||||
description: "Équipe créée avec succès",
|
||||
@@ -129,10 +126,10 @@ export function useTeamsManagement(
|
||||
|
||||
try {
|
||||
setIsSubmitting(true);
|
||||
await AdminManagementService.updateTeam({
|
||||
await adminClient.updateTeam({
|
||||
id: editingTeam.id,
|
||||
...teamFormData,
|
||||
memberCount: editingTeam.memberCount || 0,
|
||||
memberCount: (editingTeam as any).memberCount || 0,
|
||||
});
|
||||
|
||||
toast({
|
||||
@@ -175,7 +172,7 @@ export function useTeamsManagement(
|
||||
)
|
||||
) {
|
||||
try {
|
||||
await AdminManagementService.deleteTeam(teamId);
|
||||
await adminClient.deleteTeam(teamId);
|
||||
toast({
|
||||
title: "Succès",
|
||||
description: "Équipe supprimée avec succès",
|
||||
@@ -183,9 +180,7 @@ export function useTeamsManagement(
|
||||
|
||||
// Mettre à jour l'état local au lieu de recharger la page
|
||||
setTeams((prev) => prev.filter((t) => t.id !== teamId));
|
||||
setTeamStats((prev) =>
|
||||
prev.filter((stats) => stats.teamId !== teamId)
|
||||
);
|
||||
setTeamStats((prev) => prev.filter((stats) => stats.teamId !== teamId));
|
||||
} catch (error: any) {
|
||||
toast({
|
||||
title: "Erreur",
|
||||
@@ -224,17 +219,15 @@ export function useTeamsManagement(
|
||||
)
|
||||
) {
|
||||
try {
|
||||
await AdminManagementService.deleteDirection(direction);
|
||||
await adminClient.deleteDirection(direction);
|
||||
toast({
|
||||
title: "Succès",
|
||||
description: `Direction "${direction}" et toutes ses équipes supprimées avec succès`,
|
||||
variant: "default",
|
||||
});
|
||||
|
||||
|
||||
// Mettre à jour l'état local au lieu de recharger la page
|
||||
setTeams((prev) =>
|
||||
prev.filter((team) => team.direction !== direction)
|
||||
);
|
||||
setTeams((prev) => prev.filter((team) => team.direction !== direction));
|
||||
setTeamStats((prev) =>
|
||||
prev.filter((stats) => stats.direction !== direction)
|
||||
);
|
||||
@@ -250,9 +243,7 @@ export function useTeamsManagement(
|
||||
};
|
||||
|
||||
// Extraire les directions uniques pour les formulaires
|
||||
const directions = Array.from(
|
||||
new Set(teams.map((team) => team.direction))
|
||||
);
|
||||
const directions = Array.from(new Set(teams.map((team) => team.direction)));
|
||||
|
||||
return {
|
||||
teams,
|
||||
|
||||
Reference in New Issue
Block a user