- refactored bearer form
- started refactoring Channel form
This commit is contained in:
@@ -1,32 +1,71 @@
|
||||
import { Field, useFormikContext } from "formik";
|
||||
import { Field, Form, Formik } from "formik";
|
||||
import FormToggle from "../components/FormToggle";
|
||||
import { useCameraOutput } from "../../../hooks/useCameraOutput";
|
||||
import { cleanArray } from "../../../utils/utils";
|
||||
import FormGroup from "../components/FormGroup";
|
||||
import type { BearerTypeFieldType } from "../../../types/types";
|
||||
|
||||
export const ValuesComponent = () => {
|
||||
return null;
|
||||
};
|
||||
|
||||
const BearerTypeFields = () => {
|
||||
useFormikContext();
|
||||
const { dispatcherQuery, dispatcherMutation } = useCameraOutput();
|
||||
|
||||
const format = dispatcherQuery?.data?.propFormat?.value;
|
||||
const rawOptions = dispatcherQuery?.data?.propFormat?.accepted;
|
||||
const enabled = dispatcherQuery?.data?.propEnabled?.value;
|
||||
const verbose = dispatcherQuery?.data?.propVerbose?.value;
|
||||
const options = cleanArray(rawOptions);
|
||||
|
||||
const initialValues: BearerTypeFieldType = {
|
||||
format: format ?? "JSON",
|
||||
enabled: enabled === "true",
|
||||
verbose: verbose === "true",
|
||||
};
|
||||
|
||||
const handleSubmit = (values: BearerTypeFieldType) => {
|
||||
dispatcherMutation.mutate(values);
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="flex flex-col space-y-4 px-2">
|
||||
<div className="flex items-center gap-3 justify-between">
|
||||
<label htmlFor="format">Format</label>
|
||||
<Field
|
||||
as="select"
|
||||
name="format"
|
||||
id="format"
|
||||
className="p-2 border border-gray-400 rounded-lg text-white bg-[#253445] w-full md:w-60"
|
||||
>
|
||||
<option value="JSON">JSON</option>
|
||||
<option value="BOF2">BOF2</option>
|
||||
</Field>
|
||||
</div>
|
||||
<div className="flex flex-col space-y-4">
|
||||
<FormToggle name="enabled" label="Enabled" />
|
||||
<FormToggle name="verbose" label="Verbose" />
|
||||
</div>
|
||||
</div>
|
||||
<Formik
|
||||
initialValues={initialValues}
|
||||
onSubmit={handleSubmit}
|
||||
enableReinitialize
|
||||
>
|
||||
<Form>
|
||||
<div className="flex flex-col space-y-4 px-2">
|
||||
<FormGroup>
|
||||
<label htmlFor="format">Format</label>
|
||||
<Field
|
||||
as="select"
|
||||
name="format"
|
||||
id="format"
|
||||
className="p-2 border border-gray-400 rounded-lg text-white bg-[#253445] w-full md:w-60"
|
||||
>
|
||||
{options?.map((option: string) => (
|
||||
<option key={option} value={option}>
|
||||
{option}
|
||||
</option>
|
||||
))}
|
||||
</Field>
|
||||
</FormGroup>
|
||||
<FormGroup>
|
||||
<div className="flex flex-col space-y-4">
|
||||
<FormToggle name="enabled" label="Enabled" />
|
||||
<FormToggle name="verbose" label="Verbose" />
|
||||
</div>
|
||||
</FormGroup>
|
||||
<button
|
||||
type="submit"
|
||||
className="bg-[#26B170] text-white px-4 py-2 rounded hover:bg-green-700 transition w-full md:w-[50%]"
|
||||
>
|
||||
Save Changes
|
||||
</button>
|
||||
</div>
|
||||
</Form>
|
||||
</Formik>
|
||||
);
|
||||
};
|
||||
|
||||
|
||||
@@ -1,72 +1,89 @@
|
||||
import { Field, useFormikContext } from "formik";
|
||||
import { Field, Form, Formik } from "formik";
|
||||
import FormGroup from "../components/FormGroup";
|
||||
import { useState } from "react";
|
||||
import { faEyeSlash, faEye } from "@fortawesome/free-solid-svg-icons";
|
||||
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
|
||||
|
||||
const ChannelFields = () => {
|
||||
useFormikContext();
|
||||
const [showPwd, setShowPwd] = useState(false);
|
||||
const initialValues = {
|
||||
backOfficeURL: "",
|
||||
username: "",
|
||||
password: "",
|
||||
connectTimeoutSeconds: 0,
|
||||
readTimeoutSeconds: 0,
|
||||
};
|
||||
|
||||
const handleSubmit = (values) => {
|
||||
console.log(values);
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="flex flex-col space-y-2 px-2">
|
||||
<FormGroup>
|
||||
<label htmlFor="backoffice" className="m-0">
|
||||
Back Office URL
|
||||
</label>
|
||||
<Field
|
||||
name={"backOfficeURL"}
|
||||
type="text"
|
||||
id="backoffice"
|
||||
placeholder="https://www.backoffice.com"
|
||||
className="p-1.5 border border-gray-400 rounded-lg w-full md:w-60"
|
||||
/>
|
||||
</FormGroup>
|
||||
<FormGroup>
|
||||
<label htmlFor="username">Username</label>
|
||||
<Field
|
||||
name={"username"}
|
||||
type="text"
|
||||
id="username"
|
||||
placeholder="Back office username"
|
||||
className="p-1.5 border border-gray-400 rounded-lg w-full md:w-60"
|
||||
/>
|
||||
</FormGroup>
|
||||
<FormGroup>
|
||||
<label htmlFor="password">Password</label>
|
||||
<Field
|
||||
name={"password"}
|
||||
type={showPwd ? "text" : "password"}
|
||||
id="password"
|
||||
placeholder="Back office password"
|
||||
className="p-1.5 border 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}
|
||||
/>
|
||||
</FormGroup>
|
||||
<FormGroup>
|
||||
<label htmlFor="connectTimeoutSeconds">Connect Timeout Seconds</label>
|
||||
<Field
|
||||
name={"connectTimeoutSeconds"}
|
||||
type="number"
|
||||
id="connectTimeoutSeconds"
|
||||
className="p-1.5 border border-gray-400 rounded-lg w-full md:w-60"
|
||||
/>
|
||||
</FormGroup>
|
||||
<FormGroup>
|
||||
<label htmlFor="readTimeoutSeconds">Read Timeout Seconds</label>
|
||||
<Field
|
||||
name={"readTimeoutSeconds"}
|
||||
type="number"
|
||||
id="readTimeoutSeconds"
|
||||
placeholder="https://example.com"
|
||||
className="p-1.5 border border-gray-400 rounded-lg w-full md:w-60"
|
||||
/>
|
||||
</FormGroup>
|
||||
</div>
|
||||
<Formik initialValues={initialValues} onSubmit={handleSubmit}>
|
||||
<Form>
|
||||
<div className="flex flex-col space-y-2 px-2">
|
||||
<FormGroup>
|
||||
<label htmlFor="backoffice" className="m-0">
|
||||
Back Office URL
|
||||
</label>
|
||||
<Field
|
||||
name={"backOfficeURL"}
|
||||
type="text"
|
||||
id="backoffice"
|
||||
placeholder="https://www.backoffice.com"
|
||||
className="p-1.5 border border-gray-400 rounded-lg w-full md:w-60"
|
||||
/>
|
||||
</FormGroup>
|
||||
<FormGroup>
|
||||
<label htmlFor="username">Username</label>
|
||||
<Field
|
||||
name={"username"}
|
||||
type="text"
|
||||
id="username"
|
||||
placeholder="Back office username"
|
||||
className="p-1.5 border border-gray-400 rounded-lg w-full md:w-60"
|
||||
/>
|
||||
</FormGroup>
|
||||
<FormGroup>
|
||||
<label htmlFor="password">Password</label>
|
||||
<Field
|
||||
name={"password"}
|
||||
type={showPwd ? "text" : "password"}
|
||||
id="password"
|
||||
placeholder="Back office password"
|
||||
className="p-1.5 border 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}
|
||||
/>
|
||||
</FormGroup>
|
||||
<FormGroup>
|
||||
<label htmlFor="connectTimeoutSeconds">
|
||||
Connect Timeout Seconds
|
||||
</label>
|
||||
<Field
|
||||
name={"connectTimeoutSeconds"}
|
||||
type="number"
|
||||
id="connectTimeoutSeconds"
|
||||
className="p-1.5 border border-gray-400 rounded-lg w-full md:w-60"
|
||||
/>
|
||||
</FormGroup>
|
||||
<FormGroup>
|
||||
<label htmlFor="readTimeoutSeconds">Read Timeout Seconds</label>
|
||||
<Field
|
||||
name={"readTimeoutSeconds"}
|
||||
type="number"
|
||||
id="readTimeoutSeconds"
|
||||
placeholder="https://example.com"
|
||||
className="p-1.5 border border-gray-400 rounded-lg w-full md:w-60"
|
||||
/>
|
||||
</FormGroup>
|
||||
</div>
|
||||
</Form>
|
||||
</Formik>
|
||||
);
|
||||
};
|
||||
|
||||
|
||||
@@ -11,14 +11,6 @@ const SettingForms = () => {
|
||||
const [advancedToggle, setAdvancedToggle] = useState(false);
|
||||
|
||||
const initialValues = {
|
||||
format: "JSON",
|
||||
enabled: false,
|
||||
verbose: false,
|
||||
backOfficeURL: "",
|
||||
username: "",
|
||||
password: "",
|
||||
connectTimeoutSeconds: 0,
|
||||
readTimeoutSeconds: 0,
|
||||
overviewQuality: "high",
|
||||
overviewImageScaleFactor: "full",
|
||||
overviewType: "Plate Overview",
|
||||
@@ -50,34 +42,37 @@ const SettingForms = () => {
|
||||
};
|
||||
|
||||
return (
|
||||
<Formik initialValues={initialValues} onSubmit={handleSubmit}>
|
||||
<Form className="flex flex-col space-y-3">
|
||||
<div className="mx-auto grid grid-cols-1 sm:grid-cols-1 lg:grid-cols-2 gap-2 px-2 sm:px-4 lg:px-0 w-full">
|
||||
<BearerTypeCard />
|
||||
<ChannelCard />
|
||||
</div>
|
||||
<AdvancedToggle
|
||||
advancedToggle={advancedToggle}
|
||||
onAdvancedChange={setAdvancedToggle}
|
||||
/>
|
||||
{advancedToggle && (
|
||||
<>
|
||||
<div className="md:col-span-2">
|
||||
<SightingDataCard />
|
||||
</div>
|
||||
<div className="md:col-span-2">
|
||||
<OverviewTextCard />
|
||||
</div>
|
||||
</>
|
||||
)}
|
||||
<button
|
||||
type="submit"
|
||||
className="bg-[#26B170] text-white px-4 py-2 rounded hover:bg-green-700 transition w-full md:w-[50%]"
|
||||
>
|
||||
Save Changes
|
||||
</button>
|
||||
</Form>
|
||||
</Formik>
|
||||
<div className="mx-auto grid grid-cols-1 sm:grid-cols-1 lg:grid-cols-2 gap-2 px-2 sm:px-4 lg:px-0 w-full">
|
||||
<BearerTypeCard />
|
||||
<ChannelCard />
|
||||
</div>
|
||||
// <Formik initialValues={initialValues} onSubmit={handleSubmit}>
|
||||
// <Form className="flex flex-col space-y-3">
|
||||
// <div className="mx-auto grid grid-cols-1 sm:grid-cols-1 lg:grid-cols-2 gap-2 px-2 sm:px-4 lg:px-0 w-full">
|
||||
//
|
||||
// </div>
|
||||
// <AdvancedToggle
|
||||
// advancedToggle={advancedToggle}
|
||||
// onAdvancedChange={setAdvancedToggle}
|
||||
// />
|
||||
// {advancedToggle && (
|
||||
// <>
|
||||
// <div className="md:col-span-2">
|
||||
// <SightingDataCard />
|
||||
// </div>
|
||||
// <div className="md:col-span-2">
|
||||
// <OverviewTextCard />
|
||||
// </div>
|
||||
// </>
|
||||
// )}
|
||||
// <button
|
||||
// type="submit"
|
||||
// className="bg-[#26B170] text-white px-4 py-2 rounded hover:bg-green-700 transition w-full md:w-[50%]"
|
||||
// >
|
||||
// Save Changes
|
||||
// </button>
|
||||
// </Form>
|
||||
// </Formik>
|
||||
);
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user