mirror of
https://github.com/oceanprotocol/market.git
synced 2024-12-02 05:57:29 +01:00
* 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>
43 lines
1.3 KiB
TypeScript
43 lines
1.3 KiB
TypeScript
import React, { ReactElement } from 'react'
|
|
import { prettySize } from './utils'
|
|
import cleanupContentType from '@utils/cleanupContentType'
|
|
import styles from './Info.module.css'
|
|
import { FileMetadata } from '@oceanprotocol/lib'
|
|
|
|
export default function FileInfo({
|
|
file,
|
|
handleClose
|
|
}: {
|
|
file: FileMetadata
|
|
handleClose(): void
|
|
}): ReactElement {
|
|
return file.valid ? (
|
|
<div className={styles.info}>
|
|
<h3 className={styles.url}>{file.url}</h3>
|
|
<ul>
|
|
<li className={styles.success}>✓ URL confirmed</li>
|
|
{file.contentLength && <li>{prettySize(+file.contentLength)}</li>}
|
|
{file.contentType && <li>{cleanupContentType(file.contentType)}</li>}
|
|
</ul>
|
|
<button className={styles.removeButton} onClick={handleClose}>
|
|
×
|
|
</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}>
|
|
×
|
|
</button>
|
|
</div>
|
|
)
|
|
}
|