2016-07-13 20:13:28 +00:00
|
|
|
import React, { PropTypes } from 'react';
|
|
|
|
import { reduxForm } from 'redux-form';
|
|
|
|
import NewFileForm from './NewFileForm';
|
|
|
|
import classNames from 'classnames';
|
|
|
|
import InlineSVG from 'react-inlinesvg';
|
|
|
|
const exitUrl = require('../../../images/exit.svg');
|
|
|
|
|
2016-07-15 23:05:18 +00:00
|
|
|
import FileUploader from './FileUploader';
|
|
|
|
|
2016-07-13 20:13:28 +00:00
|
|
|
// At some point this will probably be generalized to a generic modal
|
|
|
|
// in which you can insert different content
|
|
|
|
// but for now, let's just make this work
|
2016-08-30 03:23:10 +00:00
|
|
|
function NewFileModal(props) {
|
|
|
|
const modalClass = classNames({
|
|
|
|
modal: true,
|
|
|
|
'modal--reduced': !props.canUploadMedia
|
|
|
|
});
|
|
|
|
return (
|
|
|
|
<section className={modalClass}>
|
|
|
|
<div className="modal-content">
|
|
|
|
<div className="modal__header">
|
|
|
|
<h2 className="modal__title">Add File</h2>
|
|
|
|
<button className="modal__exit-button" onClick={props.closeModal}>
|
|
|
|
<InlineSVG src={exitUrl} alt="Close New File Modal" />
|
|
|
|
</button>
|
2016-07-13 20:13:28 +00:00
|
|
|
</div>
|
2016-08-30 03:23:10 +00:00
|
|
|
<NewFileForm {...props} />
|
|
|
|
{(() => {
|
|
|
|
if (props.canUploadMedia) {
|
|
|
|
return (
|
|
|
|
<div>
|
|
|
|
<p className="modal__divider">OR</p>
|
|
|
|
<FileUploader />
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
return '';
|
|
|
|
})()}
|
|
|
|
</div>
|
|
|
|
</section>
|
|
|
|
);
|
2016-07-13 20:13:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NewFileModal.propTypes = {
|
2016-07-21 02:18:20 +00:00
|
|
|
closeModal: PropTypes.func.isRequired,
|
|
|
|
canUploadMedia: PropTypes.bool.isRequired
|
2016-07-13 20:13:28 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
function validate(formProps) {
|
|
|
|
const errors = {};
|
|
|
|
|
|
|
|
if (!formProps.name) {
|
|
|
|
errors.name = 'Please enter a name';
|
2016-10-22 20:42:43 +00:00
|
|
|
} else if (!formProps.name.match(/(.+\.js$|.+\.css$|.+\.json$|.+\.txt$)/i)) {
|
2016-10-22 19:23:37 +00:00
|
|
|
errors.name = 'File must be of type JavaScript, CSS, JSON, or TXT.';
|
2016-07-13 20:13:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return errors;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
export default reduxForm({
|
|
|
|
form: 'new-file',
|
|
|
|
fields: ['name'],
|
|
|
|
validate
|
2016-08-30 18:39:37 +00:00
|
|
|
})(NewFileModal);
|