import React, { useEffect, useState } from 'react'; import { Button } from '@/components/elements/button/index'; import Can from '@/components/elements/Can'; import { ServerContext } from '@/state/server'; import { PowerAction } from '@/components/server/console/ServerConsoleContainer'; import { Dialog } from '@/components/elements/dialog'; import AdditionalPowerButtons from '@/blueprint/components/Server/Terminal/AdditionalPowerButtons'; interface PowerButtonProps { className?: string; } export default ({ className }: PowerButtonProps) => { const [open, setOpen] = useState(false); const status = ServerContext.useStoreState((state) => state.status.value); const instance = ServerContext.useStoreState((state) => state.socket.instance); const killable = status === 'stopping'; const onButtonClick = ( action: PowerAction | 'kill-confirmed', e: React.MouseEvent ): void => { e.preventDefault(); if (action === 'kill') { return setOpen(true); } if (instance) { setOpen(false); instance.send('set state', action === 'kill-confirmed' ? 'kill' : action); } }; useEffect(() => { if (status === 'offline') { setOpen(false); } }, [status]); return (
setOpen(false)} title={'Forcibly Stop Process'} confirm={'Continue'} onConfirmed={onButtonClick.bind(this, 'kill-confirmed')} > Forcibly stopping a server can lead to data corruption. Restart {killable ? 'Kill' : 'Stop'}
); };