import React, { Component } from 'react';
import PropTypes from 'prop-types';
import ReactModal from 'react-modal';
import classnames from 'classnames';
import { R_URL_REQUIRES_PROTOCOL } from '../../helpers/constants';
import './Modal.css';
ReactModal.setAppElement('#root');
export default class Modal extends Component {
state = {
url: '',
isUrlValid: false,
};
// eslint-disable-next-line
isUrlValid = url => {
return R_URL_REQUIRES_PROTOCOL.test(url);
};
handleUrlChange = async (e) => {
const { value: url } = e.currentTarget;
if (this.isUrlValid(url)) {
this.setState(...this.state, { url, isUrlValid: true });
} else {
this.setState(...this.state, { url, isUrlValid: false });
}
};
handleNext = () => {
this.props.addFilter(this.state.url);
setTimeout(() => {
if (this.props.isFilterAdded) {
this.props.toggleModal();
}
}, 2000);
};
render() {
const {
isOpen,
toggleModal,
title,
inputDescription,
} = this.props;
const { isUrlValid, url } = this.state;
const inputClass = classnames({
'form-control mb-2': true,
'is-invalid': url.length > 0 && !isUrlValid,
'is-valid': url.length > 0 && isUrlValid,
});
const renderBody = () => {
if (!this.props.isFilterAdded) {
return (