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

58 lines
1.6 KiB
React
Raw Permalink Normal View History

import PropTypes from 'prop-types';
import React from 'react';
2016-08-30 05:23:10 +02:00
import { reduxForm } from 'redux-form';
import { withTranslation } from 'react-i18next';
import i18n from 'i18next';
2016-08-30 05:23:10 +02:00
import NewFolderForm from './NewFolderForm';
2020-04-30 00:34:37 +02:00
import ExitIcon from '../../../images/exit.svg';
class NewFolderModal extends React.Component {
componentDidMount() {
this.newFolderModal.focus();
}
render() {
return (
2018-05-09 04:10:52 +02:00
<section className="modal" ref={(element) => { this.newFolderModal = element; }} >
<div className="modal-content-folder">
<div className="modal__header">
<h2 className="modal__title">{this.props.t('NewFolderModal.Title')}</h2>
<button
className="modal__exit-button"
onClick={this.props.closeModal}
aria-label={this.props.t('NewFolderModal.CloseButtonARIA')}
>
<ExitIcon focusable="false" aria-hidden="true" />
</button>
</div>
<NewFolderForm {...this.props} />
2016-08-30 05:23:10 +02:00
</div>
</section>
);
}
2016-08-30 05:23:10 +02:00
}
NewFolderModal.propTypes = {
closeModal: PropTypes.func.isRequired,
t: PropTypes.func.isRequired
2016-08-30 05:23:10 +02:00
};
function validate(formProps) {
const errors = {};
if (!formProps.name) {
errors.name = i18n.t('NewFolderModal.EnterName');
} else if (formProps.name.trim().length === 0) {
errors.name = i18n.t('NewFolderModal.EmptyName');
} else if (formProps.name.match(/\.+/i)) {
errors.name = i18n.t('NewFolderModal.InvalidExtension');
}
return errors;
}
export default withTranslation()(reduxForm({
2016-08-30 05:23:10 +02:00
form: 'new-folder',
fields: ['name'],
validate
})(NewFolderModal));