2018-02-07 19:06:07 +01:00
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
import React from 'react';
|
2020-08-11 15:56:45 +02:00
|
|
|
import { withTranslation } from 'react-i18next';
|
2016-11-16 19:12:36 +01:00
|
|
|
import { domOnlyProps } from '../../../utils/reduxFormUtils';
|
2016-08-30 05:23:10 +02:00
|
|
|
|
2020-04-26 11:52:12 +02:00
|
|
|
import Button from '../../../common/Button';
|
|
|
|
|
2020-08-11 15:56:45 +02:00
|
|
|
|
2016-08-30 05:23:10 +02:00
|
|
|
class NewFolderForm extends React.Component {
|
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
|
|
|
this.createFolder = this.props.createFolder.bind(this);
|
|
|
|
}
|
|
|
|
|
2016-09-04 01:42:23 +02:00
|
|
|
componentDidMount() {
|
2017-02-22 20:29:35 +01:00
|
|
|
this.fileName.focus();
|
2016-09-04 01:42:23 +02:00
|
|
|
}
|
|
|
|
|
2016-08-30 05:23:10 +02:00
|
|
|
render() {
|
2018-10-22 21:41:35 +02:00
|
|
|
const {
|
2019-08-22 22:47:22 +02:00
|
|
|
fields: { name }, handleSubmit
|
2018-10-22 21:41:35 +02:00
|
|
|
} = this.props;
|
2016-08-30 05:23:10 +02:00
|
|
|
return (
|
2016-11-30 01:18:11 +01:00
|
|
|
<form
|
|
|
|
className="new-folder-form"
|
|
|
|
onSubmit={(data) => {
|
2020-03-24 23:07:58 +01:00
|
|
|
handleSubmit(this.createFolder)(data);
|
2016-11-30 01:18:11 +01:00
|
|
|
}}
|
|
|
|
>
|
2019-09-26 21:06:43 +02:00
|
|
|
<div className="new-folder-form__input-wrapper">
|
|
|
|
<label className="new-folder-form__name-label" htmlFor="name">Name:</label>
|
|
|
|
<input
|
|
|
|
className="new-folder-form__name-input"
|
|
|
|
id="name"
|
|
|
|
type="text"
|
2020-04-06 18:46:17 +02:00
|
|
|
maxLength="128"
|
2020-08-11 15:56:45 +02:00
|
|
|
placeholder={this.props.t('NewFolderForm.Placeholder')}
|
2019-09-26 21:06:43 +02:00
|
|
|
ref={(element) => { this.fileName = element; }}
|
|
|
|
{...domOnlyProps(name)}
|
|
|
|
/>
|
2020-04-26 11:52:12 +02:00
|
|
|
<Button
|
|
|
|
type="submit"
|
2020-08-11 15:56:45 +02:00
|
|
|
>{this.props.t('NewFolderForm.AddFolderSubmit')}
|
2020-04-26 11:52:12 +02:00
|
|
|
</Button>
|
2019-09-26 21:06:43 +02:00
|
|
|
</div>
|
2018-10-22 21:41:35 +02:00
|
|
|
{name.touched && name.error && <span className="form-error">{name.error}</span>}
|
2016-08-30 05:23:10 +02:00
|
|
|
</form>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
NewFolderForm.propTypes = {
|
|
|
|
fields: PropTypes.shape({
|
2016-08-30 05:26:45 +02:00
|
|
|
name: PropTypes.object.isRequired
|
2016-08-30 05:23:10 +02:00
|
|
|
}).isRequired,
|
|
|
|
handleSubmit: PropTypes.func.isRequired,
|
2016-11-30 01:18:11 +01:00
|
|
|
createFolder: PropTypes.func.isRequired,
|
2018-10-22 21:41:35 +02:00
|
|
|
closeModal: PropTypes.func.isRequired,
|
|
|
|
submitting: PropTypes.bool,
|
2020-08-11 15:56:45 +02:00
|
|
|
pristine: PropTypes.bool,
|
|
|
|
t: PropTypes.func.isRequired
|
2018-10-22 21:41:35 +02:00
|
|
|
};
|
|
|
|
NewFolderForm.defaultProps = {
|
|
|
|
submitting: false,
|
|
|
|
pristine: true
|
2016-08-30 05:23:10 +02:00
|
|
|
};
|
2020-08-11 15:56:45 +02:00
|
|
|
export default withTranslation()(NewFolderForm);
|