p5.js-web-editor/client/modules/IDE/components/NewFolderModal.jsx

52 lines
1.4 KiB
React
Raw Normal View History

import PropTypes from 'prop-types';
import React from 'react';
2016-08-30 03:23:10 +00:00
import { reduxForm } from 'redux-form';
import InlineSVG from 'react-inlinesvg';
import NewFolderForm from './NewFolderForm';
const exitUrl = require('../../../images/exit.svg');
class NewFolderModal extends React.Component {
componentDidMount() {
this.newFolderModal.focus();
}
render() {
return (
2018-05-09 02:10:52 +00:00
<section className="modal" ref={(element) => { this.newFolderModal = element; }} >
<div className="modal-content-folder">
<div className="modal__header">
<h2 className="modal__title">Create 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 03:23:10 +00:00
</div>
</section>
);
}
2016-08-30 03:23:10 +00:00
}
NewFolderModal.propTypes = {
closeModal: PropTypes.func.isRequired
};
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';
} else if (formProps.name.match(/\.+/i)) {
errors.name = 'Folder name cannot contain an extension';
}
return errors;
}
2016-08-30 03:23:10 +00:00
export default reduxForm({
form: 'new-folder',
fields: ['name'],
validate
2016-08-30 03:23:10 +00:00
})(NewFolderModal);