'use client' import { useState } from 'react' import { useRouter } from 'next/navigation' import { Button } from '@/components/ui/button' import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuSeparator, DropdownMenuTrigger, } from '@/components/ui/dropdown-menu' import { AlertDialog, AlertDialogAction, AlertDialogCancel, AlertDialogContent, AlertDialogDescription, AlertDialogFooter, AlertDialogHeader, AlertDialogTitle, } from '@/components/ui/alert-dialog' import { MoreHorizontal, Trash2, RefreshCw, Copy } from 'lucide-react' interface Machine { id: string name: string hostname: string | null os: string | null osVersion: string | null isOnline: boolean accessKey: string lastSeen: Date | null } interface MachineActionsProps { machine: Machine } export function MachineActions({ machine }: MachineActionsProps) { const [showDeleteDialog, setShowDeleteDialog] = useState(false) const [isDeleting, setIsDeleting] = useState(false) const router = useRouter() const handleDelete = async () => { setIsDeleting(true) const res = await fetch(`/api/machines/${machine.id}`, { method: 'DELETE' }) if (res.ok) router.refresh() setIsDeleting(false) setShowDeleteDialog(false) } const copyAccessKey = () => navigator.clipboard.writeText(machine.accessKey) return ( <> Copy Access Key router.refresh()}> Refresh Status setShowDeleteDialog(true)} className="text-destructive focus:text-destructive" > Delete Machine Delete machine? This will remove {`"${machine.name}"`} from your account. The agent on the remote machine will need to be re-registered. Cancel {isDeleting ? 'Deleting...' : 'Delete'} ) }