refactor: convert admin user management to Server Actions

- Add src/app/actions/admin.ts with updateUserRoles, deleteUser, resetUserPassword
- Update EditUserDialog, DeleteUserDialog, ResetPasswordDialog to use Server Actions
- Remove admin users API routes (PATCH/DELETE/PUT)
This commit is contained in:
2026-02-28 11:06:42 +01:00
parent 7134c069d7
commit b40f59bec6
7 changed files with 87 additions and 164 deletions

View File

@@ -13,6 +13,7 @@ import {
} from "@/components/ui/alert-dialog";
import { useToast } from "@/components/ui/use-toast";
import type { AdminUserData } from "@/lib/services/admin.service";
import { deleteUser } from "@/app/actions/admin";
interface DeleteUserDialogProps {
user: AdminUserData;
@@ -29,13 +30,10 @@ export function DeleteUserDialog({ user, open, onOpenChange, onSuccess }: Delete
setIsLoading(true);
try {
const response = await fetch(`/api/admin/users/${user.id}`, {
method: "DELETE",
});
const result = await deleteUser(user.id);
if (!response.ok) {
const data = await response.json();
throw new Error(data.error || "Erreur lors de la suppression");
if (!result.success) {
throw new Error(result.message);
}
toast({

View File

@@ -14,6 +14,7 @@ import { Checkbox } from "@/components/ui/checkbox";
import { Label } from "@/components/ui/label";
import { useToast } from "@/components/ui/use-toast";
import type { AdminUserData } from "@/lib/services/admin.service";
import { updateUserRoles } from "@/app/actions/admin";
interface EditUserDialogProps {
user: AdminUserData;
@@ -51,15 +52,10 @@ export function EditUserDialog({ user, open, onOpenChange, onSuccess }: EditUser
setIsLoading(true);
try {
const response = await fetch(`/api/admin/users/${user.id}`, {
method: "PATCH",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ roles: selectedRoles }),
});
const result = await updateUserRoles(user.id, selectedRoles);
if (!response.ok) {
const data = await response.json();
throw new Error(data.error || "Erreur lors de la mise à jour");
if (!result.success) {
throw new Error(result.message);
}
toast({

View File

@@ -15,6 +15,7 @@ import { Label } from "@/components/ui/label";
import { useToast } from "@/components/ui/use-toast";
import { Lock } from "lucide-react";
import type { AdminUserData } from "@/lib/services/admin.service";
import { resetUserPassword } from "@/app/actions/admin";
interface ResetPasswordDialogProps {
user: AdminUserData;
@@ -65,15 +66,10 @@ export function ResetPasswordDialog({
setIsLoading(true);
try {
const response = await fetch(`/api/admin/users/${user.id}/password`, {
method: "PUT",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ newPassword }),
});
const result = await resetUserPassword(user.id, newPassword);
if (!response.ok) {
const data = await response.json();
throw new Error(data.error || "Erreur lors de la réinitialisation");
if (!result.success) {
throw new Error(result.message);
}
toast({