mirror of
https://github.com/R0m1k3/CollectFlow.git
synced 2026-10-11 17:26:32 +02:00
feat: Introduce an admin user management component to create, delete, and update user passwords.
This commit is contained in:
1 parent
44d7f95d4c
commit
997abee21a
1 file changed
+30
-1
@@ -1,7 +1,7 @@
|
||||
"use client";
|
||||
|
||||
import { useState, useEffect } from "react";
|
||||
import { getUsers, createUser, deleteUser } from "../api/user-actions";
|
||||
import { getUsers, createUser, deleteUser, updatePassword } from "../api/user-actions";
|
||||
import {
|
||||
UserPlus,
|
||||
Trash2,
|
||||
@@ -9,6 +9,7 @@ import {
|
||||
User,
|
||||
Loader2,
|
||||
Check,
|
||||
Key,
|
||||
} from "lucide-react";
|
||||
import { SuccessModal } from "@/components/shared/success-modal";
|
||||
|
||||
@@ -56,6 +57,27 @@ export function UserManagement() {
|
||||
setIsCreating(false);
|
||||
};
|
||||
|
||||
const handleUpdatePassword = async (id: number, username: string) => {
|
||||
const pass = window.prompt(`Nouveau mot de passe pour ${username} :`);
|
||||
if (!pass) return;
|
||||
|
||||
if (pass.length < 4) {
|
||||
alert("Le mot de passe doit faire au moins 4 caractères.");
|
||||
return;
|
||||
}
|
||||
|
||||
const res = await updatePassword(id, pass);
|
||||
if (res.success) {
|
||||
setModal({
|
||||
isOpen: true,
|
||||
title: "Mot de passe mis à jour",
|
||||
message: `Le mot de passe de ${username} a été modifié avec succès.`
|
||||
});
|
||||
} else {
|
||||
alert(res.error);
|
||||
}
|
||||
};
|
||||
|
||||
const handleDelete = async (id: number, username: string) => {
|
||||
if (!window.confirm(`Supprimer l'utilisateur ${username} ?`)) return;
|
||||
const res = await deleteUser(id);
|
||||
@@ -148,6 +170,13 @@ export function UserManagement() {
|
||||
</span>
|
||||
</div>
|
||||
<div className="flex items-center gap-2 opacity-0 group-hover:opacity-100 transition-opacity">
|
||||
<button
|
||||
onClick={() => handleUpdatePassword(u.id, u.username)}
|
||||
className="p-2.5 rounded-xl hover:bg-indigo-500/10 text-slate-500 hover:text-indigo-400 transition-colors"
|
||||
title="Changer le mot de passe"
|
||||
>
|
||||
<Key className="w-4 h-4" />
|
||||
</button>
|
||||
<button
|
||||
onClick={() => handleDelete(u.id, u.username)}
|
||||
className="p-2.5 rounded-xl hover:bg-rose-500/10 text-slate-500 hover:text-rose-500 transition-colors"
|
||||
|
||||
Reference in new issue
Block a user