1
0
mirror of https://github.com/oceanprotocol/market.git synced 2024-12-02 05:57:29 +01:00

adding links validation in edit form

This commit is contained in:
EnzoVezzaro 2022-08-15 09:02:54 -04:00
parent 4d119467a4
commit 95199054f8

View File

@ -1,4 +1,4 @@
import React, { ReactElement, useState } from 'react' import React, { ReactElement, useEffect, useState } from 'react'
import { useField, useFormikContext } from 'formik' import { useField, useFormikContext } from 'formik'
import FileInfo from './Info' import FileInfo from './Info'
import UrlInput from '../URLInput' import UrlInput from '../URLInput'
@ -16,7 +16,7 @@ export default function FilesInput(props: InputProps): ReactElement {
async function handleValidation(e: React.SyntheticEvent, url: string) { async function handleValidation(e: React.SyntheticEvent, url: string) {
// File example 'https://oceanprotocol.com/tech-whitepaper.pdf' // File example 'https://oceanprotocol.com/tech-whitepaper.pdf'
e.preventDefault() e?.preventDefault()
try { try {
const providerUrl = values?.services const providerUrl = values?.services
@ -47,6 +47,12 @@ export default function FilesInput(props: InputProps): ReactElement {
helpers.setTouched(false) helpers.setTouched(false)
} }
useEffect(() => {
if (field.name === 'links' && asset?.metadata?.links) {
handleValidation(null, asset.metadata.links[0])
}
}, [])
return ( return (
<> <>
{field?.value?.[0]?.valid === true ? ( {field?.value?.[0]?.valid === true ? (