2025-11-03 15:01:13 +00:00
|
|
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
2025-11-04 10:24:06 +00:00
|
|
|
import { Field, useFormikContext, type FormikTouched } from "formik";
|
2025-08-18 12:53:30 +01:00
|
|
|
import FormGroup from "../components/FormGroup";
|
2025-10-07 14:00:58 +01:00
|
|
|
import { useEffect, useState } from "react";
|
2025-09-16 14:20:38 +01:00
|
|
|
import { faEyeSlash, faEye } from "@fortawesome/free-solid-svg-icons";
|
|
|
|
|
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
|
2025-11-04 10:24:06 +00:00
|
|
|
import type { BearerTypeFieldType, InitialValuesForm } from "../../../types/types";
|
2025-10-07 14:00:58 +01:00
|
|
|
import { toast } from "sonner";
|
2025-11-04 10:24:06 +00:00
|
|
|
import type { UseQueryResult } from "@tanstack/react-query";
|
2025-11-03 15:01:13 +00:00
|
|
|
|
|
|
|
|
type ChannelFieldsProps = {
|
|
|
|
|
touched: FormikTouched<BearerTypeFieldType & InitialValuesForm>;
|
|
|
|
|
isSubmitting: boolean;
|
2025-11-04 10:24:06 +00:00
|
|
|
|
2025-11-03 15:01:13 +00:00
|
|
|
backOfficeData: UseQueryResult<any, Error>;
|
2025-11-04 10:24:06 +00:00
|
|
|
format?: string;
|
2025-11-03 15:01:13 +00:00
|
|
|
};
|
2025-08-18 12:53:30 +01:00
|
|
|
|
2025-11-04 10:24:06 +00:00
|
|
|
const ChannelFields = ({ touched, isSubmitting, format }: ChannelFieldsProps) => {
|
2025-09-16 14:20:38 +01:00
|
|
|
const [showPwd, setShowPwd] = useState(false);
|
2025-11-04 10:24:06 +00:00
|
|
|
const { submitCount, isValid, values, errors } = useFormikContext<BearerTypeFieldType & InitialValuesForm>();
|
2025-10-07 14:00:58 +01:00
|
|
|
|
2025-11-03 15:01:13 +00:00
|
|
|
const ValidationToastOnce = () => {
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
if (submitCount > 0 && !isValid) {
|
|
|
|
|
toast.error("Check fields are filled in");
|
|
|
|
|
}
|
|
|
|
|
}, []);
|
|
|
|
|
return null;
|
|
|
|
|
};
|
2025-10-15 11:00:52 +01:00
|
|
|
|
2025-11-03 15:01:13 +00:00
|
|
|
return (
|
2025-11-04 10:24:06 +00:00
|
|
|
<>
|
2025-11-04 11:17:04 +00:00
|
|
|
{format?.toLowerCase() !== "bof2" && format?.toLowerCase() !== "json" ? (
|
|
|
|
|
<>
|
|
|
|
|
<div className="mt-4 flex flex-col items-center justify-center rounded-2xl border border-slate-800 bg-slate-900/40 p-10 text-center">
|
|
|
|
|
<div className="mb-3 rounded-xl bg-slate-800 px-3 py-1 text-xs uppercase tracking-wider text-slate-400">
|
|
|
|
|
Format coming soon
|
|
|
|
|
</div>
|
2025-11-03 15:01:13 +00:00
|
|
|
|
2025-11-04 11:17:04 +00:00
|
|
|
<p className="max-w-md text-slate-300">
|
|
|
|
|
Output configuration currently supports <span className="font-bold text-blue-400">JSON</span> or{" "}
|
|
|
|
|
<span className="font-bold text-emerald-400">BOF2</span>. <br /> More formats will be added in future
|
|
|
|
|
updates.
|
|
|
|
|
</p>
|
2025-10-07 14:00:58 +01:00
|
|
|
</div>
|
2025-11-04 11:17:04 +00:00
|
|
|
</>
|
|
|
|
|
) : (
|
|
|
|
|
<>
|
|
|
|
|
<div className="flex flex-col space-y-2 px-2">
|
2025-11-04 10:24:06 +00:00
|
|
|
<FormGroup>
|
2025-11-04 11:17:04 +00:00
|
|
|
<label htmlFor="backoffice" className="m-0">
|
|
|
|
|
Back Office URL
|
|
|
|
|
</label>
|
|
|
|
|
|
2025-11-04 10:24:06 +00:00
|
|
|
<Field
|
2025-11-04 11:17:04 +00:00
|
|
|
name={"backOfficeURL"}
|
2025-11-04 10:24:06 +00:00
|
|
|
type="text"
|
2025-11-04 11:17:04 +00:00
|
|
|
id="backoffice"
|
|
|
|
|
placeholder="https://www.backoffice.com"
|
2025-11-04 10:24:06 +00:00
|
|
|
className={`p-1.5 border ${
|
2025-11-04 11:17:04 +00:00
|
|
|
errors.backOfficeURL && touched.backOfficeURL ? "border-red-500" : "border-gray-400 "
|
2025-11-04 10:24:06 +00:00
|
|
|
} rounded-lg w-full md:w-60`}
|
|
|
|
|
/>
|
|
|
|
|
</FormGroup>
|
|
|
|
|
<FormGroup>
|
2025-11-04 11:17:04 +00:00
|
|
|
<label htmlFor="username">Username</label>
|
2025-11-04 10:24:06 +00:00
|
|
|
<Field
|
2025-11-04 11:17:04 +00:00
|
|
|
name={"username"}
|
2025-11-04 10:24:06 +00:00
|
|
|
type="text"
|
2025-11-04 11:17:04 +00:00
|
|
|
id="username"
|
|
|
|
|
placeholder="Back office username"
|
2025-11-04 10:24:06 +00:00
|
|
|
className={`p-1.5 border ${
|
2025-11-04 11:17:04 +00:00
|
|
|
errors.username && touched.username ? "border-red-500" : "border-gray-400 "
|
2025-11-04 10:24:06 +00:00
|
|
|
} rounded-lg w-full md:w-60`}
|
|
|
|
|
/>
|
|
|
|
|
</FormGroup>
|
2025-11-04 11:17:04 +00:00
|
|
|
<FormGroup>
|
|
|
|
|
<label htmlFor="password">Password</label>
|
|
|
|
|
<div className="flex gap-2 items-center relative mb-4">
|
|
|
|
|
<Field
|
|
|
|
|
name={"password"}
|
|
|
|
|
type={showPwd ? "text" : "password"}
|
|
|
|
|
id="password"
|
|
|
|
|
placeholder="Back office password"
|
|
|
|
|
className={`p-1.5 border ${
|
|
|
|
|
errors.password && touched.password ? "border-red-500" : "border-gray-400 "
|
|
|
|
|
} rounded-lg w-full md:w-60`}
|
|
|
|
|
/>
|
|
|
|
|
<FontAwesomeIcon
|
|
|
|
|
type="button"
|
|
|
|
|
className="absolute right-5 end-0"
|
|
|
|
|
onClick={() => setShowPwd((s) => !s)}
|
|
|
|
|
icon={showPwd ? faEyeSlash : faEye}
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
</FormGroup>
|
2025-11-04 10:24:06 +00:00
|
|
|
|
|
|
|
|
<FormGroup>
|
2025-11-04 11:17:04 +00:00
|
|
|
<label htmlFor="connectTimeoutSeconds">Connect Timeout Seconds</label>
|
2025-11-04 10:24:06 +00:00
|
|
|
<Field
|
2025-11-04 11:17:04 +00:00
|
|
|
name={"connectTimeoutSeconds"}
|
|
|
|
|
type="number"
|
|
|
|
|
id="connectTimeoutSeconds"
|
|
|
|
|
className={`p-1.5 border ${
|
|
|
|
|
errors.connectTimeoutSeconds && touched.connectTimeoutSeconds ? "border-red-500" : "border-gray-400 "
|
|
|
|
|
} rounded-lg w-full md:w-60`}
|
|
|
|
|
/>
|
2025-11-04 10:24:06 +00:00
|
|
|
</FormGroup>
|
|
|
|
|
<FormGroup>
|
2025-11-04 11:17:04 +00:00
|
|
|
<label htmlFor="readTimeoutSeconds">Read Timeout Seconds</label>
|
2025-11-04 10:24:06 +00:00
|
|
|
<Field
|
2025-11-04 11:17:04 +00:00
|
|
|
name={"readTimeoutSeconds"}
|
|
|
|
|
type="number"
|
|
|
|
|
id="readTimeoutSeconds"
|
|
|
|
|
placeholder="https://example.com"
|
|
|
|
|
className={`p-1.5 border ${
|
|
|
|
|
errors.readTimeoutSeconds && touched.readTimeoutSeconds ? "border-red-500" : "border-gray-400 "
|
|
|
|
|
} rounded-lg w-full md:w-60`}
|
|
|
|
|
/>
|
2025-11-04 10:24:06 +00:00
|
|
|
</FormGroup>
|
|
|
|
|
|
2025-11-04 11:17:04 +00:00
|
|
|
{format?.toLowerCase() === "bof2" && (
|
|
|
|
|
<>
|
|
|
|
|
<div className="border-b border-gray-500 my-3">
|
|
|
|
|
<h2 className="font-bold">{values.format} Constants</h2>
|
|
|
|
|
</div>
|
|
|
|
|
<FormGroup>
|
|
|
|
|
<label htmlFor="FFID">Feed ID / Force ID</label>
|
|
|
|
|
<Field
|
|
|
|
|
name={"FFID"}
|
|
|
|
|
type="text"
|
|
|
|
|
id="FFID"
|
|
|
|
|
placeholder="ABC123"
|
|
|
|
|
className={`p-1.5 border ${
|
|
|
|
|
errors.readTimeoutSeconds && touched.readTimeoutSeconds ? "border-red-500" : "border-gray-400 "
|
|
|
|
|
} rounded-lg w-full md:w-60`}
|
|
|
|
|
/>
|
|
|
|
|
</FormGroup>
|
|
|
|
|
|
|
|
|
|
<FormGroup>
|
|
|
|
|
<label htmlFor="SCID">Source ID / Camera ID</label>
|
|
|
|
|
<Field
|
|
|
|
|
name={"SCID"}
|
|
|
|
|
type="text"
|
|
|
|
|
id="SCID"
|
|
|
|
|
placeholder="DEF345"
|
|
|
|
|
className={`p-1.5 border ${
|
|
|
|
|
errors.readTimeoutSeconds && touched.readTimeoutSeconds ? "border-red-500" : "border-gray-400 "
|
|
|
|
|
} rounded-lg w-full md:w-60`}
|
|
|
|
|
/>
|
|
|
|
|
</FormGroup>
|
|
|
|
|
|
|
|
|
|
<FormGroup>
|
|
|
|
|
<label htmlFor="timestampSource">Timestamp Source</label>
|
|
|
|
|
<Field
|
|
|
|
|
name={"timestampSource"}
|
|
|
|
|
as="select"
|
|
|
|
|
id="timestampSource"
|
|
|
|
|
className="p-2 border border-gray-400 rounded-lg text-white bg-[#253445] w-full md:w-60"
|
|
|
|
|
>
|
|
|
|
|
<option value="">-- Select format --</option>
|
|
|
|
|
<option value={"UTC"}>UTC</option>
|
|
|
|
|
<option value={"local"}>Local</option>
|
|
|
|
|
</Field>
|
|
|
|
|
</FormGroup>
|
|
|
|
|
<FormGroup>
|
|
|
|
|
<label htmlFor="GPSFormat">GPS Format</label>
|
|
|
|
|
<Field
|
|
|
|
|
name={"GPSFormat"}
|
|
|
|
|
as="select"
|
|
|
|
|
id="GPSFormat"
|
|
|
|
|
className="p-2 border border-gray-400 rounded-lg text-white bg-[#253445] w-full md:w-60"
|
|
|
|
|
>
|
|
|
|
|
<option value="">-- Select format --</option>
|
|
|
|
|
<option value={"Decimal degrees"}>Decimal degrees</option>
|
|
|
|
|
<option value={"minutes"}>Minutes</option>
|
|
|
|
|
</Field>
|
|
|
|
|
</FormGroup>
|
|
|
|
|
</>
|
|
|
|
|
)}
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<button
|
|
|
|
|
type="submit"
|
|
|
|
|
className="w-1/4 text-white bg-green-700 hover:bg-green-800 font-small rounded-lg text-sm px-2 py-2.5"
|
|
|
|
|
>
|
|
|
|
|
{isSubmitting ? "Saving..." : "Save Changes"}
|
|
|
|
|
</button>
|
|
|
|
|
<ValidationToastOnce />
|
|
|
|
|
</>
|
|
|
|
|
)}
|
2025-11-04 10:24:06 +00:00
|
|
|
</>
|
2025-08-18 12:53:30 +01:00
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export default ChannelFields;
|