1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-07-20 10:00:00 +00:00
seahub/frontend/src/components/dialog/terms-editor-dialog.js

82 lines
2.0 KiB
JavaScript
Raw Normal View History

import React from 'react';
import PropTypes from 'prop-types';
import { Modal, ModalHeader, ModalBody } from 'reactstrap';
import { SimpleEditor } from '@seafile/seafile-editor';
import { gettext } from '../../utils/constants';
const propTypes = {
title: PropTypes.string,
content: PropTypes.string,
onCommit: PropTypes.func.isRequired,
onCloseEditorDialog: PropTypes.func.isRequired,
};
class TermsEditorDialog extends React.Component {
2023-12-07 06:20:29 +00:00
constructor(props) {
super(props);
this.state = {
isValueChanged: false,
};
this.editorRef = React.createRef();
}
static defaultProps = {
title: gettext('Terms'),
};
onKeyDown = (event) => {
event.stopPropagation();
};
toggle = () => {
2023-12-07 06:20:29 +00:00
const { isValueChanged } = this.state;
if (isValueChanged) {
let currentContent = this.getCurrentContent();
this.props.onCommit(currentContent);
}
this.props.onCloseEditorDialog();
};
2023-12-08 07:19:00 +00:00
onContentChanged = () => {
2024-07-18 03:58:42 +00:00
return this.setState({ isValueChanged: true });
};
getCurrentContent = () => {
2023-12-07 06:20:29 +00:00
return this.editorRef.current.getValue();
};
setSimpleEditorRef = (editor) => {
this.simpleEditor = editor;
};
render() {
let { content, title } = this.props;
return (
<Modal
isOpen={true}
toggle={this.toggle}
onKeyDown={this.onKeyDown}
wrapClassName={'conditions-editor-dialog-wrapper'}
className={'conditions-editor-dialog'}
contentClassName={'conditions-editor-dialog-content'}
size={'lg'}
2024-07-18 03:58:42 +00:00
style={{ width: 770 }}
>
<ModalHeader className="conditions-editor-dialog-title" toggle={this.toggle}>{title}</ModalHeader>
<ModalBody className={'conditions-editor-dialog-main'}>
<SimpleEditor
2023-12-07 06:20:29 +00:00
ref={this.editorRef}
value={content || ''}
2023-12-08 07:19:00 +00:00
onContentChanged={this.onContentChanged}
/>
</ModalBody>
</Modal>
);
}
}
TermsEditorDialog.propTypes = propTypes;
export default TermsEditorDialog;