diff --git a/src/components/configuration/AssistRulesEditor.tsx b/src/components/configuration/AssistRulesEditor.tsx index f2c2445..a8359a9 100755 --- a/src/components/configuration/AssistRulesEditor.tsx +++ b/src/components/configuration/AssistRulesEditor.tsx @@ -6,7 +6,10 @@ import { updateAssistRulesAction } from '@/lib/actions/configuration'; interface AssistRulesEditorProps { serverId: string; - config: AssistRules; + formData: AssistRules; + restart: boolean; + onFormDataChange: (data: AssistRules) => void; + onRestartChange: (restart: boolean) => void; } const assistFields = [ @@ -57,9 +60,7 @@ const assistFields = [ } ]; -export function AssistRulesEditor({ serverId, config }: AssistRulesEditorProps) { - const [formData, setFormData] = useState(config); - const [restart, setRestart] = useState(true); +export function AssistRulesEditor({ serverId, formData, restart, onFormDataChange, onRestartChange }: AssistRulesEditorProps) { const [isSubmitting, setIsSubmitting] = useState(false); const handleSubmit = async (e: React.FormEvent) => { @@ -85,10 +86,10 @@ export function AssistRulesEditor({ serverId, config }: AssistRulesEditorProps) }; const handleInputChange = (key: keyof AssistRules, value: string | number) => { - setFormData((prev) => ({ - ...prev, + onFormDataChange({ + ...formData, [key]: typeof value === 'string' ? parseInt(value) : value - })); + }); }; return ( @@ -127,7 +128,7 @@ export function AssistRulesEditor({ serverId, config }: AssistRulesEditorProps) setRestart(e.target.checked)} + onChange={(e) => onRestartChange(e.target.checked)} className="h-4 w-4 rounded border-border bg-overlay accent-green focus:ring-1 focus:ring-blue" /> Restart server after saving diff --git a/src/components/configuration/ConfigurationEditor.tsx b/src/components/configuration/ConfigurationEditor.tsx index 522401e..7138184 100755 --- a/src/components/configuration/ConfigurationEditor.tsx +++ b/src/components/configuration/ConfigurationEditor.tsx @@ -6,12 +6,13 @@ import { updateConfigurationAction } from '@/lib/actions/configuration'; interface ConfigurationEditorProps { serverId: string; - config: Configuration; + formData: Configuration; + restart: boolean; + onFormDataChange: (data: Configuration) => void; + onRestartChange: (restart: boolean) => void; } -export function ConfigurationEditor({ serverId, config }: ConfigurationEditorProps) { - const [formData, setFormData] = useState(config); - const [restart, setRestart] = useState(true); +export function ConfigurationEditor({ serverId, formData, restart, onFormDataChange, onRestartChange }: ConfigurationEditorProps) { const [isSubmitting, setIsSubmitting] = useState(false); const handleSubmit = async (e: React.FormEvent) => { @@ -37,10 +38,10 @@ export function ConfigurationEditor({ serverId, config }: ConfigurationEditorPro }; const handleInputChange = (key: keyof Configuration, value: string | number) => { - setFormData((prev) => ({ - ...prev, + onFormDataChange({ + ...formData, [key]: typeof value === 'string' ? parseInt(value) : value - })); + }); }; return ( @@ -111,7 +112,7 @@ export function ConfigurationEditor({ serverId, config }: ConfigurationEditorPro setRestart(e.target.checked)} + onChange={(e) => onRestartChange(e.target.checked)} className="h-4 w-4 rounded border-border bg-overlay accent-green focus:ring-1 focus:ring-blue" /> Restart server after saving diff --git a/src/components/configuration/EventConfigEditor.tsx b/src/components/configuration/EventConfigEditor.tsx index 0c436c6..6c02ae0 100755 --- a/src/components/configuration/EventConfigEditor.tsx +++ b/src/components/configuration/EventConfigEditor.tsx @@ -6,7 +6,10 @@ import { updateEventConfigAction } from '@/lib/actions/configuration'; interface EventConfigEditorProps { serverId: string; - config: EventConfig; + formData: EventConfig; + restart: boolean; + onFormDataChange: (data: EventConfig) => void; + onRestartChange: (restart: boolean) => void; } const sessionTypes = [ @@ -15,9 +18,7 @@ const sessionTypes = [ { value: 'R', label: 'Race' } ]; -export function EventConfigEditor({ serverId, config }: EventConfigEditorProps) { - const [formData, setFormData] = useState(config); - const [restart, setRestart] = useState(true); +export function EventConfigEditor({ serverId, formData, restart, onFormDataChange, onRestartChange }: EventConfigEditorProps) { const [isSubmitting, setIsSubmitting] = useState(false); const handleSubmit = async (e: React.FormEvent) => { @@ -49,15 +50,15 @@ export function EventConfigEditor({ serverId, config }: EventConfigEditorProps) const handleInputChange = (key: keyof EventConfig, value: string | number) => { if (key === 'sessions') return; - setFormData((prev) => ({ - ...prev, + onFormDataChange({ + ...formData, [key]: typeof formData[key] === 'number' ? typeof value === 'string' ? parseFloat(value) || 0 : value : value - })); + }); }; const handleSessionChange = (index: number, field: keyof Session, value: string | number) => { @@ -67,11 +68,7 @@ export function EventConfigEditor({ serverId, config }: EventConfigEditorProps) [field]: field === 'sessionType' ? value : typeof value === 'string' ? parseFloat(value) || 0 : value }; - - setFormData((prev) => ({ - ...prev, - sessions: newSessions - })); + onFormDataChange({ ...formData, sessions: newSessions }); }; const addSession = () => { @@ -82,18 +79,11 @@ export function EventConfigEditor({ serverId, config }: EventConfigEditorProps) sessionType: 'P', sessionDurationMinutes: 20 }; - - setFormData((prev) => ({ - ...prev, - sessions: [...prev.sessions, newSession] - })); + onFormDataChange({ ...formData, sessions: [...formData.sessions, newSession] }); }; const removeSession = (index: number) => { - setFormData((prev) => ({ - ...prev, - sessions: prev.sessions.filter((_, i) => i !== index) - })); + onFormDataChange({ ...formData, sessions: formData.sessions.filter((_, i) => i !== index) }); }; return ( @@ -412,7 +402,7 @@ export function EventConfigEditor({ serverId, config }: EventConfigEditorProps) setRestart(e.target.checked)} + onChange={(e) => onRestartChange(e.target.checked)} className="h-4 w-4 rounded border-border bg-overlay accent-green focus:ring-1 focus:ring-blue" /> Restart server after saving diff --git a/src/components/configuration/EventRulesEditor.tsx b/src/components/configuration/EventRulesEditor.tsx index 264818d..4ead6f9 100755 --- a/src/components/configuration/EventRulesEditor.tsx +++ b/src/components/configuration/EventRulesEditor.tsx @@ -6,7 +6,10 @@ import { updateEventRulesAction } from '@/lib/actions/configuration'; interface EventRulesEditorProps { serverId: string; - config: EventRules; + formData: EventRules; + restart: boolean; + onFormDataChange: (data: EventRules) => void; + onRestartChange: (restart: boolean) => void; } const numberFields = [ @@ -68,9 +71,7 @@ const booleanFields = [ } ]; -export function EventRulesEditor({ serverId, config }: EventRulesEditorProps) { - const [formData, setFormData] = useState(config); - const [restart, setRestart] = useState(true); +export function EventRulesEditor({ serverId, formData, restart, onFormDataChange, onRestartChange }: EventRulesEditorProps) { const [isSubmitting, setIsSubmitting] = useState(false); const handleSubmit = async (e: React.FormEvent) => { @@ -96,10 +97,7 @@ export function EventRulesEditor({ serverId, config }: EventRulesEditorProps) { }; const handleInputChange = (key: keyof EventRules, value: string | number | boolean) => { - setFormData((prev) => ({ - ...prev, - [key]: value - })); + onFormDataChange({ ...formData, [key]: value }); }; return ( @@ -151,7 +149,7 @@ export function EventRulesEditor({ serverId, config }: EventRulesEditorProps) { setRestart(e.target.checked)} + onChange={(e) => onRestartChange(e.target.checked)} className="h-4 w-4 rounded border-border bg-overlay accent-green focus:ring-1 focus:ring-blue" /> Restart server after saving diff --git a/src/components/configuration/ServerSettingsEditor.tsx b/src/components/configuration/ServerSettingsEditor.tsx index 8fcfc9f..df2607c 100755 --- a/src/components/configuration/ServerSettingsEditor.tsx +++ b/src/components/configuration/ServerSettingsEditor.tsx @@ -6,7 +6,10 @@ import { updateServerSettingsAction } from '@/lib/actions/configuration'; interface ServerSettingsEditorProps { serverId: string; - config: ServerSettings; + formData: ServerSettings; + restart: boolean; + onFormDataChange: (data: ServerSettings) => void; + onRestartChange: (restart: boolean) => void; } const textFields = [ @@ -87,9 +90,7 @@ const selectFields = [ } ]; -export function ServerSettingsEditor({ serverId, config }: ServerSettingsEditorProps) { - const [formData, setFormData] = useState(config); - const [restart, setRestart] = useState(true); +export function ServerSettingsEditor({ serverId, formData, restart, onFormDataChange, onRestartChange }: ServerSettingsEditorProps) { const [isSubmitting, setIsSubmitting] = useState(false); const handleSubmit = async (e: React.FormEvent) => { @@ -115,10 +116,7 @@ export function ServerSettingsEditor({ serverId, config }: ServerSettingsEditorP }; const handleInputChange = (key: keyof ServerSettings, value: string | number) => { - setFormData((prev) => ({ - ...prev, - [key]: value - })); + onFormDataChange({ ...formData, [key]: value }); }; return ( @@ -226,7 +224,7 @@ export function ServerSettingsEditor({ serverId, config }: ServerSettingsEditorP setRestart(e.target.checked)} + onChange={(e) => onRestartChange(e.target.checked)} className="h-4 w-4 rounded border-border bg-overlay accent-green focus:ring-1 focus:ring-blue" /> Restart server after saving diff --git a/src/components/server/ServerConfigurationTabs.tsx b/src/components/server/ServerConfigurationTabs.tsx index baba695..ffb0367 100755 --- a/src/components/server/ServerConfigurationTabs.tsx +++ b/src/components/server/ServerConfigurationTabs.tsx @@ -36,25 +36,80 @@ export function ServerConfigurationTabs({ }: ServerConfigurationTabsProps) { const [currentTab, setCurrentTab] = useState(ServerTab.statistics); + const [configData, setConfigData] = useState(configurations.configuration); + const [configRestart, setConfigRestart] = useState(true); + + const [assistData, setAssistData] = useState(configurations.assistRules); + const [assistRestart, setAssistRestart] = useState(true); + + const [eventData, setEventData] = useState(configurations.event); + const [eventRestart, setEventRestart] = useState(true); + + const [eventRulesData, setEventRulesData] = useState(configurations.eventRules); + const [eventRulesRestart, setEventRulesRestart] = useState(true); + + const [settingsData, setSettingsData] = useState(configurations.settings); + const [settingsRestart, setSettingsRestart] = useState(true); + const renderTabContent = () => { switch (currentTab) { case ServerTab.statistics: return ; case ServerTab.configuration: - return ; + return ( + + ); case ServerTab.assistRules: - return ; + return ( + + ); case ServerTab.event: - return ; + return ( + + ); case ServerTab.eventRules: - return ; + return ( + + ); case ServerTab.settings: - return ; + return ( + + ); case ServerTab.leaderboard: return ;