forked from pterodactyl/panel
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPowerButtons.tsx
More file actions
73 lines (68 loc) · 2.66 KB
/
Copy pathPowerButtons.tsx
File metadata and controls
73 lines (68 loc) · 2.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import React, { 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';
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<HTMLButtonElement, MouseEvent>): void => {
e.preventDefault();
if (action === 'kill') {
return setOpen(true);
}
if (instance) {
setOpen(false);
instance.send('set state', action === 'kill-confirmed' ? 'kill' : action);
}
};
return (
<div className={className}>
<Dialog.Confirm
open={open}
hideCloseIcon
onClose={() => setOpen(false)}
title={'Forcibly Stop Process'}
confirm={'Continue'}
onConfirmed={onButtonClick.bind(this, 'kill-confirmed')}
>
Forcibly stopping a server can lead to data corruption.
</Dialog.Confirm>
<Can action={'control.start'}>
<Button
className={'w-full sm:w-24'}
disabled={status !== 'offline'}
onClick={onButtonClick.bind(this, 'start')}
>
Start
</Button>
</Can>
<Can action={'control.restart'}>
<Button.Text
className={'w-full sm:w-24'}
variant={Button.Variants.Secondary}
disabled={!status}
onClick={onButtonClick.bind(this, 'restart')}
>
Restart
</Button.Text>
</Can>
<Can action={'control.stop'}>
<Button.Danger
className={'w-full sm:w-24'}
variant={killable ? undefined : Button.Variants.Secondary}
disabled={status === 'offline'}
onClick={onButtonClick.bind(this, killable ? 'kill' : 'stop')}
>
{killable ? 'Kill' : 'Stop'}
</Button.Danger>
</Can>
</div>
);
};