26 lines
820 B
TypeScript
26 lines
820 B
TypeScript
"use client";
|
||
|
||
import { useState } from "react";
|
||
import { useRouter } from "next/navigation";
|
||
|
||
export default function ActivateRoundButton({ roundId, isActive }: { roundId: string; isActive: boolean }) {
|
||
const router = useRouter();
|
||
const [loading, setLoading] = useState(false);
|
||
|
||
async function activate() {
|
||
setLoading(true);
|
||
await fetch(`/api/rounds/${roundId}/activate`, { method: "POST" });
|
||
router.refresh();
|
||
setLoading(false);
|
||
}
|
||
|
||
if (isActive) return <span className="text-xs text-green-600 font-medium px-3 py-1.5">✓ فعال</span>;
|
||
|
||
return (
|
||
<button onClick={activate} disabled={loading}
|
||
className="bg-blue-600 text-white px-3 py-1.5 rounded-lg text-sm hover:bg-blue-700 transition disabled:opacity-50">
|
||
{loading ? "..." : "فعالسازی"}
|
||
</button>
|
||
);
|
||
}
|