import { Formik, Field, Form } from "formik"; import FormGroup from "../components/FormGroup"; import { handleSoftReboot, handleHardReboot } from "./Reboots"; import { timezones } from "./timezones"; import SystemFileUpload from "./SystemFileUpload"; import type { SystemValues, SystemValuesErrors } from "../../../types/types"; import { useSystemConfig } from "../../../hooks/useSystemConfig"; const SystemConfigFields = () => { const { saveSystemSettings, systemSettingsData } = useSystemConfig(); const initialvalues: SystemValues = { deviceName: systemSettingsData?.deviceName ?? "", timeZone: systemSettingsData?.timeZone ?? "", sntpServer: systemSettingsData?.sntpServer ?? "", sntpInterval: systemSettingsData?.sntpInterval ?? 60, softwareUpdate: null, }; const handleSubmit = (values: SystemValues) => saveSystemSettings(values); const validateValues = (values: SystemValues) => { const errors: SystemValuesErrors = {}; const interval = Number(values.sntpInterval); if (!values.deviceName) errors.deviceName = "Required"; if (!values.timeZone) errors.timeZone = "Required"; if (isNaN(interval) || interval <= 0) errors.sntpInterval = "Cannot be less than 0"; if (!values.sntpServer) errors.sntpServer = "Required"; return errors; }; return ( {({ values, errors, touched }) => (
{touched.deviceName && errors.deviceName && ( {errors.deviceName} )} {touched.timeZone && errors.timeZone && ( {errors.timeZone} )} {timezones.map((timezone) => ( ))} {touched.sntpServer && errors.sntpServer && ( {errors.sntpServer} )} {touched.sntpInterval && errors.sntpInterval && ( {errors.sntpInterval} )} )}
); }; export default SystemConfigFields;