diff --git a/typescript/frontend-marios2/src/content/dashboards/SodiohomeInstallations/SodistoreHomeConfiguration.tsx b/typescript/frontend-marios2/src/content/dashboards/SodiohomeInstallations/SodistoreHomeConfiguration.tsx index 183a1e8d9..b3ecc7e5d 100644 --- a/typescript/frontend-marios2/src/content/dashboards/SodiohomeInstallations/SodistoreHomeConfiguration.tsx +++ b/typescript/frontend-marios2/src/content/dashboards/SodiohomeInstallations/SodistoreHomeConfiguration.tsx @@ -152,67 +152,33 @@ function SodistoreHomeConfiguration(props: SodistoreHomeConfigurationProps) { const handleChange = (e) => { const { name, value } = e.target; - switch (name) { - // case 'minimumSoC': - // if ( - // /[^0-9.]/.test(value) || - // isNaN(parseFloat(value)) || - // parseFloat(value) > 30 || - // parseFloat(value) < 10 - // ) { - // SetErrorForField(name, true); - // } else { - // SetErrorForField(name, false); - // } - // break; - case 'minimumSoC': { - const numValue = parseFloat(value); + if (name === 'minimumSoC') { + const numValue = parseFloat(value); - // Check for invalid characters or non-numeric - if (/[^0-9.]/.test(value) || isNaN(numValue)) { - SetErrorForField(name, { - hasError: true, - message: 'Invalid number format', - }); - break; - } - - // Define device-based ranges + // invalid characters or not a number + if (/[^0-9.]/.test(value) || isNaN(numValue)) { + SetErrorForField(name, 'Invalid number format'); + } else { const minsocRanges = { 3: { min: 10, max: 30 }, 4: { min: 5, max: 100 }, }; - // Fallback range if device not listed const { min, max } = minsocRanges[device] || { min: 10, max: 30 }; if (numValue < min || numValue > max) { - SetErrorForField(name, { - hasError: true, - message: `Value should be between ${min}-${max}%`, - }); + SetErrorForField(name, `Value should be between ${min}-${max}%`); } else { - SetErrorForField(name, { hasError: false, message: '' }); + // ✅ valid → clear error + SetErrorForField(name, ''); } - break; } - - case 'gridSetPoint': - if (/[^0-9.]/.test(value) || isNaN(parseFloat(value))) { - SetErrorForField(name, true); - } else { - SetErrorForField(name, false); - } - break; - - default: - break; } - setFormValues({ - ...formValues, - [name]: value - }); + setFormValues(prev => ({ + ...prev, + [name]: value, + })); }; const handleTimeChargeDischargeChange = (name: string, value: any) => { @@ -367,27 +333,37 @@ function SodistoreHomeConfiguration(props: SodistoreHomeConfigurationProps) {
+ {/**/} + {/* }*/} + {/* name="minimumSoC"*/} + {/* value={formValues.minimumSoC}*/} + {/* onChange={handleChange}*/} + {/* helperText={*/} + {/* errors.minimumSoC ? (*/} + {/* */} + {/* Value should be between {device === 4 ? '5–100' : '10–30'}%*/} + {/* */} + {/* ) : (*/} + {/* ''*/} + {/* )*/} + {/* }*/} + {/* fullWidth*/} + {/*/>*/} - } + label="Minimum SoC (%)" name="minimumSoC" value={formValues.minimumSoC} onChange={handleChange} - helperText={ - errors.minimumSoC ? ( - - Value should be between {device === 4 ? '5–100' : '10–30'}% - - ) : ( - '' - ) - } + error={Boolean(errors.minimumSoC)} + helperText={errors.minimumSoC} fullWidth /> +