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