fix: move delete user button to client component to fix onClick error
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
'use client';
|
||||
|
||||
import { Trash2 } from 'lucide-react';
|
||||
import { deleteUser } from './actions';
|
||||
|
||||
export function DeleteUserButton({ userId, username, disabled }: { userId: string; username: string; disabled: boolean }) {
|
||||
if (disabled) return null;
|
||||
|
||||
const handleSubmit = (e: React.FormEvent<HTMLFormElement>) => {
|
||||
if (!confirm(`"${username}" kullanıcısı silinsin mi?`)) {
|
||||
e.preventDefault();
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<form action={deleteUser} onSubmit={handleSubmit}>
|
||||
<input type="hidden" name="id" value={userId} />
|
||||
<button
|
||||
type="submit"
|
||||
title="Kullanıcıyı Sil"
|
||||
className="p-2 text-red-400 hover:text-red-600 hover:bg-red-50 dark:hover:bg-red-900/20 rounded-lg transition-colors"
|
||||
>
|
||||
<Trash2 className="w-4 h-4" />
|
||||
</button>
|
||||
</form>
|
||||
);
|
||||
}
|
||||
@@ -1,8 +1,9 @@
|
||||
import { prisma } from '@/lib/db';
|
||||
import { getSession } from '@/lib/auth';
|
||||
import { redirect } from 'next/navigation';
|
||||
import { UserPlus, Trash2, KeyRound, ShieldCheck } from 'lucide-react';
|
||||
import { createUser, deleteUser, changePassword } from './actions';
|
||||
import { UserPlus, KeyRound, ShieldCheck } from 'lucide-react';
|
||||
import { createUser, changePassword } from './actions';
|
||||
import { DeleteUserButton } from './DeleteUserButton';
|
||||
|
||||
export default async function UsersAdminPage() {
|
||||
const session = await getSession();
|
||||
@@ -95,23 +96,11 @@ export default async function UsersAdminPage() {
|
||||
})}
|
||||
</p>
|
||||
</div>
|
||||
{users.length > 1 && (
|
||||
<form action={deleteUser}>
|
||||
<input type="hidden" name="id" value={user.id} />
|
||||
<button
|
||||
type="submit"
|
||||
title="Kullanıcıyı Sil"
|
||||
className="p-2 text-red-400 hover:text-red-600 hover:bg-red-50 dark:hover:bg-red-900/20 rounded-lg transition-colors"
|
||||
onClick={(e) => {
|
||||
if (!confirm(`"${user.username}" kullanıcısı silinsin mi?`)) {
|
||||
e.preventDefault();
|
||||
}
|
||||
}}
|
||||
>
|
||||
<Trash2 className="w-4 h-4" />
|
||||
</button>
|
||||
</form>
|
||||
)}
|
||||
<DeleteUserButton
|
||||
userId={user.id}
|
||||
username={user.username}
|
||||
disabled={users.length <= 1}
|
||||
/>
|
||||
</div>
|
||||
))}
|
||||
{users.length === 0 && (
|
||||
|
||||
Reference in New Issue
Block a user