diff --git a/client/src/actions/index.js b/client/src/actions/index.js index 7a28a600..396f9136 100644 --- a/client/src/actions/index.js +++ b/client/src/actions/index.js @@ -398,10 +398,10 @@ export const addFilterRequest = createAction('ADD_FILTER_REQUEST'); export const addFilterFailure = createAction('ADD_FILTER_FAILURE'); export const addFilterSuccess = createAction('ADD_FILTER_SUCCESS'); -export const addFilter = url => async (dispatch) => { +export const addFilter = (url, name) => async (dispatch) => { dispatch(addFilterRequest()); try { - await apiClient.addFilter(url); + await apiClient.addFilter(url, name); dispatch(addFilterSuccess(url)); dispatch(getFilteringStatus()); } catch (error) { diff --git a/client/src/api/Api.js b/client/src/api/Api.js index 636b0ddd..f24d8add 100644 --- a/client/src/api/Api.js +++ b/client/src/api/Api.js @@ -167,10 +167,11 @@ export default class Api { return this.makeRequest(path, method); } - addFilter(url) { + addFilter(url, name) { const { path, method } = this.FILTERING_ADD_FILTER; - const parameter = 'url'; - const requestBody = `${parameter}=${url}`; + const urlParameter = 'url'; + const nameParameter = 'name'; + const requestBody = `${urlParameter}=${url}&${nameParameter}=${name}`; const config = { data: requestBody, header: { 'Content-Type': 'text/plain' }, diff --git a/client/src/components/ui/Modal.js b/client/src/components/ui/Modal.js index 3b39e52a..cc7cca25 100644 --- a/client/src/components/ui/Modal.js +++ b/client/src/components/ui/Modal.js @@ -7,11 +7,14 @@ import './Modal.css'; ReactModal.setAppElement('#root'); +const initialState = { + url: '', + name: '', + isUrlValid: false, +}; + export default class Modal extends Component { - state = { - url: '', - isUrlValid: false, - }; + state = initialState; // eslint-disable-next-line isUrlValid = url => { @@ -27,33 +30,48 @@ export default class Modal extends Component { } }; + handleNameChange = (e) => { + const { value: name } = e.currentTarget; + this.setState({ ...this.state, name }); + }; + handleNext = () => { - this.props.addFilter(this.state.url); + this.props.addFilter(this.state.url, this.state.name); setTimeout(() => { if (this.props.isFilterAdded) { - this.props.toggleModal(); + this.closeModal(); } }, 2000); }; + + closeModal = () => { + this.props.toggleModal(); + this.setState({ ...this.state, ...initialState }); + } + render() { const { isOpen, - toggleModal, title, inputDescription, } = this.props; - const { isUrlValid, url } = this.state; - const inputClass = classnames({ + const { isUrlValid, url, name } = this.state; + const inputUrlClass = classnames({ 'form-control mb-2': true, 'is-invalid': url.length > 0 && !isUrlValid, 'is-valid': url.length > 0 && isUrlValid, }); + const inputNameClass = classnames({ + 'form-control mb-2': true, + 'is-valid': name.length > 0, + }); const renderBody = () => { if (!this.props.isFilterAdded) { return ( - + + {inputDescription &&
{inputDescription} @@ -68,21 +86,21 @@ export default class Modal extends Component { ); }; - const isValidForSubmit = !(url.length > 0 && isUrlValid); + const isValidForSubmit = !(url.length > 0 && isUrlValid && name.length > 0); return (

{title}

-
@@ -92,7 +110,7 @@ export default class Modal extends Component { { !this.props.isFilterAdded &&
- +
}