import React from "react"; import { useEffect } from "react" import Card from "../../UI/Card"; import CardHeader from "../../UI/CardHeader"; import FormGroup from "../components/FormGroup"; import { sendBlobFileUpload } from "./Upload"; import { handleSoftReboot, handleHardReboot } from "./Reboots.tsx"; import { handleSystemRecall, handleSystemSave } from "./SettingSaveRecall.tsx"; const SystemCard = () => { const [deviceName, setDeviceName] = React.useState(""); const [timeZone, setTimeZone] = React.useState("Europe/London (UTC+00:00"); const [sntpServer, setSntpServer] = React.useState("1.uk.pool.ntp.org"); const [sntpInterval, setSntpInterval] = React.useState(60); const [selectedFile, setSelectedFile] = React.useState(null); const [error, setError] = React.useState(""); useEffect(() => { (async () => { const result = await handleSystemRecall(); // returns { deviceName, sntpServer, sntpInterval, timeZone } | null if (result) { const { deviceName: dn, sntpServer: ss, sntpInterval: si, timeZone: tz } = result; setDeviceName(dn ?? ""); setSntpServer(ss ?? ""); setSntpInterval(Number.isFinite(si) ? si : 60); setTimeZone(tz ?? "UTC (UTC-00)"); } })(); }, []); const handleFileChange = (e: React.ChangeEvent) => { const file = e.target.files?.[0] ?? null; setSelectedFile(file); if (!file) { setError("No file selected."); return; } if (file.size > 8 * 1024 * 1024) { setError("File is too large (max 8MB)."); setSelectedFile(null); return }; setError(""); } const handleSubmit = async (e: React.FormEvent) => { e.preventDefault(); // prevent full page reload if (!selectedFile) { setError("Please select a file before uploading."); return; } setError(""); const result = await sendBlobFileUpload( selectedFile, { timeoutMs: 30000, fieldName: "upload", }); // The helper returns a string (either success body or formatted error) // You can decide how to distinguish. Here, we show it optimistically and let the text speak. if (result.startsWith("Server returned") || result.startsWith("Timeout") || result.startsWith("HTTP error") || result.startsWith("Unexpected error")) { setError(result); } }; return (
setDeviceName(e.target.value)} />
setSntpServer(e.target.value)} />
setSntpInterval(Number(e.target.value))} />
{error &&

{error}

}
); }; export default SystemCard;