import { Formik, Field, Form } from "formik"; import FormGroup from "../components/FormGroup"; import { useReboots } from "../../../hooks/useReboots"; import { timezones } from "./timezones"; import SystemFileUpload from "./SystemFileUpload"; import type { SystemValues, SystemValuesErrors } from "../../../types/types"; import { useDNSSettings, useSystemConfig } from "../../../hooks/useSystemConfig"; const SystemConfigFields = () => { const { saveSystemSettings, systemSettingsData, saveSystemSettingsLoading } = useSystemConfig(); const { hardRebootMutation } = useReboots(); const { dnsQuery, dnsMutation } = useDNSSettings(); const dnsPrimary = dnsQuery?.data?.propNameServerPrimary?.value; const dnsSecondary = dnsQuery?.data?.propNameServerSecondary?.value; const initialvalues: SystemValues = { deviceName: systemSettingsData?.deviceName ?? "", timeZone: systemSettingsData?.timeZone ?? "", sntpServer: systemSettingsData?.sntpServer ?? "", sntpInterval: systemSettingsData?.sntpInterval ?? 60, serverPrimary: dnsPrimary ?? "", serverSecondary: dnsSecondary ?? "", softwareUpdate: null, }; const handleSubmit = async (values: SystemValues) => { saveSystemSettings(values); await dnsMutation.mutateAsync(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; }; // const handleSoftReboot = async () => { // await softRebootMutation.mutate(); // }; const handleHardReboot = async () => { await hardRebootMutation.mutate(); }; return ( {({ values, errors, touched, isSubmitting }) => (
{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} )}

Reboot

{/* */} )}
); }; export default SystemConfigFields;