/* * Copyright (C) 2019-2024 CZ.NIC z.s.p.o. (https://www.nic.cz/) * * This is free software, licensed under the GNU General Public License v3. * See /LICENSE for more information. */ import React, { useState, useEffect } from "react"; import PropTypes from "prop-types"; import { useAPIPost } from "../api/hooks"; import { API_STATE } from "../api/utils"; import Button from "../bootstrap/Button"; import { Modal, ModalHeader, ModalBody, ModalFooter } from "../bootstrap/Modal"; import { useAlert } from "../context/alertContext/AlertContext"; import { ForisURLs } from "../utils/forisUrls"; RebootButton.propTypes = { /** Additional props to be passed to the button */ props: PropTypes.object, }; function RebootButton(props) { const [triggered, setTriggered] = useState(false); const [modalShown, setModalShown] = useState(false); const [triggerRebootStatus, triggerReboot] = useAPIPost(ForisURLs.reboot); const [setAlert] = useAlert(); useEffect(() => { if (triggerRebootStatus.state === API_STATE.ERROR) { setAlert(_("Reboot request failed.")); } }); const rebootHandler = () => { setTriggered(true); triggerReboot(); setModalShown(false); }; return ( <> setModalShown(true)} {...props} > {_("Reboot")} > ); } RebootModal.propTypes = { shown: PropTypes.bool.isRequired, setShown: PropTypes.func.isRequired, onReboot: PropTypes.func.isRequired, }; function RebootModal({ shown, setShown, onReboot }) { return ( {_("Are you sure you want to restart the router?")} setShown(false)} > {_("Cancel")} {_("Confirm reboot")} ); } export default RebootButton;
{_("Are you sure you want to restart the router?")}