diff --git a/src/common/RebootButton.js b/src/common/RebootButton.js new file mode 100644 index 0000000..3b6c256 --- /dev/null +++ b/src/common/RebootButton.js @@ -0,0 +1,77 @@ +/* + * Copyright (C) 2019 CZ.NIC z.s.p.o. (http://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 { ForisURLs } from "forisUrls"; + +import { Button } from "bootstrap/Button"; +import { + Modal, ModalHeader, ModalBody, ModalFooter, +} from "bootstrap/Modal"; +import { useAlert } from "alertContext/AlertContext"; + +RebootButton.propTypes = { + forisFormSize: PropTypes.bool, +}; + +export 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.")); + } + }); + + function rebootHandler() { + setTriggered(true); + triggerReboot(); + setModalShown(false); + } + + return ( + <> + + + + ); +} + +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?")}

+ + + + +
+ ); +} diff --git a/src/common/__tests__/RebootButton.test.js b/src/common/__tests__/RebootButton.test.js new file mode 100644 index 0000000..3eb205e --- /dev/null +++ b/src/common/__tests__/RebootButton.test.js @@ -0,0 +1,55 @@ +/* + * Copyright (C) 2019 CZ.NIC z.s.p.o. (http://www.nic.cz/) + * + * This is free software, licensed under the GNU General Public License v3. + * See /LICENSE for more information. + */ + +import React from "react"; + +import { fireEvent, getByText, queryByText, render, wait } from "customTestRender"; +import mockAxios from "jest-mock-axios"; +import { mockJSONError } from "testUtils/network"; +import { mockSetAlert } from "testUtils/alertContextMock"; + +import { RebootButton } from "../RebootButton"; + +describe("", () => { + let componentContainer; + beforeEach(() => { + const { container } = render(<> +