mirror of
https://github.com/oceanprotocol/market.git
synced 2024-12-02 05:57:29 +01:00
merge v4 into v4-c2d
This commit is contained in:
commit
cc5c761aca
@ -66,6 +66,24 @@ export interface InputProps {
|
|||||||
disclaimerValues?: string[]
|
disclaimerValues?: string[]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function checkError(
|
||||||
|
form: any,
|
||||||
|
parsedFieldName: string[],
|
||||||
|
field: FieldInputProps<any>
|
||||||
|
) {
|
||||||
|
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<InputProps>): ReactElement {
|
export default function Input(props: Partial<InputProps>): ReactElement {
|
||||||
const {
|
const {
|
||||||
label,
|
label,
|
||||||
@ -81,17 +99,12 @@ export default function Input(props: Partial<InputProps>): ReactElement {
|
|||||||
|
|
||||||
const isFormikField = typeof field !== 'undefined'
|
const isFormikField = typeof field !== 'undefined'
|
||||||
const isNestedField = field?.name?.includes('.')
|
const isNestedField = field?.name?.includes('.')
|
||||||
|
|
||||||
// TODO: this feels hacky as it assumes nested `values` store. But we can't use the
|
// 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?
|
// `useField()` hook in here to get `meta.error` so we have to match against form?.errors?
|
||||||
// handling flat and nested data at same time.
|
// handling flat and nested data at same time.
|
||||||
const parsedFieldName =
|
const parsedFieldName =
|
||||||
isFormikField && (isNestedField ? field?.name.split('.') : [field?.name])
|
isFormikField && (isNestedField ? field?.name.split('.') : [field?.name])
|
||||||
// const hasFormikError = !!meta?.touched && !!meta?.error
|
const hasFormikError = checkError(form, parsedFieldName, field)
|
||||||
const hasFormikError =
|
|
||||||
form?.errors !== {} &&
|
|
||||||
form?.touched?.[parsedFieldName[0]]?.[parsedFieldName[1]] &&
|
|
||||||
form?.errors?.[parsedFieldName[0]]?.[parsedFieldName[1]]
|
|
||||||
|
|
||||||
const styleClasses = cx({
|
const styleClasses = cx({
|
||||||
field: true,
|
field: true,
|
||||||
|
@ -17,40 +17,6 @@ export function checkIfTimeoutInPredefinedValues(
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
function handleTimeoutCustomOption(
|
|
||||||
data: FormFieldContent[],
|
|
||||||
values: Partial<FormPublishData>
|
|
||||||
) {
|
|
||||||
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({
|
export default function FormEditMetadata({
|
||||||
data,
|
data,
|
||||||
showPrice,
|
showPrice,
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import { Metadata, ServiceComputeOptions } from '@oceanprotocol/lib'
|
import { Metadata, ServiceComputeOptions } from '@oceanprotocol/lib'
|
||||||
import { mapTimeoutStringToSeconds, secondsToString } from '@utils/ddo'
|
import { secondsToString } from '@utils/ddo'
|
||||||
import * as Yup from 'yup'
|
import * as Yup from 'yup'
|
||||||
import { MetadataEditForm } from './_types'
|
import { MetadataEditForm } from './_types'
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user