mirror of
https://github.com/blakeblackshear/frigate.git
synced 2026-07-15 00:11:15 +03:00
fix validation for speed estimation
This commit is contained in:
parent
9637226183
commit
cfcb23fefb
@ -293,7 +293,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: "onBlur",
|
mode: "onChange",
|
||||||
defaultValues: {
|
defaultValues: {
|
||||||
name: polygon?.name ?? "",
|
name: polygon?.name ?? "",
|
||||||
friendly_name: polygon?.friendly_name ?? polygon?.name ?? "",
|
friendly_name: polygon?.friendly_name ?? polygon?.name ?? "",
|
||||||
@ -314,18 +314,25 @@ export default function ZoneEditPane({
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const watchSpeedEstimation = form.watch("speedEstimation");
|
||||||
|
const watchLineA = form.watch("lineA");
|
||||||
|
const watchLineB = form.watch("lineB");
|
||||||
|
const watchLineC = form.watch("lineC");
|
||||||
|
const watchLineD = form.watch("lineD");
|
||||||
|
|
||||||
|
const canSave =
|
||||||
|
form.formState.isValid &&
|
||||||
|
(!watchSpeedEstimation ||
|
||||||
|
(!!watchLineA && !!watchLineB && !!watchLineC && !!watchLineD));
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (
|
if (watchSpeedEstimation && polygon && polygon.points.length !== 4) {
|
||||||
form.watch("speedEstimation") &&
|
|
||||||
polygon &&
|
|
||||||
polygon.points.length !== 4
|
|
||||||
) {
|
|
||||||
toast.error(
|
toast.error(
|
||||||
t("masksAndZones.zones.speedThreshold.toast.error.pointLengthError"),
|
t("masksAndZones.zones.speedThreshold.toast.error.pointLengthError"),
|
||||||
);
|
);
|
||||||
form.setValue("speedEstimation", false);
|
form.setValue("speedEstimation", false);
|
||||||
}
|
}
|
||||||
}, [polygon, form, t]);
|
}, [polygon, form, t, watchSpeedEstimation]);
|
||||||
|
|
||||||
const saveToConfig = useCallback(
|
const saveToConfig = useCallback(
|
||||||
async (
|
async (
|
||||||
@ -966,7 +973,7 @@ export default function ZoneEditPane({
|
|||||||
</Button>
|
</Button>
|
||||||
<Button
|
<Button
|
||||||
variant="select"
|
variant="select"
|
||||||
disabled={isLoading || !form.formState.isValid}
|
disabled={isLoading || !canSave}
|
||||||
className="flex flex-1"
|
className="flex flex-1"
|
||||||
aria-label={t("button.save", { ns: "common" })}
|
aria-label={t("button.save", { ns: "common" })}
|
||||||
type="submit"
|
type="submit"
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user