2018-02-07 18:06:07 +00:00
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
import React from 'react';
|
2016-08-30 03:23:10 +00:00
|
|
|
import { reduxForm } from 'redux-form';
|
|
|
|
import NewFolderForm from './NewFolderForm';
|
|
|
|
|
2020-04-29 22:34:37 +00:00
|
|
|
import ExitIcon from '../../../images/exit.svg';
|
2017-02-22 19:29:35 +00:00
|
|
|
|
2016-11-30 00:18:11 +00:00
|
|
|
class NewFolderModal extends React.Component {
|
|
|
|
componentDidMount() {
|
2017-02-22 19:29:35 +00:00
|
|
|
this.newFolderModal.focus();
|
2016-11-30 00:18:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
|
|
|
return (
|
2018-05-09 02:10:52 +00:00
|
|
|
<section className="modal" ref={(element) => { this.newFolderModal = element; }} >
|
2016-11-30 00:18:11 +00:00
|
|
|
<div className="modal-content-folder">
|
|
|
|
<div className="modal__header">
|
2019-09-26 19:06:43 +00:00
|
|
|
<h2 className="modal__title">Create Folder</h2>
|
2020-05-05 23:03:58 +00:00
|
|
|
<button
|
|
|
|
className="modal__exit-button"
|
|
|
|
onClick={this.props.closeModal}
|
|
|
|
aria-label="Close New Folder Modal"
|
|
|
|
>
|
|
|
|
<ExitIcon focusable="false" aria-hidden="true" />
|
2016-11-30 00:18:11 +00:00
|
|
|
</button>
|
|
|
|
</div>
|
|
|
|
<NewFolderForm {...this.props} />
|
2016-08-30 03:23:10 +00:00
|
|
|
</div>
|
2016-11-30 00:18:11 +00:00
|
|
|
</section>
|
|
|
|
);
|
|
|
|
}
|
2016-08-30 03:23:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NewFolderModal.propTypes = {
|
|
|
|
closeModal: PropTypes.func.isRequired
|
|
|
|
};
|
|
|
|
|
2018-10-22 19:41:35 +00: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';
|
2019-07-17 16:30:26 +00:00
|
|
|
} else if (formProps.name.match(/\.+/i)) {
|
|
|
|
errors.name = 'Folder name cannot contain an extension';
|
2018-10-22 19:41:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return errors;
|
|
|
|
}
|
2016-08-30 03:23:10 +00:00
|
|
|
export default reduxForm({
|
|
|
|
form: 'new-folder',
|
2018-10-22 19:41:35 +00:00
|
|
|
fields: ['name'],
|
|
|
|
validate
|
2016-08-30 03:23:10 +00:00
|
|
|
})(NewFolderModal);
|