import { useMutation, useQueryClient } from '@tanstack/react-query'; import { Play, Square, RotateCcw, Skull } from 'lucide-react'; import { api } from '@/lib/api'; import { Button } from '@/components/ui/button'; import { Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle, DialogTrigger, DialogClose, } from '@/components/ui/dialog'; interface PowerControlsProps { serverId: string; orgId: string; status: string; } type PowerAction = 'start' | 'stop' | 'restart' | 'kill'; interface CachedServerDetail { status: string; [key: string]: unknown; } export function PowerControls({ serverId, orgId, status }: PowerControlsProps) { const queryClient = useQueryClient(); const serverQueryKey = ['server', orgId, serverId] as const; const powerMutation = useMutation({ mutationFn: (action: PowerAction) => api.post(`/organizations/${orgId}/servers/${serverId}/power`, { action }), onMutate: (action) => { const nextStatusByAction: Record = { start: 'starting', stop: 'stopping', restart: 'stopping', kill: 'stopped', }; queryClient.setQueryData(serverQueryKey, (current) => { if (!current) return current; return { ...current, status: nextStatusByAction[action], }; }); }, onSettled: () => { queryClient.invalidateQueries({ queryKey: serverQueryKey }); queryClient.invalidateQueries({ queryKey: ['servers', orgId] }); }, }); const isRunning = status === 'running'; const isStopped = status === 'stopped' || status === 'error'; const isTransitioning = status === 'starting' || status === 'stopping' || status === 'installing'; return (
Kill Server This will forcefully terminate the server process. Any unsaved data may be lost.
); }