From 7f9923167e8fc9d26130aa4bf5339d3f4eba0cad Mon Sep 17 00:00:00 2001 From: Toba Ojo Date: Wed, 3 Dec 2025 19:51:02 +0000 Subject: [PATCH] - added formik custom fields to settings and output --- .../output/components/ChannelFields.tsx | 44 +++- .../output/components/OutputForms.tsx | 3 + .../settings/components/SystemConfig.tsx | 220 +++++++++++------- src/types/types.ts | 6 +- 4 files changed, 184 insertions(+), 89 deletions(-) diff --git a/src/features/output/components/ChannelFields.tsx b/src/features/output/components/ChannelFields.tsx index 1633ac8..d35fe21 100644 --- a/src/features/output/components/ChannelFields.tsx +++ b/src/features/output/components/ChannelFields.tsx @@ -1,4 +1,4 @@ -import { Field } from "formik"; +import { Field, FieldArray } from "formik"; import type { FormTypes, InitialValuesFormErrors, OutputDataResponse } from "../../../types/types"; import { useEffect, useMemo } from "react"; import { useOptionalConstants } from "../hooks/useOptionalConstants"; @@ -17,6 +17,7 @@ type ChannelFieldsProps = { const ChannelFields = ({ errors, touched, values, outputData, onSetFieldValue }: ChannelFieldsProps) => { const { optionalConstantsQuery } = useOptionalConstants(outputData?.id?.split("-")[1] || ""); const optionalConstants = optionalConstantsQuery?.data; + const channelFieldsObject = useMemo(() => { return { connectTimeoutSeconds: outputData?.propConnectTimeoutSeconds?.value || "5", @@ -261,6 +262,47 @@ const ChannelFields = ({ errors, touched, values, outputData, onSetFieldValue }: )} +
+

Custom Fields

+
+
+ + {(arrayHelpers) => ( + <> + {values?.customFields?.map((_, index) => ( +
+ + +
+ ))} + + {values?.customFields && values?.customFields?.length > 0 && ( + + )} + + )} +
+
) : ( <> diff --git a/src/features/output/components/OutputForms.tsx b/src/features/output/components/OutputForms.tsx index 8ab9e50..f43b25c 100644 --- a/src/features/output/components/OutputForms.tsx +++ b/src/features/output/components/OutputForms.tsx @@ -41,6 +41,9 @@ const OutputForms = () => { LID2: "", // ftp - fields + + //custom fields + customFields: [], }; const handleSubmit = async (values: FormTypes) => { diff --git a/src/features/settings/components/SystemConfig.tsx b/src/features/settings/components/SystemConfig.tsx index 2706a95..00cfde0 100644 --- a/src/features/settings/components/SystemConfig.tsx +++ b/src/features/settings/components/SystemConfig.tsx @@ -1,4 +1,4 @@ -import { Formik, Form, Field } from "formik"; +import { Formik, Form, Field, FieldArray } from "formik"; import { useSystemSettings } from "../hooks/useSystemSettings"; import type { SystemSettings } from "../../../types/types"; import { toast } from "sonner"; @@ -28,104 +28,150 @@ const SystemConfig = () => { primaryServer: "", secondaryServer: "", timeSource: timeSource ?? "", + customFields: [], }; const handleSubmit = async (values: SystemSettings) => { const result = await systemSettingsMutation.mutateAsync(values); - console.log(result); + if (result.id) { toast.success("System settings updated successfully"); + } else { + toast.error("Failed to update system settings"); } }; return ( -
-
- - -
-
- - - {timeZoneOpts?.map((option: string) => ( - - ))} - -
-
- - - {timeSourceOpts?.map((option: string) => ( - - ))} - -
+ {({ values }) => ( + +
+ + +
+
+ + + {timeZoneOpts?.map((option: string) => ( + + ))} + +
+
+ + + {timeSourceOpts?.map((option: string) => ( + + ))} + +
-
- - -
-
- - -
-
- - -
-
- - -
- -
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+

Custom Fields

+
+
+ + {(arrayHelpers) => ( + <> + {values.customFields.map((field, index) => ( +
+ + +
+ ))} + + {values.customFields.length > 0 && ( + + )} + + )} +
+
+ + + )}
); }; diff --git a/src/types/types.ts b/src/types/types.ts index c79cb13..262514f 100644 --- a/src/types/types.ts +++ b/src/types/types.ts @@ -56,6 +56,10 @@ export type OptionalLaneIDs = { LID3?: string; }; +export type CustomFields = { + customFields?: string[]; +}; + export type InitialValuesFormErrors = { backOfficeURL?: string; username?: string; @@ -64,7 +68,7 @@ export type InitialValuesFormErrors = { readTimeoutSeconds?: string; }; -export type FormTypes = BearerTypeFields & OptionalConstants & OptionalLaneIDs; +export type FormTypes = BearerTypeFields & OptionalConstants & OptionalLaneIDs & CustomFields; type FieldProperty = { datatype: string; value: string; -- 2.25.1