"use client"; import { Check, Copy, KeyRound, MessageCircle, Unplug, Volume2, VolumeX, } from "lucide-react"; import { useState } from "react"; import { setTradeLock } from "@/actions/bulk-users"; import { alertUser, disconnectUser, muteUser, resetPassword, sendCredits, unmuteUser, } from "@/actions/users"; import { useConfirmDialog } from "@/components/admin/confirm-dialog"; import { CurrencyIcon } from "@/components/shared/currency-icon"; import { Badge } from "@/components/ui/badge"; import { Button } from "@/components/ui/button"; import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card"; import { Dialog, DialogContent, DialogDescription, DialogHeader, DialogTitle, } from "@/components/ui/dialog"; import { Input } from "@/components/ui/input"; import { Label } from "@/components/ui/label"; import { useServerAction } from "@/hooks/use-server-action"; import { formatNumber } from "@/lib/format-date"; interface UserQuickActionsProps { userId: number; username: string; isOnline: boolean; } export function UserQuickActions({ userId, username, isOnline, }: UserQuickActionsProps) { const { run, isPending } = useServerAction(); const { confirm, dialog: confirmDialog } = useConfirmDialog(); // Reset password state const [newPassword, setNewPassword] = useState(null); const [copied, setCopied] = useState(false); // Alert state const [alertMessage, setAlertMessage] = useState(""); // Mute state const [muteDuration, setMuteDuration] = useState("10"); // Credits state const [creditAmount, setCreditAmount] = useState("1000"); async function handleResetPassword() { const ok = await confirm({ title: "Reset password", description: `Reset password for ${username}? A new random password will be generated.`, confirmLabel: "Reset", variant: "danger", }); if (!ok) return; run(() => resetPassword({ userId }), { successMessage: "Password reset successfully.", onSuccess: (data) => { setNewPassword(data.newPassword as string); }, }); } function handleDisconnect() { run(() => disconnectUser({ userId }), { successMessage: `${username} disconnected.`, }); } function handleAlert() { if (!alertMessage.trim()) return; run(() => alertUser({ userId, message: alertMessage.trim() }), { successMessage: "Alert sent.", onSuccess: () => setAlertMessage(""), }); } function handleMute() { const duration = Number(muteDuration); if (Number.isNaN(duration) || duration < 0) return; run(() => muteUser({ userId, duration }), { successMessage: `${username} muted.`, }); } function handleUnmute() { run(() => unmuteUser({ userId }), { successMessage: `${username} unmuted.`, }); } function handleSendCredits() { const amount = parseInt(creditAmount, 10); if (!amount || amount <= 0) return; run(() => sendCredits({ userId, amount }), { successMessage: `${formatNumber(amount)} credits sent to ${username}.`, }); } function copyPassword() { if (newPassword) { navigator.clipboard.writeText(newPassword); setCopied(true); setTimeout(() => setCopied(false), 2000); } } return ( <> {confirmDialog} Quick Actions {/* Row 1: Password + Disconnect */}
{/* Send Alert */}
setAlertMessage(e.target.value)} onKeyDown={(e) => e.key === "Enter" && handleAlert()} className="flex-1" />
{/* Mute */}
setMuteDuration(e.target.value)} className="w-32" />
{/* Send Credits */}
setCreditAmount(e.target.value)} className="w-32" min={1} />
{/* Trade lock (DB only — no RCON helper) */}
{/* Password Reset Dialog */} setNewPassword(null)}> Password Reset New password generated for {username}. Copy it now — it won't be shown again.
{newPassword}
); }