refactor: disable shutdown

This commit is contained in:
Carlos Valente
2024-12-13 09:50:32 +01:00
committed by Carlos Valente
parent 5032cbf65a
commit b64b154330
@@ -11,7 +11,7 @@ import {
} from '@chakra-ui/react'; } from '@chakra-ui/react';
import { useElectronEvent } from '../../../../common/hooks/useElectronEvent'; import { useElectronEvent } from '../../../../common/hooks/useElectronEvent';
import { isLocalhost } from '../../../../externals'; import { isLocalhost, isOntimeCloud } from '../../../../externals';
import * as Panel from '../../panel-utils/PanelUtils'; import * as Panel from '../../panel-utils/PanelUtils';
export default function ShutdownPanel() { export default function ShutdownPanel() {
@@ -24,18 +24,28 @@ export default function ShutdownPanel() {
onClose(); onClose();
}; };
const canShutdown = isElectron || isLocalhost;
return ( return (
<> <>
<Panel.Header>Shutdown Ontime</Panel.Header> <Panel.Header>Shutdown Ontime</Panel.Header>
<Panel.Section> <Panel.Section>
<Panel.Paragraph> {isOntimeCloud ? (
This will shutdown the Ontime server. <br /> <Panel.Highlight>
The runtime state will be lost, but your project is kept for next time. For security reasons, shutting down the server must be done from the Ontime Cloud dashboard.
</Panel.Paragraph> </Panel.Highlight>
) : (
<Panel.Paragraph>
This will shutdown the Ontime server. <br />
The runtime state will be lost, but your project is kept for next time.
</Panel.Paragraph>
)}
<Button colorScheme='red' onClick={onOpen} maxWidth='350px' isDisabled={!(isElectron || isLocalhost)}> <Button colorScheme='red' onClick={onOpen} maxWidth='350px' isDisabled={!(isElectron || isLocalhost)}>
Shutdown ontime Shutdown ontime
</Button> </Button>
<Panel.Description>Note: Ontime can only be shutdown from the machine it is running in.</Panel.Description> {!canShutdown && (
<Panel.Description>Note: Ontime can only be shutdown from the machine it is running in.</Panel.Description>
)}
<AlertDialog variant='ontime' isOpen={isOpen} leastDestructiveRef={cancelRef} onClose={onClose}> <AlertDialog variant='ontime' isOpen={isOpen} leastDestructiveRef={cancelRef} onClose={onClose}>
<AlertDialogOverlay> <AlertDialogOverlay>
<AlertDialogContent> <AlertDialogContent>
@@ -49,7 +59,7 @@ export default function ShutdownPanel() {
<Button ref={cancelRef} onClick={onClose} variant='ontime-ghosted-white'> <Button ref={cancelRef} onClick={onClose} variant='ontime-ghosted-white'>
Cancel Cancel
</Button> </Button>
<Button colorScheme='red' onClick={sendShutdown} ml={4}> <Button colorScheme='red' onClick={sendShutdown} disabled={!canShutdown}>
Shutdown Shutdown
</Button> </Button>
</AlertDialogFooter> </AlertDialogFooter>