diff --git a/src/components/@shared/FormInput/index.tsx b/src/components/@shared/FormInput/index.tsx index 4a3aeb98c..1abd886d4 100644 --- a/src/components/@shared/FormInput/index.tsx +++ b/src/components/@shared/FormInput/index.tsx @@ -66,6 +66,24 @@ export interface InputProps { disclaimerValues?: string[] } +function checkError( + form: any, + parsedFieldName: string[], + field: FieldInputProps +) { + if (form?.errors === {}) { + return false + } else if ( + (form?.touched?.[parsedFieldName[0]]?.[parsedFieldName[1]] && + form?.errors?.[parsedFieldName[0]]?.[parsedFieldName[1]]) || + (form?.touched[field.name] && + form?.errors[field.name] && + field.name !== 'links') + ) { + return true + } +} + export default function Input(props: Partial): ReactElement { const { label, @@ -81,17 +99,12 @@ export default function Input(props: Partial): ReactElement { const isFormikField = typeof field !== 'undefined' const isNestedField = field?.name?.includes('.') - // TODO: this feels hacky as it assumes nested `values` store. But we can't use the // `useField()` hook in here to get `meta.error` so we have to match against form?.errors? // handling flat and nested data at same time. const parsedFieldName = isFormikField && (isNestedField ? field?.name.split('.') : [field?.name]) - // const hasFormikError = !!meta?.touched && !!meta?.error - const hasFormikError = - form?.errors !== {} && - form?.touched?.[parsedFieldName[0]]?.[parsedFieldName[1]] && - form?.errors?.[parsedFieldName[0]]?.[parsedFieldName[1]] + const hasFormikError = checkError(form, parsedFieldName, field) const styleClasses = cx({ field: true, diff --git a/src/components/Asset/Edit/FormEditMetadata.tsx b/src/components/Asset/Edit/FormEditMetadata.tsx index 1c4461744..e7e5af8f2 100644 --- a/src/components/Asset/Edit/FormEditMetadata.tsx +++ b/src/components/Asset/Edit/FormEditMetadata.tsx @@ -17,40 +17,6 @@ export function checkIfTimeoutInPredefinedValues( return false } -function handleTimeoutCustomOption( - data: FormFieldContent[], - values: Partial -) { - const timeoutFieldContent = data.filter( - (field) => field.name === 'timeout' - )[0] - const timeoutInputIndex = data.findIndex( - (element) => element.name === 'timeout' - ) - if ( - data[timeoutInputIndex].options.length < 6 && - !checkIfTimeoutInPredefinedValues( - values?.services[0]?.timeout, - timeoutFieldContent.options - ) - ) { - data[timeoutInputIndex].options.push(values?.services[0]?.timeout) - } else if ( - data[timeoutInputIndex].options.length === 6 && - checkIfTimeoutInPredefinedValues( - values?.services[0]?.timeout, - timeoutFieldContent.options - ) - ) { - data[timeoutInputIndex].options.pop() - } else if ( - data[timeoutInputIndex].options.length === 6 && - data[timeoutInputIndex].options[5] !== values?.services[0]?.timeout - ) { - data[timeoutInputIndex].options[5] = values?.services[0]?.timeout - } -} - export default function FormEditMetadata({ data, showPrice, diff --git a/src/components/Asset/Edit/_constants.ts b/src/components/Asset/Edit/_constants.ts index 39d912d80..a03a1416a 100644 --- a/src/components/Asset/Edit/_constants.ts +++ b/src/components/Asset/Edit/_constants.ts @@ -1,5 +1,5 @@ import { Metadata, ServiceComputeOptions } from '@oceanprotocol/lib' -import { mapTimeoutStringToSeconds, secondsToString } from '@utils/ddo' +import { secondsToString } from '@utils/ddo' import * as Yup from 'yup' import { MetadataEditForm } from './_types'