2025-11-03 15:01:13 +00:00
|
|
|
import { useFormikContext, type FormikTouched } from "formik";
|
2025-08-18 12:53:30 +01:00
|
|
|
import Card from "../../UI/Card";
|
|
|
|
|
import CardHeader from "../../UI/CardHeader";
|
|
|
|
|
import ChannelFields from "./ChannelFields";
|
2025-11-03 15:01:13 +00:00
|
|
|
import type { BearerTypeFieldType, InitialValuesForm } from "../../../types/types";
|
2025-11-04 10:24:06 +00:00
|
|
|
import { useCameraBackOfficeOutput } from "../../../hooks/useBackOfficeConfig";
|
2025-11-03 15:01:13 +00:00
|
|
|
import { useEffect, useMemo } from "react";
|
|
|
|
|
|
|
|
|
|
type ChannelCardProps = {
|
|
|
|
|
touched: FormikTouched<BearerTypeFieldType & InitialValuesForm>;
|
|
|
|
|
isSubmitting: boolean;
|
2025-11-04 15:29:48 +00:00
|
|
|
isBof2ConstantsLoading: boolean;
|
|
|
|
|
isDispatcherLoading: boolean;
|
2025-11-03 15:01:13 +00:00
|
|
|
};
|
|
|
|
|
|
2025-11-04 15:29:48 +00:00
|
|
|
const ChannelCard = ({ touched, isSubmitting, isBof2ConstantsLoading, isDispatcherLoading }: ChannelCardProps) => {
|
2025-11-04 10:24:06 +00:00
|
|
|
const { values, setFieldValue } = useFormikContext<BearerTypeFieldType & InitialValuesForm>();
|
|
|
|
|
const { backOfficeQuery } = useCameraBackOfficeOutput(values?.format);
|
2025-11-04 15:29:48 +00:00
|
|
|
const isBackOfficeQueryLoading = backOfficeQuery?.isFetching;
|
2025-11-03 15:01:13 +00:00
|
|
|
|
|
|
|
|
const mapped = useMemo(() => {
|
2025-11-04 15:29:48 +00:00
|
|
|
const d = backOfficeQuery?.data;
|
2025-11-03 15:01:13 +00:00
|
|
|
return {
|
|
|
|
|
backOfficeURL: d?.propBackofficeURL?.value ?? "",
|
|
|
|
|
username: d?.propUsername?.value ?? "",
|
|
|
|
|
password: d?.propPassword?.value ?? "",
|
|
|
|
|
connectTimeoutSeconds: Number(d?.propConnectTimeoutSeconds?.value),
|
|
|
|
|
readTimeoutSeconds: Number(d?.propReadTimeoutSeconds?.value),
|
|
|
|
|
};
|
|
|
|
|
}, [backOfficeQuery.data]);
|
|
|
|
|
|
|
|
|
|
useEffect(() => {
|
2025-11-04 15:29:48 +00:00
|
|
|
if (!backOfficeQuery?.isSuccess) return;
|
2025-11-04 10:24:06 +00:00
|
|
|
for (const [key, value] of Object.entries(mapped)) {
|
|
|
|
|
setFieldValue(key, value);
|
|
|
|
|
}
|
|
|
|
|
}, [backOfficeQuery.isSuccess, mapped, setFieldValue]);
|
2025-08-18 12:53:30 +01:00
|
|
|
|
|
|
|
|
return (
|
2025-09-26 13:58:14 +01:00
|
|
|
<Card className="p-4">
|
2025-11-03 15:01:13 +00:00
|
|
|
<CardHeader title={`Channel (${values?.format})`} />
|
2025-11-04 15:29:48 +00:00
|
|
|
{!isBof2ConstantsLoading && !isDispatcherLoading && !isBackOfficeQueryLoading ? (
|
|
|
|
|
<ChannelFields
|
|
|
|
|
touched={touched}
|
|
|
|
|
isSubmitting={isSubmitting}
|
|
|
|
|
backOfficeData={backOfficeQuery}
|
|
|
|
|
format={values?.format}
|
|
|
|
|
/>
|
|
|
|
|
) : (
|
|
|
|
|
<>Loading...</>
|
|
|
|
|
)}
|
2025-08-18 12:53:30 +01:00
|
|
|
</Card>
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export default ChannelCard;
|