Add name field to the filter subscription dialog
This commit is contained in:
parent
8cf898e8d9
commit
5be66e7dc7
|
@ -398,10 +398,10 @@ export const addFilterRequest = createAction('ADD_FILTER_REQUEST');
|
||||||
export const addFilterFailure = createAction('ADD_FILTER_FAILURE');
|
export const addFilterFailure = createAction('ADD_FILTER_FAILURE');
|
||||||
export const addFilterSuccess = createAction('ADD_FILTER_SUCCESS');
|
export const addFilterSuccess = createAction('ADD_FILTER_SUCCESS');
|
||||||
|
|
||||||
export const addFilter = url => async (dispatch) => {
|
export const addFilter = (url, name) => async (dispatch) => {
|
||||||
dispatch(addFilterRequest());
|
dispatch(addFilterRequest());
|
||||||
try {
|
try {
|
||||||
await apiClient.addFilter(url);
|
await apiClient.addFilter(url, name);
|
||||||
dispatch(addFilterSuccess(url));
|
dispatch(addFilterSuccess(url));
|
||||||
dispatch(getFilteringStatus());
|
dispatch(getFilteringStatus());
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|
|
@ -167,10 +167,11 @@ export default class Api {
|
||||||
return this.makeRequest(path, method);
|
return this.makeRequest(path, method);
|
||||||
}
|
}
|
||||||
|
|
||||||
addFilter(url) {
|
addFilter(url, name) {
|
||||||
const { path, method } = this.FILTERING_ADD_FILTER;
|
const { path, method } = this.FILTERING_ADD_FILTER;
|
||||||
const parameter = 'url';
|
const urlParameter = 'url';
|
||||||
const requestBody = `${parameter}=${url}`;
|
const nameParameter = 'name';
|
||||||
|
const requestBody = `${urlParameter}=${url}&${nameParameter}=${name}`;
|
||||||
const config = {
|
const config = {
|
||||||
data: requestBody,
|
data: requestBody,
|
||||||
header: { 'Content-Type': 'text/plain' },
|
header: { 'Content-Type': 'text/plain' },
|
||||||
|
|
|
@ -7,11 +7,14 @@ import './Modal.css';
|
||||||
|
|
||||||
ReactModal.setAppElement('#root');
|
ReactModal.setAppElement('#root');
|
||||||
|
|
||||||
|
const initialState = {
|
||||||
|
url: '',
|
||||||
|
name: '',
|
||||||
|
isUrlValid: false,
|
||||||
|
};
|
||||||
|
|
||||||
export default class Modal extends Component {
|
export default class Modal extends Component {
|
||||||
state = {
|
state = initialState;
|
||||||
url: '',
|
|
||||||
isUrlValid: false,
|
|
||||||
};
|
|
||||||
|
|
||||||
// eslint-disable-next-line
|
// eslint-disable-next-line
|
||||||
isUrlValid = url => {
|
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 = () => {
|
handleNext = () => {
|
||||||
this.props.addFilter(this.state.url);
|
this.props.addFilter(this.state.url, this.state.name);
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
if (this.props.isFilterAdded) {
|
if (this.props.isFilterAdded) {
|
||||||
this.props.toggleModal();
|
this.closeModal();
|
||||||
}
|
}
|
||||||
}, 2000);
|
}, 2000);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
closeModal = () => {
|
||||||
|
this.props.toggleModal();
|
||||||
|
this.setState({ ...this.state, ...initialState });
|
||||||
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const {
|
const {
|
||||||
isOpen,
|
isOpen,
|
||||||
toggleModal,
|
|
||||||
title,
|
title,
|
||||||
inputDescription,
|
inputDescription,
|
||||||
} = this.props;
|
} = this.props;
|
||||||
const { isUrlValid, url } = this.state;
|
const { isUrlValid, url, name } = this.state;
|
||||||
const inputClass = classnames({
|
const inputUrlClass = classnames({
|
||||||
'form-control mb-2': true,
|
'form-control mb-2': true,
|
||||||
'is-invalid': url.length > 0 && !isUrlValid,
|
'is-invalid': url.length > 0 && !isUrlValid,
|
||||||
'is-valid': 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 = () => {
|
const renderBody = () => {
|
||||||
if (!this.props.isFilterAdded) {
|
if (!this.props.isFilterAdded) {
|
||||||
return (
|
return (
|
||||||
<React.Fragment>
|
<React.Fragment>
|
||||||
<input type="text" className={inputClass} placeholder="Enter URL or path" onChange={this.handleUrlChange}/>
|
<input type="text" className={inputNameClass} placeholder="Enter name" onChange={this.handleNameChange} />
|
||||||
|
<input type="text" className={inputUrlClass} placeholder="Enter URL" onChange={this.handleUrlChange} />
|
||||||
{inputDescription &&
|
{inputDescription &&
|
||||||
<div className="description">
|
<div className="description">
|
||||||
{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 (
|
return (
|
||||||
<ReactModal
|
<ReactModal
|
||||||
className="Modal__Bootstrap modal-dialog modal-dialog-centered"
|
className="Modal__Bootstrap modal-dialog modal-dialog-centered"
|
||||||
closeTimeoutMS={0}
|
closeTimeoutMS={0}
|
||||||
isOpen={ isOpen }
|
isOpen={ isOpen }
|
||||||
onRequestClose={toggleModal}
|
onRequestClose={this.closeModal}
|
||||||
>
|
>
|
||||||
<div className="modal-content">
|
<div className="modal-content">
|
||||||
<div className="modal-header">
|
<div className="modal-header">
|
||||||
<h4 className="modal-title">
|
<h4 className="modal-title">
|
||||||
{title}
|
{title}
|
||||||
</h4>
|
</h4>
|
||||||
<button type="button" className="close" onClick={toggleModal}>
|
<button type="button" className="close" onClick={this.closeModal}>
|
||||||
<span className="sr-only">Close</span>
|
<span className="sr-only">Close</span>
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
|
@ -92,7 +110,7 @@ export default class Modal extends Component {
|
||||||
{
|
{
|
||||||
!this.props.isFilterAdded &&
|
!this.props.isFilterAdded &&
|
||||||
<div className="modal-footer">
|
<div className="modal-footer">
|
||||||
<button type="button" className="btn btn-secondary" onClick={toggleModal}>Cancel</button>
|
<button type="button" className="btn btn-secondary" onClick={this.closeModal}>Cancel</button>
|
||||||
<button type="button" className="btn btn-success" onClick={this.handleNext} disabled={isValidForSubmit}>Add filter</button>
|
<button type="button" className="btn btn-success" onClick={this.handleNext} disabled={isValidForSubmit}>Add filter</button>
|
||||||
</div>
|
</div>
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue