- finally fixed custom imput to match what is on backend on sighting amend endpoint
This commit is contained in:
@@ -5,11 +5,7 @@ import ChannelFields from "./ChannelFields";
|
|||||||
import type { FormTypes } from "../../../types/types";
|
import type { FormTypes } from "../../../types/types";
|
||||||
import { useGetBearerConfig } from "../hooks/useBearer";
|
import { useGetBearerConfig } from "../hooks/useBearer";
|
||||||
|
|
||||||
type ChannelCardProps = {
|
const ChannelCard = () => {
|
||||||
customFields: (string | undefined)[];
|
|
||||||
};
|
|
||||||
|
|
||||||
const ChannelCard = ({ customFields }: ChannelCardProps) => {
|
|
||||||
const { values, errors, touched, setFieldValue } = useFormikContext<FormTypes>();
|
const { values, errors, touched, setFieldValue } = useFormikContext<FormTypes>();
|
||||||
const { bearerQuery } = useGetBearerConfig(values?.format?.toLowerCase() || "json");
|
const { bearerQuery } = useGetBearerConfig(values?.format?.toLowerCase() || "json");
|
||||||
const outputData = bearerQuery?.data;
|
const outputData = bearerQuery?.data;
|
||||||
@@ -22,7 +18,6 @@ const ChannelCard = ({ customFields }: ChannelCardProps) => {
|
|||||||
values={values}
|
values={values}
|
||||||
outputData={outputData}
|
outputData={outputData}
|
||||||
onSetFieldValue={setFieldValue}
|
onSetFieldValue={setFieldValue}
|
||||||
customFields={customFields}
|
|
||||||
/>
|
/>
|
||||||
<button
|
<button
|
||||||
type="submit"
|
type="submit"
|
||||||
|
|||||||
@@ -12,13 +12,12 @@ type ChannelFieldsProps = {
|
|||||||
};
|
};
|
||||||
outputData?: OutputDataResponse;
|
outputData?: OutputDataResponse;
|
||||||
onSetFieldValue: (field: string, value: string, shouldValidate?: boolean | undefined) => void;
|
onSetFieldValue: (field: string, value: string, shouldValidate?: boolean | undefined) => void;
|
||||||
customFields: (string | undefined)[];
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const ChannelFields = ({ errors, touched, values, outputData, onSetFieldValue, customFields }: ChannelFieldsProps) => {
|
const ChannelFields = ({ errors, touched, values, outputData, onSetFieldValue }: ChannelFieldsProps) => {
|
||||||
const { optionalConstantsQuery } = useOptionalConstants(outputData?.id?.split("-")[1] || "");
|
const { optionalConstantsQuery } = useOptionalConstants(outputData?.id?.split("-")[1] || "");
|
||||||
const optionalConstants = optionalConstantsQuery?.data;
|
const optionalConstants = optionalConstantsQuery?.data;
|
||||||
console.log(customFields);
|
|
||||||
const channelFieldsObject = useMemo(() => {
|
const channelFieldsObject = useMemo(() => {
|
||||||
return {
|
return {
|
||||||
connectTimeoutSeconds: outputData?.propConnectTimeoutSeconds?.value || "5",
|
connectTimeoutSeconds: outputData?.propConnectTimeoutSeconds?.value || "5",
|
||||||
@@ -160,7 +159,7 @@ const ChannelFields = ({ errors, touched, values, outputData, onSetFieldValue, c
|
|||||||
className="p-2 border border-gray-400 rounded-lg text-white bg-[#253445] w-full md:w-60"
|
className="p-2 border border-gray-400 rounded-lg text-white bg-[#253445] w-full md:w-60"
|
||||||
>
|
>
|
||||||
<option value={"UTC"}>UTC</option>
|
<option value={"UTC"}>UTC</option>
|
||||||
<option value={"local"}>Local</option>
|
<option value={"LOCAL"}>Local</option>
|
||||||
</Field>
|
</Field>
|
||||||
</div>
|
</div>
|
||||||
<div className="flex flex-row justify-between">
|
<div className="flex flex-row justify-between">
|
||||||
@@ -270,23 +269,24 @@ const ChannelFields = ({ errors, touched, values, outputData, onSetFieldValue, c
|
|||||||
<FieldArray name="customFields">
|
<FieldArray name="customFields">
|
||||||
{(arrayHelpers) => (
|
{(arrayHelpers) => (
|
||||||
<>
|
<>
|
||||||
{values?.customFields?.slice(0, 6).map((_, index) => (
|
{values?.customFields?.map((_, index) => {
|
||||||
<div key={index} className="flex flex-row justify-between items-center mb-4">
|
// if (!field.value) return null;
|
||||||
|
return (
|
||||||
|
<div key={index} className="flex flex-row justify-between items-center mb-4 gap-2">
|
||||||
<Field
|
<Field
|
||||||
name={`customFields.${index}.label`}
|
name={`customFields.${index}.label`}
|
||||||
className="p-2 border border-gray-400 rounded-lg w-full max-w-xs"
|
className="p-2 border border-gray-400 rounded-lg w-full max-w-xs"
|
||||||
placeholder={`Custom Field ${index + 1} label`}
|
placeholder={`Custom Field ${index + 1} Label`}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<Field
|
<Field
|
||||||
name={`customFields.${index}.value`}
|
name={`customFields.${index}.value`}
|
||||||
key={index}
|
|
||||||
className="p-2 border border-gray-400 rounded-lg w-full max-w-xs"
|
className="p-2 border border-gray-400 rounded-lg w-full max-w-xs"
|
||||||
placeholder={`Enter Custom Field ${index + 1} value`}
|
placeholder={`Custom Field ${index + 1} Value`}
|
||||||
autoComplete="off"
|
autoComplete="off"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
))}
|
);
|
||||||
|
})}
|
||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
onClick={() => arrayHelpers.push({ label: "", value: "" })}
|
onClick={() => arrayHelpers.push({ label: "", value: "" })}
|
||||||
|
|||||||
@@ -10,9 +10,10 @@ import { useCustomFields } from "../hooks/useCustomFields";
|
|||||||
const OutputForms = () => {
|
const OutputForms = () => {
|
||||||
const { bearerMutation } = usePostBearerConfig();
|
const { bearerMutation } = usePostBearerConfig();
|
||||||
const { dispatcherQuery, dispatcherMutation } = useDispatcherConfig();
|
const { dispatcherQuery, dispatcherMutation } = useDispatcherConfig();
|
||||||
const { customFieldsQuery } = useCustomFields();
|
const { customFieldsQuery, customFieldsMutation } = useCustomFields();
|
||||||
|
|
||||||
const isLoading = dispatcherQuery?.isLoading;
|
const isLoading = dispatcherQuery?.isLoading;
|
||||||
|
|
||||||
const format = dispatcherQuery?.data?.propFormat?.value;
|
const format = dispatcherQuery?.data?.propFormat?.value;
|
||||||
const { optionalConstantsQuery, optionalConstantsMutation } = useOptionalConstants(format?.toLowerCase());
|
const { optionalConstantsQuery, optionalConstantsMutation } = useOptionalConstants(format?.toLowerCase());
|
||||||
const FFID = optionalConstantsQuery?.data?.propFeedIdentifier?.value;
|
const FFID = optionalConstantsQuery?.data?.propFeedIdentifier?.value;
|
||||||
@@ -23,18 +24,25 @@ const OutputForms = () => {
|
|||||||
const customFieldLabel1 = customFieldsQuery?.data?.propCustomFieldName1?.value;
|
const customFieldLabel1 = customFieldsQuery?.data?.propCustomFieldName1?.value;
|
||||||
const customFieldLabel2 = customFieldsQuery?.data?.propCustomFieldName2?.value;
|
const customFieldLabel2 = customFieldsQuery?.data?.propCustomFieldName2?.value;
|
||||||
const customFieldLabel3 = customFieldsQuery?.data?.propCustomFieldName3?.value;
|
const customFieldLabel3 = customFieldsQuery?.data?.propCustomFieldName3?.value;
|
||||||
const customFieldLabel4 = customFieldsQuery?.data?.propCustomFieldName4?.value;
|
const customFieldLabel4 = customFieldsQuery?.data?.propStringName4?.value;
|
||||||
const customFieldLabel5 = customFieldsQuery?.data?.propCustomFieldName5?.value;
|
const customFieldLabel5 = customFieldsQuery?.data?.propStringName5?.value;
|
||||||
const customFieldLabel6 = customFieldsQuery?.data?.propCustomFieldName6?.value;
|
const customFieldLabel6 = customFieldsQuery?.data?.propStringName6?.value;
|
||||||
|
|
||||||
const customfields = [
|
const customFieldValues1 = customFieldsQuery?.data?.propCustomFieldValue1?.value;
|
||||||
customFieldLabel1,
|
const customFieldValues2 = customFieldsQuery?.data?.propCustomFieldValue2?.value;
|
||||||
customFieldLabel2,
|
const customFieldValues3 = customFieldsQuery?.data?.propCustomFieldValue3?.value;
|
||||||
customFieldLabel3,
|
const customFieldValues4 = customFieldsQuery?.data?.propStringValue4?.value;
|
||||||
customFieldLabel4,
|
const customFieldValues5 = customFieldsQuery?.data?.propStringValue5?.value;
|
||||||
customFieldLabel5,
|
const customFieldValues6 = customFieldsQuery?.data?.propStringValue6?.value;
|
||||||
customFieldLabel6,
|
|
||||||
];
|
const initialCustomFields = [
|
||||||
|
{ label: customFieldLabel1 || "", value: customFieldValues1 || "" },
|
||||||
|
{ label: customFieldLabel2 || "", value: customFieldValues2 || "" },
|
||||||
|
{ label: customFieldLabel3 || "", value: customFieldValues3 || "" },
|
||||||
|
{ label: customFieldLabel4 || "", value: customFieldValues4 || "" },
|
||||||
|
{ label: customFieldLabel5 || "", value: customFieldValues5 || "" },
|
||||||
|
{ label: customFieldLabel6 || "", value: customFieldValues6 || "" },
|
||||||
|
].filter((field) => field.label && field.value);
|
||||||
|
|
||||||
const inititalValues: FormTypes = {
|
const inititalValues: FormTypes = {
|
||||||
format: format ?? "JSON",
|
format: format ?? "JSON",
|
||||||
@@ -61,7 +69,7 @@ const OutputForms = () => {
|
|||||||
// ftp - fields
|
// ftp - fields
|
||||||
|
|
||||||
//custom fields
|
//custom fields
|
||||||
customFields: customfields ?? ["", "", "", "", "", ""],
|
customFields: initialCustomFields,
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleSubmit = async (values: FormTypes) => {
|
const handleSubmit = async (values: FormTypes) => {
|
||||||
@@ -107,6 +115,11 @@ const OutputForms = () => {
|
|||||||
await optionalConstantsMutation.mutateAsync(optionalUTMCFields);
|
await optionalConstantsMutation.mutateAsync(optionalUTMCFields);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (values.customFields && values.customFields.length > 0) {
|
||||||
|
const customFields = [...values.customFields];
|
||||||
|
|
||||||
|
await customFieldsMutation.mutateAsync(customFields);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
if (isLoading) {
|
if (isLoading) {
|
||||||
@@ -117,7 +130,7 @@ const OutputForms = () => {
|
|||||||
<Formik initialValues={inititalValues} onSubmit={handleSubmit} enableReinitialize>
|
<Formik initialValues={inititalValues} onSubmit={handleSubmit} enableReinitialize>
|
||||||
<Form className="grid grid-cols-1 md:grid-cols-2">
|
<Form className="grid grid-cols-1 md:grid-cols-2">
|
||||||
<BearerTypeCard />
|
<BearerTypeCard />
|
||||||
<ChannelCard customFields={customfields} />
|
<ChannelCard />
|
||||||
</Form>
|
</Form>
|
||||||
</Formik>
|
</Formik>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import { useQuery } from "@tanstack/react-query";
|
import { useQuery, useMutation } from "@tanstack/react-query";
|
||||||
import { CAMBASE } from "../../../utils/config";
|
import { CAMBASE } from "../../../utils/config";
|
||||||
|
import type { CustomFieldConfig } from "../../../types/types";
|
||||||
|
|
||||||
const fetchCustomFields = async () => {
|
const fetchCustomFields = async () => {
|
||||||
const response = await fetch(`${CAMBASE}/api/fetch-config?id=SightingAmmend0-custom-fields`);
|
const response = await fetch(`${CAMBASE}/api/fetch-config?id=SightingAmmend0-custom-fields`);
|
||||||
@@ -9,11 +10,56 @@ const fetchCustomFields = async () => {
|
|||||||
return response.json();
|
return response.json();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const postCustomFields = async (customFieldConfig: CustomFieldConfig[]) => {
|
||||||
|
const fields = [];
|
||||||
|
|
||||||
|
for (const customField of customFieldConfig) {
|
||||||
|
if (customField.value)
|
||||||
|
if (customFieldConfig.indexOf(customField) > 2) {
|
||||||
|
fields.push({
|
||||||
|
property: `propStringName${customFieldConfig.indexOf(customField) + 1}`,
|
||||||
|
value: customField.label,
|
||||||
|
});
|
||||||
|
fields.push({
|
||||||
|
property: `propStringValue${customFieldConfig.indexOf(customField) + 1}`,
|
||||||
|
value: customField.value,
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
fields.push(
|
||||||
|
{
|
||||||
|
property: `propCustomFieldName${customFieldConfig.indexOf(customField) + 1}`,
|
||||||
|
value: customField.label,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
property: `propCustomFieldValue${customFieldConfig.indexOf(customField) + 1}`,
|
||||||
|
value: customField.value,
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
const customFieldConfigPayload = {
|
||||||
|
id: "SightingAmmend0-custom-fields",
|
||||||
|
fields,
|
||||||
|
};
|
||||||
|
|
||||||
|
const response = await fetch(`${CAMBASE}/api/update-config`, {
|
||||||
|
method: "POST",
|
||||||
|
body: JSON.stringify(customFieldConfigPayload),
|
||||||
|
});
|
||||||
|
if (!response.ok) throw new Error("Network response was not ok");
|
||||||
|
return response.json();
|
||||||
|
};
|
||||||
|
|
||||||
export const useCustomFields = () => {
|
export const useCustomFields = () => {
|
||||||
const customFieldsQuery = useQuery({
|
const customFieldsQuery = useQuery({
|
||||||
queryKey: ["customFields"],
|
queryKey: ["customFields"],
|
||||||
queryFn: fetchCustomFields,
|
queryFn: fetchCustomFields,
|
||||||
});
|
});
|
||||||
|
|
||||||
return { customFieldsQuery };
|
const customFieldsMutation = useMutation({
|
||||||
|
mutationKey: ["customFieldsMutation"],
|
||||||
|
mutationFn: postCustomFields,
|
||||||
|
});
|
||||||
|
|
||||||
|
return { customFieldsQuery, customFieldsMutation };
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -56,8 +56,13 @@ export type OptionalLaneIDs = {
|
|||||||
LID3?: string;
|
LID3?: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export type CustomField = {
|
||||||
|
label: string;
|
||||||
|
value: string;
|
||||||
|
};
|
||||||
|
|
||||||
export type CustomFields = {
|
export type CustomFields = {
|
||||||
customFields?: string[];
|
customFields?: CustomField[];
|
||||||
};
|
};
|
||||||
|
|
||||||
export type InitialValuesFormErrors = {
|
export type InitialValuesFormErrors = {
|
||||||
@@ -195,3 +200,8 @@ export type NetworkConfig = {
|
|||||||
primaryServer?: string;
|
primaryServer?: string;
|
||||||
secondaryServer?: string;
|
secondaryServer?: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export type CustomFieldConfig = {
|
||||||
|
label: string;
|
||||||
|
value: string;
|
||||||
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user