2026-05-22 14:41:07 -05:00
|
|
|
import type { FormValidation } from "@rjsf/utils";
|
|
|
|
|
import type { TFunction } from "i18next";
|
|
|
|
|
import { isJsonObject } from "@/lib/utils";
|
|
|
|
|
import type { JsonObject } from "@/types/configForm";
|
|
|
|
|
|
|
|
|
|
export function validateDetectDimensions(
|
|
|
|
|
formData: unknown,
|
|
|
|
|
errors: FormValidation,
|
|
|
|
|
t: TFunction,
|
|
|
|
|
): FormValidation {
|
|
|
|
|
if (!isJsonObject(formData as JsonObject)) {
|
|
|
|
|
return errors;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const data = formData as JsonObject;
|
|
|
|
|
const width = data.width;
|
|
|
|
|
const height = data.height;
|
|
|
|
|
|
|
|
|
|
const widthErrors = errors.width as
|
2026-09-15 16:18:49 -05:00
|
|
|
{ addError?: (message: string) => void } | undefined;
|
2026-05-22 14:41:07 -05:00
|
|
|
const heightErrors = errors.height as
|
2026-09-15 16:18:49 -05:00
|
|
|
{ addError?: (message: string) => void } | undefined;
|
2026-05-22 14:41:07 -05:00
|
|
|
|
|
|
|
|
const message = t("detect.dimensionMustBeEven", { ns: "config/validation" });
|
|
|
|
|
|
|
|
|
|
if (typeof width === "number" && width % 2 !== 0) {
|
|
|
|
|
widthErrors?.addError?.(message);
|
|
|
|
|
}
|
|
|
|
|
if (typeof height === "number" && height % 2 !== 0) {
|
|
|
|
|
heightErrors?.addError?.(message);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return errors;
|
|
|
|
|
}
|