import React, { useState, useEffect } from "react"; import ReactModal from "react-modal"; function SettingModal({ showModal, onClose }) { const [name, setName] = useState("CPLV4"); const [mac1, setMac1] = useState("0 48 86 81 46 157"); const [mac2, setMac2] = useState("0 48 86 81 46 158"); const [ip, setIp] = useState("10.10.0.118"); const [subnet, setSubnet] = useState("255.255.255.0"); const [gateway, setGateway] = useState("10.10.0.1"); const [systemUhr, setSystemUhr] = useState("16.10.24 15:27:23 Uhr"); const [ntp1, setNtp1] = useState("192.53.103.108"); const [ntp2, setNtp2] = useState("0.0.0.0"); const [ntp3, setNtp3] = useState("0.0.0.0"); const [zeitzone, setZeitzone] = useState("2"); const [activ, setActiv] = useState("1"); // UseEffect to get initial values from window object useEffect(() => { if (window.deviceName) setName(window.deviceName); if (window.mac1) setMac1(window.mac1); if (window.mac2) setMac2(window.mac2); if (window.ip) setIp(window.ip); if (window.subnet) setSubnet(window.subnet); if (window.gateway) setGateway(window.gateway); if (window.datetime) setSystemUhr(window.datetime); if (window.ntpServer1Ip) setNtp1(window.ntpServer1Ip); if (window.ntpServer2Ip) setNtp2(window.ntpServer2Ip); if (window.ntpServer3Ip) setNtp3(window.ntpServer3Ip); if (window.ntpTimezone) setZeitzone(window.ntpTimezone); if (window.ntpActive) setActiv(window.ntpActive); }, []); const handleSubmit = () => { const url = `CPL?SNNA=${name}&SEI01=${ip}&SEI02=${subnet}&SEI03=${gateway}&SNIP1=${ntp1}&SNIP2=${ntp2}&SNIP3=${ntp3}&SNTZ=${zeitzone}&SNAC=${activ}`; // Send data to the server fetch(url) .then((response) => { if (response.ok) { alert("Daten erfolgreich gesendet!"); } else { alert("Fehler beim Senden der Daten!"); } }) .catch((error) => { console.error("Fehler:", error); alert("Fehler beim Senden der Daten!"); }); }; return (

System:

setName(e.target.value)} // Update state on change />
setMac1(e.target.value)} // Update state on change />
setMac2(e.target.value)} // Update state on change />
setIp(e.target.value)} // Update state on change />
setSubnet(e.target.value)} // Update state on change />
setGateway(e.target.value)} // Update state on change />
{/* SNTP Client */}

SNTP Client:

setNtp1(e.target.value)} // Update state on change />
setNtp2(e.target.value)} // Update state on change />
setNtp3(e.target.value)} // Update state on change />
setZeitzone(e.target.value)} // Update state on change />
setActiv(e.target.value)} // Update state on change />
{/* Datenbank leeren und Neustart CPL */}
{/* Modal Footer */}
); } export default SettingModal;