-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathnew-view-dialog.js
More file actions
70 lines (61 loc) · 2 KB
/
Copy pathnew-view-dialog.js
File metadata and controls
70 lines (61 loc) · 2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import React from 'react';
import PropTypes from 'prop-types';
import { Modal, ModalBody, ModalFooter, Form, FormGroup, Label, Input, Alert, Button } from 'reactstrap';
import intl from 'react-intl-universal';
import { DTableModalHeader } from 'dtable-ui-component';
const propTypes = {
onNewViewConfirm: PropTypes.func,
onNewViewCancel: PropTypes.func,
};
class NewViewDialog extends React.Component {
constructor(props) {
super(props);
this.state = {
viewName: '',
errMessage: '',
};
}
handleChange = (event) => {
let value = event.target.value;
if (value === this.state.viewName) {
return;
}
this.setState({ viewName: value });
};
toggle = () => {
this.props.onNewViewCancel();
};
handleSubmit = () => {
let { viewName } = this.state;
viewName = viewName.trim();
if (!viewName) {
this.setState({ errMessage: 'Name_is_required' });
return;
}
this.props.onNewViewConfirm(viewName);
this.props.onNewViewCancel();
};
render() {
return (
<Modal isOpen={true} toggle={this.toggle} autoFocus={false}>
<DTableModalHeader toggle={this.toggle}>{intl.get('New_view')}</DTableModalHeader>
<ModalBody>
<Form>
<FormGroup>
<Label for="viewName">{intl.get('Name')}</Label>
<Input id="viewName" value={this.state.viewName} innerRef={input => {this.newInput = input;}} onChange={this.handleChange} autoFocus={true} />
<Input style={{ display: 'none' }} />
</FormGroup>
</Form>
{this.state.errMessage && <Alert color="danger" className="mt-2">{intl.get(this.state.errMessage)}</Alert>}
</ModalBody>
<ModalFooter>
<Button color="secondary" onClick={this.toggle}>{intl.get('Cancel')}</Button>
<Button color="primary" onClick={this.handleSubmit}>{intl.get('Submit')}</Button>
</ModalFooter>
</Modal>
);
}
}
NewViewDialog.propTypes = propTypes;
export default NewViewDialog;