refactor: remove legacy evaluation route and update user management interfaces
- Deleted the obsolete evaluations route to streamline the API. - Added User and UserFormData interfaces to admin-client for better user management. - Updated useUsersManagement hook to utilize adminClient for fetching and creating users, improving data handling. - Cleaned up unused imports and code for better maintainability.
This commit is contained in:
@@ -1,20 +1,8 @@
|
||||
import { useState, useEffect } from "react";
|
||||
import { useToast } from "@/hooks/use-toast";
|
||||
import { Team } from "@/lib/types";
|
||||
|
||||
interface User {
|
||||
uuid: string;
|
||||
firstName: string;
|
||||
lastName: string;
|
||||
teamName?: string;
|
||||
hasEvaluations: boolean;
|
||||
}
|
||||
|
||||
interface UserFormData {
|
||||
firstName: string;
|
||||
lastName: string;
|
||||
teamId: string;
|
||||
}
|
||||
import { adminClient } from "@/clients";
|
||||
import { User, UserFormData } from "@/clients/domains/admin-client";
|
||||
|
||||
export function useUsersManagement(teams: Team[]) {
|
||||
const [users, setUsers] = useState<User[]>([]);
|
||||
@@ -34,11 +22,7 @@ export function useUsersManagement(teams: Team[]) {
|
||||
setIsLoading(true);
|
||||
setError(null);
|
||||
try {
|
||||
const response = await fetch("/api/admin/users");
|
||||
if (!response.ok) {
|
||||
throw new Error("Erreur lors de la récupération des utilisateurs");
|
||||
}
|
||||
const usersData = await response.json();
|
||||
const usersData = await adminClient.getUsers();
|
||||
setUsers(usersData);
|
||||
} catch (err: any) {
|
||||
setError(err.message || "Erreur lors du chargement des utilisateurs");
|
||||
@@ -68,7 +52,7 @@ export function useUsersManagement(teams: Team[]) {
|
||||
|
||||
try {
|
||||
setIsSubmitting(true);
|
||||
// TODO: Implémenter la création d'utilisateur
|
||||
await adminClient.createUser(userFormData);
|
||||
toast({
|
||||
title: "Succès",
|
||||
description: "Utilisateur créé avec succès",
|
||||
@@ -112,8 +96,7 @@ export function useUsersManagement(teams: Team[]) {
|
||||
|
||||
setDeletingUserId(user.uuid);
|
||||
try {
|
||||
// TODO: Implémenter la suppression d'utilisateur
|
||||
// await adminClient.deleteUser(user.uuid);
|
||||
await adminClient.deleteUser(user.uuid);
|
||||
|
||||
// Mettre à jour la liste locale
|
||||
setUsers((prev) => prev.filter((u) => u.uuid !== user.uuid));
|
||||
|
||||
Reference in New Issue
Block a user