Files
football-next/app/(admin)/admin/players/[id]/edit/DeleteButton.tsx
a.alinaghipour aa9ed69dd2 first commit
2026-04-05 15:53:20 +03:30

35 lines
1000 B
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"use client";
import { useRouter } from "next/navigation";
import { useState } from "react";
export default function DeleteButton({ playerId }: { playerId: string }) {
const router = useRouter();
const [confirm, setConfirm] = useState(false);
async function handleDelete() {
await fetch(`/api/players/${playerId}`, { method: "DELETE" });
router.push("/admin/players");
router.refresh();
}
if (confirm) {
return (
<div className="flex gap-2">
<button onClick={handleDelete} className="bg-red-600 text-white px-4 py-2 rounded-xl text-sm hover:bg-red-700">
تأیید حذف
</button>
<button onClick={() => setConfirm(false)} className="bg-gray-200 px-4 py-2 rounded-xl text-sm hover:bg-gray-300">
انصراف
</button>
</div>
);
}
return (
<button onClick={() => setConfirm(true)} className="text-red-500 hover:text-red-700 text-sm font-medium">
حذف بازیکن
</button>
);
}