2018-02-07 19:06:07 +01:00
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
import React from 'react';
|
2016-08-30 05:23:10 +02:00
|
|
|
import { reduxForm } from 'redux-form';
|
2020-08-11 15:56:45 +02:00
|
|
|
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';
|
2017-02-22 20:29:35 +01:00
|
|
|
|
2016-11-30 01:18:11 +01:00
|
|
|
class NewFolderModal extends React.Component {
|
|
|
|
componentDidMount() {
|
2017-02-22 20:29:35 +01:00
|
|
|
this.newFolderModal.focus();
|
2016-11-30 01:18:11 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
|
|
|
return (
|
2018-05-09 04:10:52 +02:00
|
|
|
<section className="modal" ref={(element) => { this.newFolderModal = element; }} >
|
2016-11-30 01:18:11 +01:00
|
|
|
<div className="modal-content-folder">
|
|
|
|
<div className="modal__header">
|
2020-08-11 15:56:45 +02:00
|
|
|
<h2 className="modal__title">{this.props.t('NewFolderModal.Title')}</h2>
|
2020-05-06 01:03:58 +02:00
|
|
|
<button
|
|
|
|
className="modal__exit-button"
|
|
|
|
onClick={this.props.closeModal}
|
2020-08-11 15:56:45 +02:00
|
|
|
aria-label={this.props.t('NewFolderModal.CloseButtonARIA')}
|
2020-05-06 01:03:58 +02:00
|
|
|
>
|
|
|
|
<ExitIcon focusable="false" aria-hidden="true" />
|
2016-11-30 01:18:11 +01:00
|
|
|
</button>
|
|
|
|
</div>
|
|
|
|
<NewFolderForm {...this.props} />
|
2016-08-30 05:23:10 +02:00
|
|
|
</div>
|
2016-11-30 01:18:11 +01:00
|
|
|
</section>
|
|
|
|
);
|
|
|
|
}
|
2016-08-30 05:23:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
NewFolderModal.propTypes = {
|
2020-08-11 15:56:45 +02:00
|
|
|
closeModal: PropTypes.func.isRequired,
|
|
|
|
t: PropTypes.func.isRequired
|
2016-08-30 05:23:10 +02:00
|
|
|
};
|
|
|
|
|
2018-10-22 21:41:35 +02:00
|
|
|
function validate(formProps) {
|
|
|
|
const errors = {};
|
|
|
|
if (!formProps.name) {
|
2020-08-11 15:56:45 +02:00
|
|
|
errors.name = i18n.t('NewFolderModal.EnterName');
|
2018-10-22 21:41:35 +02:00
|
|
|
} else if (formProps.name.trim().length === 0) {
|
2020-08-11 15:56:45 +02:00
|
|
|
errors.name = i18n.t('NewFolderModal.EmptyName');
|
2019-07-17 18:30:26 +02:00
|
|
|
} else if (formProps.name.match(/\.+/i)) {
|
2020-08-11 15:56:45 +02:00
|
|
|
errors.name = i18n.t('NewFolderModal.InvalidExtension');
|
2018-10-22 21:41:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return errors;
|
|
|
|
}
|
2020-08-11 15:56:45 +02:00
|
|
|
export default withTranslation()(reduxForm({
|
2016-08-30 05:23:10 +02:00
|
|
|
form: 'new-folder',
|
2018-10-22 21:41:35 +02:00
|
|
|
fields: ['name'],
|
|
|
|
validate
|
2020-08-11 15:56:45 +02:00
|
|
|
})(NewFolderModal));
|