1
0
mirror of https://github.com/oceanprotocol/market.git synced 2024-06-26 03:06:49 +02:00

No error shown for invalid file url (#1221)

* check file url

* logic fix

* display error message

* use x mark sign

* change border and background color for wrong input

* invalid input red border

* make error visible only for touched field

Co-authored-by: ClaudiaHolhos <claudia@oceanprotocol.com>
This commit is contained in:
claudiaHash 2022-03-29 17:14:46 +03:00 committed by GitHub
parent 6e2e46d8ea
commit 90f841bb13
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 32 additions and 6 deletions

View File

@ -6,6 +6,11 @@
position: relative;
}
.hasError {
border-color: var(--brand-alert-red);
background-color: var(--brand-white);
}
.url {
margin: 0;
font-size: var(--font-size-base);
@ -42,3 +47,7 @@
.info li.success {
color: var(--brand-alert-green);
}
.info li.error {
color: var(--brand-alert-red);
}

View File

@ -11,7 +11,7 @@ export default function FileInfo({
file: FileMetadata
handleClose(): void
}): ReactElement {
return (
return file.valid ? (
<div className={styles.info}>
<h3 className={styles.url}>{file.url}</h3>
<ul>
@ -23,5 +23,20 @@ export default function FileInfo({
&times;
</button>
</div>
) : (
<div className={`${styles.info} ${!file.valid ? styles.hasError : ''}`}>
<h3 className={styles.url}>{file.url}</h3>
<ul>
<li className={styles.error}>
{' '}
No valid file detected. Check your URL and try again.
</li>
{file.contentLength && <li>{prettySize(+file.contentLength)}</li>}
{file.contentType && <li>{cleanupContentType(file.contentType)}</li>}
</ul>
<button className={styles.removeButton} onClick={handleClose}>
&times;
</button>
</div>
)
}

View File

@ -10,6 +10,7 @@ import { FormPublishData } from 'src/components/Publish/_types'
export default function FilesInput(props: InputProps): ReactElement {
const [field, meta, helpers] = useField(props.name)
const [isInvalidUrl, setIsInvalidUrl] = useState(false)
const [isLoading, setIsLoading] = useState(false)
const { values } = useFormikContext<FormPublishData>()
@ -23,6 +24,7 @@ export default function FilesInput(props: InputProps): ReactElement {
try {
setIsLoading(true)
const checkedFile = await getFileUrlInfo(url, providerUri)
setIsInvalidUrl(!checkedFile[0].valid)
checkedFile && helpers.setValue([{ url, ...checkedFile[0] }])
} catch (error) {
toast.error(
@ -63,16 +65,14 @@ export default function FilesInput(props: InputProps): ReactElement {
return (
<>
{field?.value?.length &&
field.value[0].url !== '' &&
field.value[0].valid ? (
{field.value[0].valid !== undefined ? (
<FileInfo file={field.value[0]} handleClose={handleClose} />
) : (
<UrlInput
submitText="Validate"
{...props}
name={`${field.name}[0].url`}
hasError={Boolean(meta.touched && meta.error)}
hasError={Boolean(meta.touched && isInvalidUrl)}
isLoading={isLoading}
handleButtonClick={handleButtonClick}
/>

View File

@ -41,7 +41,9 @@ export default function URLInput({
<InputGroup>
<InputElement
className={`${styles.input} ${
!isLoading && hasError ? styles.hasError : ''
!isLoading && meta.error !== undefined && meta.touched
? styles.hasError
: ''
}`}
{...props}
{...field}