diff --git a/src/pages/Connectivity.jsx b/src/pages/Connectivity.jsx index 65d912d..976f54d 100755 --- a/src/pages/Connectivity.jsx +++ b/src/pages/Connectivity.jsx @@ -11,7 +11,7 @@ const Connectivity = () => { const [mqttConfig, setMqttConfig] = useState({ enabled: false, host: '', - port: 1883, + port: 1883, // Inicialmente trata-se como número username: '', password: '', topic: '', @@ -21,7 +21,6 @@ const Connectivity = () => { // Carregar as configurações Wi-Fi e MQTT useEffect(() => { const load = async () => { - try { const wifi = await get('/api/v1/config/wifi'); setWifiConfig(wifi); // Atualiza as configurações Wi-Fi @@ -55,7 +54,12 @@ const Connectivity = () => { // Salvar configuração MQTT const saveMqtt = async () => { try { - await post('/api/v1/config/mqtt', mqttConfig); // Envia as configurações de MQTT para o servidor + // Garante que o valor de port seja sempre um número válido + const updatedMqttConfig = { + ...mqttConfig, + port: parseInt(mqttConfig.port, 10) || 1883, // Caso o valor seja inválido, define como 1883 + }; + await post('/api/v1/config/mqtt', updatedMqttConfig); // Envia as configurações de MQTT para o servidor setMqttMsg('Configuração MQTT gravada!'); } catch (error) { setMqttMsg('Erro ao gravar MQTT.'); @@ -67,20 +71,18 @@ const Connectivity = () => { {loading ? (

A carregar...

) : ( - - + <> + {/* Configuração Wi-Fi */}

Configuração Wi-Fi

{wifiMsg &&
{wifiMsg}
}
{ e.preventDefault(); saveWifi(); }}> - - -
+
@@ -90,9 +92,10 @@ const Connectivity = () => { setWifiConfig({ ...wifiConfig, ssid: e.target.value })} + disabled={!wifiConfig.enabled} />
@@ -101,17 +104,24 @@ const Connectivity = () => { setWifiConfig({ ...wifiConfig, password: e.target.value })} + disabled={!wifiConfig.enabled} />
- +
+ {/* Configuração MQTT */}

Configuração MQTT

{mqttMsg &&
{mqttMsg}
}
{ e.preventDefault(); saveMqtt(); }}> @@ -131,9 +141,10 @@ const Connectivity = () => { setMqttConfig({ ...mqttConfig, host: e.target.value })} + disabled={!mqttConfig.enabled} /> @@ -142,9 +153,10 @@ const Connectivity = () => { setMqttConfig({ ...mqttConfig, port: parseInt(e.target.value || 0) })} + onChange={e => setMqttConfig({ ...mqttConfig, port: parseInt(e.target.value || 0, 10) || 1883 })} + disabled={!mqttConfig.enabled} /> @@ -153,9 +165,10 @@ const Connectivity = () => { setMqttConfig({ ...mqttConfig, username: e.target.value })} + disabled={!mqttConfig.enabled} /> @@ -164,9 +177,10 @@ const Connectivity = () => { setMqttConfig({ ...mqttConfig, password: e.target.value })} + disabled={!mqttConfig.enabled} /> @@ -175,14 +189,20 @@ const Connectivity = () => { setMqttConfig({ ...mqttConfig, topic: e.target.value })} + disabled={!mqttConfig.enabled} />
- +
diff --git a/src/pages/ElectricalNetwork.jsx b/src/pages/ElectricalNetwork.jsx index 059592c..5a511ec 100755 --- a/src/pages/ElectricalNetwork.jsx +++ b/src/pages/ElectricalNetwork.jsx @@ -47,6 +47,21 @@ export default function ElectricalNetwork() { } }; + // Função para lidar com as alterações de valores numéricos + const handleLoadBalancingCurrentLimitChange = (e) => { + setLoadBalancing({ + ...loadBalancing, + currentLimit: parseInt(e.target.value, 10) || 0 // Converte para número + }); + }; + + const handleSolarCapacityChange = (e) => { + setSolar({ + ...solar, + capacity: parseFloat(e.target.value) || 0 // Converte para número + }); + }; + return ( {msg &&
{msg}
} @@ -140,7 +155,7 @@ export default function ElectricalNetwork() { type="number" className="border border-gray-300 rounded px-3 py-2 w-full" value={loadBalancing.currentLimit} - onChange={e => setLoadBalancing({ ...loadBalancing, currentLimit: e.target.value })} + onChange={handleLoadBalancingCurrentLimitChange} // Aplicando a conversão para número /> @@ -152,7 +167,7 @@ export default function ElectricalNetwork() { type="number" className="border border-gray-300 rounded px-3 py-2 w-full" value={solar.capacity} - onChange={e => setSolar({ ...solar, capacity: e.target.value })} + onChange={handleSolarCapacityChange} // Aplicando a conversão para número />
diff --git a/src/pages/LoadBalancing.jsx b/src/pages/LoadBalancing.jsx index 01460c1..765b4c3 100755 --- a/src/pages/LoadBalancing.jsx +++ b/src/pages/LoadBalancing.jsx @@ -1,5 +1,3 @@ -// src/pages/LoadBalancing.js - import { useState, useEffect } from 'react'; import { get, post } from '../api'; import PageLayout from '../components/PageLayout'; @@ -66,6 +64,11 @@ export default function LoadBalancing() { } }; + // Função para lidar com a mudança na corrente máxima + const handleMaxChargingCurrentChange = (e) => { + setMaxChargingCurrent(parseInt(e.target.value, 10)); // Garantir que o valor seja um número + }; + return ( {msg &&
{msg}
} @@ -96,7 +99,7 @@ export default function LoadBalancing() { min="1" max="32" className="border border-gray-300 rounded px-3 py-2 w-full" - onChange={(e) => setMaxChargingCurrent(e.target.value)} + onChange={handleMaxChargingCurrentChange} // Alterado para usar a função que converte o valor />
@@ -124,4 +127,4 @@ export default function LoadBalancing() {
); -} \ No newline at end of file +} diff --git a/src/pages/OCPP.jsx b/src/pages/OCPP.jsx index 300f754..d9d04c2 100755 --- a/src/pages/OCPP.jsx +++ b/src/pages/OCPP.jsx @@ -8,6 +8,7 @@ const OCPP = () => { const [loading, setLoading] = useState(true); const [config, setConfig] = useState({ + enabled: false, url: '', chargeBoxId: '', certificate: '', @@ -48,61 +49,74 @@ const OCPP = () => {

A carregar...

) : ( <> - {status && ( -
-

Versão: {status.ocpp_version}

-

Status: {status.status}

-
- )} - {msg &&
{msg}
} + +
{ e.preventDefault(); save(); }}> -
- - setConfig({ ...config, url: e.target.value })} - /> -
+
+ +
-
- - setConfig({ ...config, chargeBoxId: e.target.value })} - /> -
+
+ + setConfig({ ...config, url: e.target.value })} + disabled={!config.enabled} // Desabilita o campo se o checkbox estiver desmarcado + /> +
+ +
+ + setConfig({ ...config, chargeBoxId: e.target.value })} + disabled={!config.enabled} // Desabilita o campo se o checkbox estiver desmarcado + /> +
+ +
+ +