'use client'; import { useState } from 'react'; import type { EventRules } from '@/lib/types/config'; import { updateEventRulesAction } from '@/lib/actions/configuration'; interface EventRulesEditorProps { serverId: string; config: EventRules; } export function EventRulesEditor({ serverId, config }: EventRulesEditorProps) { const [formData, setFormData] = useState(config); const [restart, setRestart] = useState(true); const [isSubmitting, setIsSubmitting] = useState(false); const handleSubmit = async (e: React.FormEvent) => { e.preventDefault(); setIsSubmitting(true); const formDataObj = new FormData(); Object.entries(formData).forEach(([key, value]) => { formDataObj.append(key, value.toString()); }); if (restart) { formDataObj.append('restart', 'on'); } try { const result = await updateEventRulesAction(serverId, formDataObj); if (!result.success) { console.error('Failed to update event rules:', result.message); } } finally { setIsSubmitting(false); } }; const handleInputChange = (key: keyof EventRules, value: string | number | boolean) => { setFormData((prev) => ({ ...prev, [key]: value })); }; const numberFields = [ { key: 'qualifyStandingType' as keyof EventRules, label: 'Qualify Standing Type', min: -1, max: 1 }, { key: 'pitWindowLengthSec' as keyof EventRules, label: 'Pit Window Length (seconds)', min: -1 }, { key: 'driverStintTimeSec' as keyof EventRules, label: 'Driver Stint Time (seconds)', min: -1 }, { key: 'mandatoryPitstopCount' as keyof EventRules, label: 'Mandatory Pitstop Count', min: -1, max: 5 }, { key: 'maxTotalDrivingTime' as keyof EventRules, label: 'Max Total Driving Time (seconds)', min: -1 }, { key: 'tyreSetCount' as keyof EventRules, label: 'Tyre Set Count', min: 0, max: 50 } ]; const booleanFields = [ { key: 'isRefuellingAllowedInRace' as keyof EventRules, label: 'Refuelling Allowed in Race' }, { key: 'isRefuellingTimeFixed' as keyof EventRules, label: 'Refuelling Time Fixed' }, { key: 'isMandatoryPitstopRefuellingRequired' as keyof EventRules, label: 'Mandatory Pitstop Refuelling Required' }, { key: 'isMandatoryPitstopTyreChangeRequired' as keyof EventRules, label: 'Mandatory Pitstop Tyre Change Required' }, { key: 'isMandatoryPitstopSwapDriverRequired' as keyof EventRules, label: 'Mandatory Pitstop Swap Driver Required' } ]; return (

Race Rules

{numberFields.map(({ key, label, min, max }) => (
handleInputChange(key, parseInt(e.target.value) || 0)} className="form-input w-full" min={min} max={max} />
))}

Pitstop & Refuelling Rules

{booleanFields.map(({ key, label }) => (
))}
); }