From e113ba530011803139a4af54d5b17a65bf471df1 Mon Sep 17 00:00:00 2001 From: Matthias Kretschmann Date: Fri, 28 Jan 2022 11:46:09 +0000 Subject: [PATCH] V4-publish-fixes (#1030) * tweak file URL input * remove logging --- .../@shared/FormFields/URLInput/index.tsx | 17 +++++++++++++++-- src/components/Publish/_utils.ts | 6 ++++-- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/src/components/@shared/FormFields/URLInput/index.tsx b/src/components/@shared/FormFields/URLInput/index.tsx index 4d4030d2b..0426af0f9 100644 --- a/src/components/@shared/FormFields/URLInput/index.tsx +++ b/src/components/@shared/FormFields/URLInput/index.tsx @@ -1,10 +1,11 @@ -import React, { ReactElement } from 'react' +import React, { ReactElement, useEffect, useState } from 'react' import Button from '@shared/atoms/Button' import { ErrorMessage, useField } from 'formik' import Loader from '@shared/atoms/Loader' import styles from './index.module.css' import InputGroup from '@shared/FormInput/InputGroup' import InputElement from '@shared/FormInput/InputElement' +import isUrl from 'is-url-superb' export default function URLInput({ submitText, @@ -21,7 +22,19 @@ export default function URLInput({ hasError: boolean }): ReactElement { const [field, meta] = useField(name) - const isButtonDisabled = !field?.value || field.value === '' + const [isButtonDisabled, setIsButtonDisabled] = useState(true) + + useEffect(() => { + if (!field?.value) return + + setIsButtonDisabled( + !field?.value || + field.value === '' || + !isUrl(field.value) || + field.value.includes('javascript:') || + meta?.error + ) + }, [field?.value, meta?.error]) return ( <> diff --git a/src/components/Publish/_utils.ts b/src/components/Publish/_utils.ts index 3daac26f5..f3760a246 100644 --- a/src/components/Publish/_utils.ts +++ b/src/components/Publish/_utils.ts @@ -88,8 +88,10 @@ export async function transformPublishFormToDdo( const isPreview = !datatokenAddress && !nftAddress console.log('did', did, isPreview) // Transform from files[0].url to string[] assuming only 1 file - const filesTransformed = files?.length && files[0].valid && [files[0].url] - const linksTransformed = links?.length && links[0].valid && [links[0].url] + const filesTransformed = files?.length && + files[0].valid && [files[0].url.replace('javascript:', '')] + const linksTransformed = links?.length && + links[0].valid && [links[0].url.replace('javascript:', '')] const newMetadata: Metadata = { created: currentTime,