ensure speed estimation is disabled when user adds more than 4 points

This commit is contained in:
Josh Hawkins 2024-12-08 13:11:23 -06:00
parent e163a2f178
commit 6af95b7487

View File

@ -90,7 +90,7 @@ export default function ZoneEditPane({
return Array.isArray(distances) return Array.isArray(distances)
? distances.map((value) => parseFloat(value) || 0) ? distances.map((value) => parseFloat(value) || 0)
: [0, 0, 0, 0]; : [undefined, undefined, undefined, undefined];
}, [polygon, config]); }, [polygon, config]);
const formSchema = z const formSchema = z
@ -197,7 +197,7 @@ export default function ZoneEditPane({
const form = useForm<z.infer<typeof formSchema>>({ const form = useForm<z.infer<typeof formSchema>>({
resolver: zodResolver(formSchema), resolver: zodResolver(formSchema),
mode: "onChange", mode: "onBlur",
defaultValues: { defaultValues: {
name: polygon?.name ?? "", name: polygon?.name ?? "",
inertia: inertia:
@ -218,6 +218,19 @@ export default function ZoneEditPane({
}, },
}); });
useEffect(() => {
if (
form.watch("speedEstimation") &&
polygon &&
polygon.points.length !== 4
) {
toast.error(
"Speed estimation has been disabled for this zone. Zones with speed estimation must have exactly 4 points.",
);
form.setValue("speedEstimation", false);
}
}, [polygon, form]);
const saveToConfig = useCallback( const saveToConfig = useCallback(
async ( async (
{ {
@ -746,7 +759,9 @@ export function ZoneObjectSelector({
useEffect(() => { useEffect(() => {
updateLabelFilter(currentLabels); updateLabelFilter(currentLabels);
}, [currentLabels, updateLabelFilter]); // we know that these deps are correct
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [currentLabels]);
return ( return (
<> <>