import React from 'react'; import PropTypes from 'prop-types'; import { Modal, ModalBody, Form } from 'reactstrap'; import { gettext, siteRoot, mediaUrl } from '../../utils/constants'; import { seafileAPI } from '../../utils/seafile-api'; import SeahubModalCloseIcon from '../../components/common/seahub-modal-close'; import '../../css/lib-decrypt.css'; const propTypes = { repoID: PropTypes.string.isRequired, onLibDecryptDialog: PropTypes.func.isRequired }; class LibDecryptDialog extends React.Component { constructor(props) { super(props); this.state = { password: '', showError: false, }; } handleSubmit = (e) => { let repoID = this.props.repoID; let password = this.state.password; seafileAPI.setRepoDecryptPassword(repoID, password).then(res => { this.props.onLibDecryptDialog(); }).catch(res => { this.setState({ showError: true }); }); e.preventDefault(); }; handleKeyDown = (e) => { if (e.key == 'Enter') { this.handleSubmit(e); } }; handleChange = (e) => { this.setState({ password: e.target.value, showError: false }); }; toggle = () => { window.location.href = siteRoot; }; render() { return (

{gettext('This library is password protected')}

{this.state.showError &&

{gettext('Wrong password')}

}

{'* '}{gettext('The password will be kept in the server for only 1 hour.')}

); } } LibDecryptDialog.propTypes = propTypes; export default LibDecryptDialog;