1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-08-09 19:07:40 +00:00
seahub/frontend/src/lib/add-image-dialog.js

48 lines
1.5 KiB
JavaScript
Raw Normal View History

2018-05-02 06:09:58 +00:00
import React from 'react';
import { Button, Modal, ModalHeader, ModalBody, ModalFooter } from 'reactstrap';
import validUrl from 'valid-url';
2018-06-07 07:01:41 +00:00
import { translate } from "react-i18next";
2018-05-02 06:09:58 +00:00
class AddImageDialog extends React.Component {
state = {
url: '',
error: null
};
handleUrlChange = (event) => {
this.setState({url: event.target.value});
}
handleSubmit = (event) => {
if (validUrl.isUri(this.state.url)) {
this.props.toggleImageDialog();
this.props.onInsertImage(this.state.url);
} else {
this.setState({error: this.props.t('invalid_url')});
}
}
render() {
return (
<Modal isOpen={this.props.showAddImageDialog} toggle={this.props.toggleImageDialog} className={this.props.className}>
<ModalHeader toggle={this.props.toggleImageDialog}>{this.props.t("insert_image")}</ModalHeader>
<ModalBody>
<p>{this.props.t("enter_the_url_of_the_image")}:</p>
<input type="url" value={this.state.value} onChange={this.handleUrlChange} />
{this.state.error &&
<p className="text-danger">{this.state.error}</p>
}
</ModalBody>
<ModalFooter>
<Button color="primary" onClick={this.handleSubmit}>{this.props.t("submit")}</Button>{' '}
<Button color="secondary" onClick={this.props.toggleImageDialog}>{this.props.t("cancel")}</Button>
</ModalFooter>
</Modal>
)
}
}
2018-06-07 07:01:41 +00:00
export default translate("translations")(AddImageDialog);