|
| 1 | +import { useNavigate } from "react-router-dom"; |
| 2 | +import { useCallback } from "react"; |
| 3 | + |
| 4 | +import { useJsonRpc } from "@/hooks/useJsonRpc"; |
| 5 | +import { Button } from "@components/Button"; |
| 6 | + |
| 7 | +export default function SettingsGeneralRebootRoute() { |
| 8 | + const navigate = useNavigate(); |
| 9 | + const [send] = useJsonRpc(); |
| 10 | + |
| 11 | + const onConfirmUpdate = useCallback(() => { |
| 12 | + // This is where we send the RPC to the golang binary |
| 13 | + send("reboot", {force: true}); |
| 14 | + }, [send]); |
| 15 | + |
| 16 | + { |
| 17 | + /* TODO: Migrate to using URLs instead of the global state. To simplify the refactoring, we'll keep the global state for now. */ |
| 18 | + } |
| 19 | + return <Dialog onClose={() => navigate("..")} onConfirmUpdate={onConfirmUpdate} />; |
| 20 | +} |
| 21 | + |
| 22 | +export function Dialog({ |
| 23 | + onClose, |
| 24 | + onConfirmUpdate, |
| 25 | +}: { |
| 26 | + onClose: () => void; |
| 27 | + onConfirmUpdate: () => void; |
| 28 | +}) { |
| 29 | + |
| 30 | + return ( |
| 31 | + <div className="pointer-events-auto relative mx-auto text-left"> |
| 32 | + <div> |
| 33 | + <ConfirmationBox |
| 34 | + onYes={onConfirmUpdate} |
| 35 | + onNo={onClose} |
| 36 | + /> |
| 37 | + </div> |
| 38 | + </div> |
| 39 | + ); |
| 40 | +} |
| 41 | + |
| 42 | +function ConfirmationBox({ |
| 43 | + onYes, |
| 44 | + onNo, |
| 45 | +}: { |
| 46 | + onYes: () => void; |
| 47 | + onNo: () => void; |
| 48 | +}) { |
| 49 | + return ( |
| 50 | + <div className="flex flex-col items-start justify-start space-y-4 text-left"> |
| 51 | + <div className="text-left"> |
| 52 | + <p className="text-base font-semibold text-black dark:text-white"> |
| 53 | + Reboot JetKVM |
| 54 | + </p> |
| 55 | + <p className="text-sm text-slate-600 dark:text-slate-300"> |
| 56 | + Do you want to proceed with rebooting the system? |
| 57 | + </p> |
| 58 | + |
| 59 | + <div className="mt-4 flex gap-x-2"> |
| 60 | + <Button size="SM" theme="light" text="Yes" onClick={onYes} /> |
| 61 | + <Button size="SM" theme="blank" text="No" onClick={onNo} /> |
| 62 | + </div> |
| 63 | + </div> |
| 64 | + </div> |
| 65 | + ); |
| 66 | +} |
0 commit comments