RippleWorkers / src /components /dashboard /settings /DisconnectButton.tsx
damndeepesh
Initialize project with LavinMQ integration and Docker support
c7fbc2e
Raw History Blame Contribute Delete
1.51 kB
"use client";
import { useState } from "react";
import { Unlink, Loader2, Trash2 } from "lucide-react";
import { disconnectAccount } from "@/app/dashboard/settings/actions";
import { useRouter } from "next/navigation";
interface DisconnectButtonProps {
accountId: string;
username: string;
}
export default function DisconnectButton({ accountId, username }: DisconnectButtonProps) {
const [isPending, setIsPending] = useState(false);
const router = useRouter();
const handleDisconnect = async () => {
if (!confirm(`Are you sure you want to disconnect @${username}?`)) return;
setIsPending(true);
try {
await disconnectAccount(accountId);
router.refresh();
} catch (error) {
console.error("Failed to disconnect:", error);
alert("Failed to disconnect account. Please try again.");
} finally {
setIsPending(false);
}
};
return (
<button
onClick={handleDisconnect}
disabled={isPending}
className="group flex items-center justify-center p-2 rounded-lg text-gray-400 hover:text-red-500 hover:bg-red-50 dark:hover:bg-red-900/20 transition-all disabled:opacity-50 disabled:cursor-not-allowed"
title="Disconnect Account"
>
{isPending ? (
<Loader2 size={18} className="animate-spin" />
) : (
<Trash2 size={18} />
)}
</button>
);
}