- added validation endpoint
This commit is contained in:
@@ -10,14 +10,14 @@ import type {
|
||||
} from "../../../types/types";
|
||||
import { useQueryClient } from "@tanstack/react-query";
|
||||
import { useUpdateBackOfficeConfig } from "../../../hooks/useBackOfficeConfig";
|
||||
import { useState } from "react";
|
||||
import { useFormVaidate } from "../../../hooks/useFormValidate";
|
||||
|
||||
const SettingForms = () => {
|
||||
const qc = useQueryClient();
|
||||
const [formErrors, setFormErrors] = useState<InitialValuesFormErrors | null>(null);
|
||||
const { dispatcherQuery, dispatcherMutation, backOfficeDispatcherMutation } = useCameraOutput();
|
||||
const { backOfficeMutation } = useUpdateBackOfficeConfig();
|
||||
const { bof2ConstantsQuery } = useGetDispatcherConfig();
|
||||
const { validateMutation } = useFormVaidate();
|
||||
|
||||
const format = dispatcherQuery?.data?.propFormat?.value;
|
||||
const enabled = dispatcherQuery?.data?.propEnabled?.value;
|
||||
@@ -69,14 +69,13 @@ const SettingForms = () => {
|
||||
} else if (connect < 0) {
|
||||
errors.connectTimeoutSeconds = "Must be ≥ 0";
|
||||
}
|
||||
setFormErrors(errors);
|
||||
return errors;
|
||||
};
|
||||
|
||||
const handleSubmit = async (values: BearerTypeFieldType & InitialValuesForm & OptionalBOF2Constants) => {
|
||||
if (formErrors && Object.entries(formErrors).length > 0) {
|
||||
return;
|
||||
}
|
||||
// if (formErrors && Object.entries(formErrors).length > 0) {
|
||||
// return;
|
||||
// }
|
||||
const dispatcherData = {
|
||||
format: values.format,
|
||||
enabled: values.enabled,
|
||||
@@ -86,7 +85,12 @@ const SettingForms = () => {
|
||||
if (result?.id) {
|
||||
qc.invalidateQueries({ queryKey: ["dispatcher"] });
|
||||
qc.invalidateQueries({ queryKey: ["backoffice", values.format] });
|
||||
await backOfficeMutation.mutateAsync(values);
|
||||
const validResponse = await validateMutation.mutateAsync(values);
|
||||
if (validResponse?.reason === "OK") {
|
||||
await backOfficeMutation.mutateAsync(values);
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (values.format.toLowerCase() === "bof2") {
|
||||
|
||||
Reference in New Issue
Block a user