mirror of
https://github.com/oceanprotocol/market.git
synced 2024-12-02 05:57:29 +01: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:
parent
6e2e46d8ea
commit
90f841bb13
@ -6,6 +6,11 @@
|
|||||||
position: relative;
|
position: relative;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.hasError {
|
||||||
|
border-color: var(--brand-alert-red);
|
||||||
|
background-color: var(--brand-white);
|
||||||
|
}
|
||||||
|
|
||||||
.url {
|
.url {
|
||||||
margin: 0;
|
margin: 0;
|
||||||
font-size: var(--font-size-base);
|
font-size: var(--font-size-base);
|
||||||
@ -42,3 +47,7 @@
|
|||||||
.info li.success {
|
.info li.success {
|
||||||
color: var(--brand-alert-green);
|
color: var(--brand-alert-green);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.info li.error {
|
||||||
|
color: var(--brand-alert-red);
|
||||||
|
}
|
||||||
|
@ -11,7 +11,7 @@ export default function FileInfo({
|
|||||||
file: FileMetadata
|
file: FileMetadata
|
||||||
handleClose(): void
|
handleClose(): void
|
||||||
}): ReactElement {
|
}): ReactElement {
|
||||||
return (
|
return file.valid ? (
|
||||||
<div className={styles.info}>
|
<div className={styles.info}>
|
||||||
<h3 className={styles.url}>{file.url}</h3>
|
<h3 className={styles.url}>{file.url}</h3>
|
||||||
<ul>
|
<ul>
|
||||||
@ -23,5 +23,20 @@ export default function FileInfo({
|
|||||||
×
|
×
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</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>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -10,6 +10,7 @@ import { FormPublishData } from 'src/components/Publish/_types'
|
|||||||
|
|
||||||
export default function FilesInput(props: InputProps): ReactElement {
|
export default function FilesInput(props: InputProps): ReactElement {
|
||||||
const [field, meta, helpers] = useField(props.name)
|
const [field, meta, helpers] = useField(props.name)
|
||||||
|
const [isInvalidUrl, setIsInvalidUrl] = useState(false)
|
||||||
const [isLoading, setIsLoading] = useState(false)
|
const [isLoading, setIsLoading] = useState(false)
|
||||||
const { values } = useFormikContext<FormPublishData>()
|
const { values } = useFormikContext<FormPublishData>()
|
||||||
|
|
||||||
@ -23,6 +24,7 @@ export default function FilesInput(props: InputProps): ReactElement {
|
|||||||
try {
|
try {
|
||||||
setIsLoading(true)
|
setIsLoading(true)
|
||||||
const checkedFile = await getFileUrlInfo(url, providerUri)
|
const checkedFile = await getFileUrlInfo(url, providerUri)
|
||||||
|
setIsInvalidUrl(!checkedFile[0].valid)
|
||||||
checkedFile && helpers.setValue([{ url, ...checkedFile[0] }])
|
checkedFile && helpers.setValue([{ url, ...checkedFile[0] }])
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
toast.error(
|
toast.error(
|
||||||
@ -63,16 +65,14 @@ export default function FilesInput(props: InputProps): ReactElement {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
{field?.value?.length &&
|
{field.value[0].valid !== undefined ? (
|
||||||
field.value[0].url !== '' &&
|
|
||||||
field.value[0].valid ? (
|
|
||||||
<FileInfo file={field.value[0]} handleClose={handleClose} />
|
<FileInfo file={field.value[0]} handleClose={handleClose} />
|
||||||
) : (
|
) : (
|
||||||
<UrlInput
|
<UrlInput
|
||||||
submitText="Validate"
|
submitText="Validate"
|
||||||
{...props}
|
{...props}
|
||||||
name={`${field.name}[0].url`}
|
name={`${field.name}[0].url`}
|
||||||
hasError={Boolean(meta.touched && meta.error)}
|
hasError={Boolean(meta.touched && isInvalidUrl)}
|
||||||
isLoading={isLoading}
|
isLoading={isLoading}
|
||||||
handleButtonClick={handleButtonClick}
|
handleButtonClick={handleButtonClick}
|
||||||
/>
|
/>
|
||||||
|
@ -41,7 +41,9 @@ export default function URLInput({
|
|||||||
<InputGroup>
|
<InputGroup>
|
||||||
<InputElement
|
<InputElement
|
||||||
className={`${styles.input} ${
|
className={`${styles.input} ${
|
||||||
!isLoading && hasError ? styles.hasError : ''
|
!isLoading && meta.error !== undefined && meta.touched
|
||||||
|
? styles.hasError
|
||||||
|
: ''
|
||||||
}`}
|
}`}
|
||||||
{...props}
|
{...props}
|
||||||
{...field}
|
{...field}
|
||||||
|
Loading…
Reference in New Issue
Block a user