import { useEffect, useMemo, useState } from "react"; import { LuExternalLink } from "react-icons/lu"; import { Button, LinkButton } from "@components/Button"; import { useJsonRpc } from "@/hooks/useJsonRpc"; import { InputFieldWithLabel } from "./InputField"; import { SelectMenuBasic } from "./SelectMenuBasic"; export interface JigglerConfig { inactivity_limit_seconds: number; jitter_percentage: number; schedule_cron_tab: string; timezone?: string; } export function JigglerSetting({ onSave, defaultJigglerState, }: { onSave: (jigglerConfig: JigglerConfig) => void; defaultJigglerState?: JigglerConfig; }) { const [jigglerConfigState, setJigglerConfigState] = useState( defaultJigglerState || { inactivity_limit_seconds: 20, jitter_percentage: 0, schedule_cron_tab: "*/20 * * * * *", timezone: "UTC", }, ); const { send } = useJsonRpc(); const [timezones, setTimezones] = useState([]); useEffect(() => { send("getTimezones", {}, resp => { if ("error" in resp) return; setTimezones(resp.result as string[]); }); }, [send]); const timezoneOptions = useMemo( () => timezones.map((timezone: string) => ({ value: timezone, label: timezone, })), [timezones], ); const exampleConfigs = [ { name: "Business Hours 9-17", config: { inactivity_limit_seconds: 60, jitter_percentage: 25, schedule_cron_tab: "0 * 9-17 * * 1-5", timezone: jigglerConfigState.timezone || "UTC", }, }, { name: "Business Hours 8-17", config: { inactivity_limit_seconds: 60, jitter_percentage: 25, schedule_cron_tab: "0 * 8-17 * * 1-5", timezone: jigglerConfigState.timezone || "UTC", }, }, ]; return (

Examples

{exampleConfigs.map((example, index) => (
setJigglerConfigState({ ...jigglerConfigState, schedule_cron_tab: e.target.value, }) } /> setJigglerConfigState({ ...jigglerConfigState, inactivity_limit_seconds: Number(e.target.value), }) } /> %} value={jigglerConfigState.jitter_percentage} type="number" min="0" max="100" onChange={e => setJigglerConfigState({ ...jigglerConfigState, jitter_percentage: Number(e.target.value), }) } /> setJigglerConfigState({ ...jigglerConfigState, timezone: e.target.value, }) } options={timezoneOptions} />
); }