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

fix edit form validation (#1797)

* fix edit form validation

* more validation edit form
This commit is contained in:
EnzoVezzaro 2022-11-25 12:41:17 -04:00 committed by GitHub
parent f6d11e5e6f
commit aa8dcdaa79
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 43 additions and 30 deletions

View File

@ -2,24 +2,37 @@ import { isCID } from '@utils/ipfs'
import isUrl from 'is-url-superb'
import * as Yup from 'yup'
export function testLinks() {
export function testLinks(isEdit?: boolean) {
return Yup.string().test((value, context) => {
const { type } = context.parent
let validField
let errorMessage
switch (type) {
// we allow submit if the type input is hidden as will be ignore
case 'hidden':
validField = true
break
case 'url':
validField = isUrl(value?.toString() || '')
// if we're in publish, the field must be valid
if (!validField) {
validField = false
errorMessage = 'Must be a valid url.'
} else {
}
// we allow submit if we're in the edit page and the field is empty
if (
(!value?.toString() && isEdit) ||
(!value?.toString() && context.path === 'services[0].links[0].url')
) {
validField = true
}
// if the url has google drive, we need to block the user from submit
if (value?.toString().includes('drive.google')) {
validField = false
errorMessage =
'Google Drive is not a supported hosting service. Please use an alternative.'
}
}
break
case 'ipfs':
validField = isCID(value?.toString())

View File

@ -25,6 +25,10 @@
border: 0;
}
.tabHidden {
display: none !important;
}
.tab,
.tab label {
cursor: pointer;

View File

@ -55,11 +55,11 @@ export default function TabsFile({
<div className={styles.tabListContainer}>
<TabList className={styles.tabList}>
{items.map((item, index) => {
if (isHidden) return null
return (
<Tab
className={styles.tab}
className={`${styles.tab} ${
isHidden ? styles.tabHidden : null
}`}
key={`tab_${items[tabIndex].props.name}_${index}`}
onClick={
handleTabChange ? () => handleTabChange(item.title) : null

View File

@ -47,12 +47,14 @@ export default function FormEditMetadata({
useEffect(() => {
// let's initiate files with empty url (we can't access the asset url) with type hidden (for UI frontend)
setTimeout(() => {
setFieldValue('files', [
{
url: '',
type: 'hidden'
}
])
}, 500)
const providerUrl = values?.services
? values?.services[0].providerUrl.url

View File

@ -12,13 +12,11 @@ export const validationSchema = Yup.object().shape({
files: Yup.array<FileInfo[]>()
.of(
Yup.object().shape({
url: testLinks(),
url: testLinks(true),
valid: Yup.boolean().test((value, context) => {
const { type } = context.parent
// allow user to submit if the value type is hidden
if (type === 'hidden') return true
return value || false
})
})
@ -26,14 +24,12 @@ export const validationSchema = Yup.object().shape({
.nullable(),
links: Yup.array<FileInfo[]>().of(
Yup.object().shape({
url: testLinks(),
url: testLinks(true),
valid: Yup.boolean().test((value, context) => {
// allow user to submit if the value is null
const { valid, url } = context.parent
// allow user to continue if the url is empty
if (!url) return true
return valid
})
})

View File

@ -79,8 +79,6 @@ export default function SearchPage({
fetchAssets(parsed, chainIds)
}, [parsed, chainIds, newCancelToken, fetchAssets])
console.log(queryResult?.results)
return (
<>
<div className={styles.search}>