import useSettingsStore from '../../../store/settings.jsx'; import React, { useEffect, useState } from 'react'; import { getChangedSettings, parseSettings, saveChangedSettings, } from '../../../utils/pages/SettingsUtils.js'; import { Alert, Button, Divider, Flex, Group, NumberInput, Select, Stack, Switch, Text, } from '@mantine/core'; import ConnectionSecurityPanel from './ConnectionSecurityPanel.jsx'; import { useForm } from '@mantine/form'; import { getSystemSettingsFormInitialValues } from '../../../utils/forms/settings/SystemSettingsFormUtils.js'; import { REGION_CHOICES } from '../../../constants.js'; const SystemSettingsForm = React.memo(({ active }) => { const settings = useSettingsStore((s) => s.settings); const isModular = useSettingsStore((s) => s.environment.env_mode) === 'modular'; const ipLookupEnvDisabled = useSettingsStore( (s) => s.environment.ip_lookup_env_disabled ); const [saved, setSaved] = useState(false); const form = useForm({ mode: 'controlled', initialValues: getSystemSettingsFormInitialValues(), }); useEffect(() => { if (!active) setSaved(false); }, [active]); useEffect(() => { if (settings) { const formValues = parseSettings(settings); form.setValues(formValues); } }, [settings]); const onSubmit = async () => { setSaved(false); const changedSettings = getChangedSettings(form.getValues(), settings); // Update each changed setting in the backend (create if missing) try { await saveChangedSettings(settings, changedSettings); setSaved(true); } catch (error) { // Error notifications are already shown by API functions // Just don't show the success message console.error('Error saving settings:', error); } }; return ( {saved && ( )} { form.setFieldValue('max_system_events', value); }} min={10} max={1000} step={10} />