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';
|
2020-08-11 13:56:45 +00:00
|
|
|
import { withTranslation } from 'react-i18next';
|
|
|
|
import i18n from 'i18next';
|
2016-08-30 03:23:10 +00:00
|
|
|
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">
|
2020-08-11 13:56:45 +00:00
|
|
|
<h2 className="modal__title">{this.props.t('NewFolderModal.Title')}</h2>
|
2020-05-05 23:03:58 +00:00
|
|
|
<button
|
|
|
|
className="modal__exit-button"
|
|
|
|
onClick={this.props.closeModal}
|
2020-08-11 13:56:45 +00:00
|
|
|
aria-label={this.props.t('NewFolderModal.CloseButtonARIA')}
|
2020-05-05 23:03:58 +00:00
|
|
|
>
|
|
|
|
<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 = {
|
2020-08-11 13:56:45 +00:00
|
|
|
closeModal: PropTypes.func.isRequired,
|
|
|
|
t: PropTypes.func.isRequired
|
2016-08-30 03:23:10 +00:00
|
|
|
};
|
|
|
|
|
2018-10-22 19:41:35 +00:00
|
|
|
function validate(formProps) {
|
|
|
|
const errors = {};
|
|
|
|
if (!formProps.name) {
|
2020-08-11 13:56:45 +00:00
|
|
|
errors.name = i18n.t('NewFolderModal.EnterName');
|
2018-10-22 19:41:35 +00:00
|
|
|
} else if (formProps.name.trim().length === 0) {
|
2020-08-11 13:56:45 +00:00
|
|
|
errors.name = i18n.t('NewFolderModal.EmptyName');
|
2019-07-17 16:30:26 +00:00
|
|
|
} else if (formProps.name.match(/\.+/i)) {
|
2020-08-11 13:56:45 +00:00
|
|
|
errors.name = i18n.t('NewFolderModal.InvalidExtension');
|
2018-10-22 19:41:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return errors;
|
|
|
|
}
|
2020-08-11 13:56:45 +00:00
|
|
|
export default withTranslation()(reduxForm({
|
2016-08-30 03:23:10 +00:00
|
|
|
form: 'new-folder',
|
2018-10-22 19:41:35 +00:00
|
|
|
fields: ['name'],
|
|
|
|
validate
|
2020-08-11 13:56:45 +00:00
|
|
|
})(NewFolderModal));
|