"use client"; import { useState, useEffect } from "react"; import dynamic from "next/dynamic"; import Link from "next/link"; import { TextInput } from "@/components/input"; import { Section } from "@/components/section"; import { BlueButton } from "@/components/button"; import { useAdminConnexion } from "@/context/adminConnexionContext"; import useAdmin from '@/hook/useAdmin'; import Messages from "./components/messages"; import TeamManager from './components/teamManager'; // Imported at runtime and not at compile time const PolygonZoneSelector = dynamic(() => import('./components/polygonZoneSelector'), { ssr: false }); const CircleZoneSelector = dynamic(() => import('./components/circleZoneSelector'), { ssr: false }); const zoneTypes = { circle: "circle", polygon: "polygon" } const defaultCircleSettings = {type: zoneTypes.circle, min: null, max: null, reductionCount: 4, duration: 10} const defaultPolygonSettings = {type: zoneTypes.polygon, polygons: []} export default function ConfigurationPage() { const {zoneSettings, changeZoneSettings, penaltySettings, changePenaltySettings, addTeam} = useAdmin(); const { useProtect } = useAdminConnexion(); const [allowedTimeBetweenUpdates, setAllowedTimeBetweenUpdates] = useState(""); const [teamName, setTeamName] = useState(''); const [localZoneSettings, setLocalZoneSettings] = useState(zoneSettings); useProtect(); useEffect(() => { if (penaltySettings) { setAllowedTimeBetweenUpdates(penaltySettings.allowedTimeBetweenPositionUpdate.toString()); } }, [penaltySettings]); useEffect(() => { if (zoneSettings) { setLocalZoneSettings(zoneSettings); } }, [zoneSettings]); function updateLocalZoneSettings(key, value) { setLocalZoneSettings(prev => ({...prev, [key]: value})); }; function applySettings() { if (Number(allowedTimeBetweenUpdates) != penaltySettings.allowedTimeBetweenPositionUpdate) { changePenaltySettings({allowedTimeBetweenPositionUpdate: Number(allowedTimeBetweenUpdates)}); } } function handleChangeZoneType() { setLocalZoneSettings(localZoneSettings.type == zoneTypes.circle ? defaultPolygonSettings : defaultCircleSettings) } function handleSubmit(e) { e.preventDefault(); if (teamName !== "") { addTeam(teamName); setTeamName("") } } return (

Paramètres

setTeamName(e.target.value)} type="text" className="w-full h-full p-4 ring-1 ring-inset ring-gray-300" />

Interval between position updates

setAllowedTimeBetweenUpdates(e.target.value)} onBlur={applySettings} />
{localZoneSettings && Change zone type}
{localZoneSettings && localZoneSettings.type == zoneTypes.circle && changeZoneSettings(localZoneSettings)}/> } {localZoneSettings && localZoneSettings.type == zoneTypes.polygon && changeZoneSettings(localZoneSettings)}/> }
); }