2018-02-07 19:06:07 +01:00
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
import React from 'react';
|
2016-08-30 05:23:10 +02:00
|
|
|
import { reduxForm } from 'redux-form';
|
|
|
|
import InlineSVG from 'react-inlinesvg';
|
|
|
|
import NewFolderForm from './NewFolderForm';
|
|
|
|
|
2017-02-22 20:29:35 +01:00
|
|
|
const exitUrl = require('../../../images/exit.svg');
|
|
|
|
|
2016-11-30 01:18:11 +01:00
|
|
|
class NewFolderModal extends React.Component {
|
|
|
|
componentDidMount() {
|
2017-02-22 20:29:35 +01:00
|
|
|
this.newFolderModal.focus();
|
2016-11-30 01:18:11 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
|
|
|
return (
|
2018-05-09 04:10:52 +02:00
|
|
|
<section className="modal" ref={(element) => { this.newFolderModal = element; }} >
|
2016-11-30 01:18:11 +01:00
|
|
|
<div className="modal-content-folder">
|
|
|
|
<div className="modal__header">
|
|
|
|
<h2 className="modal__title">Add Folder</h2>
|
|
|
|
<button className="modal__exit-button" onClick={this.props.closeModal}>
|
|
|
|
<InlineSVG src={exitUrl} alt="Close New Folder Modal" />
|
|
|
|
</button>
|
|
|
|
</div>
|
|
|
|
<NewFolderForm {...this.props} />
|
2016-08-30 05:23:10 +02:00
|
|
|
</div>
|
2016-11-30 01:18:11 +01:00
|
|
|
</section>
|
|
|
|
);
|
|
|
|
}
|
2016-08-30 05:23:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
NewFolderModal.propTypes = {
|
|
|
|
closeModal: PropTypes.func.isRequired
|
|
|
|
};
|
|
|
|
|
2018-10-22 21:41:35 +02:00
|
|
|
function validate(formProps) {
|
|
|
|
const errors = {};
|
|
|
|
if (!formProps.name) {
|
|
|
|
errors.name = 'Please enter a name';
|
|
|
|
} else if (formProps.name.trim().length === 0) {
|
|
|
|
errors.name = 'Folder name cannot contain only spaces';
|
|
|
|
}
|
|
|
|
|
|
|
|
return errors;
|
|
|
|
}
|
2016-08-30 05:23:10 +02:00
|
|
|
export default reduxForm({
|
|
|
|
form: 'new-folder',
|
2018-10-22 21:41:35 +02:00
|
|
|
fields: ['name'],
|
|
|
|
validate
|
2016-08-30 05:23:10 +02:00
|
|
|
})(NewFolderModal);
|