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-07-13 22:13:28 +02:00
|
|
|
|
2020-04-26 11:52:12 +02:00
|
|
|
import Button from '../../../common/Button';
|
|
|
|
|
2016-08-30 05:23:10 +02:00
|
|
|
class NewFileForm extends React.Component {
|
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
|
|
|
this.createFile = this.props.createFile.bind(this);
|
|
|
|
}
|
|
|
|
|
2019-03-12 21:17:27 +01:00
|
|
|
componentDidMount() {
|
|
|
|
this.fileName.focus();
|
|
|
|
}
|
|
|
|
|
2016-08-30 05:23:10 +02:00
|
|
|
render() {
|
|
|
|
const { fields: { name }, handleSubmit } = this.props;
|
|
|
|
return (
|
2016-11-30 01:18:11 +01:00
|
|
|
<form
|
|
|
|
className="new-file-form"
|
|
|
|
onSubmit={(data) => {
|
|
|
|
this.props.focusOnModal();
|
|
|
|
handleSubmit(this.createFile)(data);
|
|
|
|
}}
|
|
|
|
>
|
2019-09-26 21:06:43 +02:00
|
|
|
<div className="new-file-form__input-wrapper">
|
|
|
|
<label className="new-file-form__name-label" htmlFor="name">Name:</label>
|
|
|
|
<input
|
|
|
|
className="new-file-form__name-input"
|
|
|
|
id="name"
|
|
|
|
type="text"
|
2020-08-11 15:56:45 +02:00
|
|
|
placeholder={this.props.t('NewFileForm.Placeholder')}
|
2020-04-06 18:46:17 +02:00
|
|
|
maxLength="128"
|
2019-09-26 21:06:43 +02:00
|
|
|
{...domOnlyProps(name)}
|
|
|
|
ref={(element) => { this.fileName = element; }}
|
|
|
|
/>
|
2020-04-26 11:52:12 +02:00
|
|
|
<Button
|
|
|
|
type="submit"
|
2020-08-11 15:56:45 +02:00
|
|
|
>{this.props.t('NewFileForm.AddFileSubmit')}
|
2020-04-26 11:52:12 +02:00
|
|
|
</Button>
|
2019-09-26 21:06:43 +02:00
|
|
|
</div>
|
2016-10-19 23:09:31 +02:00
|
|
|
{name.touched && name.error && <span className="form-error">{name.error}</span>}
|
2016-08-30 05:23:10 +02:00
|
|
|
</form>
|
|
|
|
);
|
|
|
|
}
|
2016-07-13 22:13:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
NewFileForm.propTypes = {
|
|
|
|
fields: PropTypes.shape({
|
2016-08-30 05:26:45 +02:00
|
|
|
name: PropTypes.object.isRequired
|
2016-07-13 22:13:28 +02:00
|
|
|
}).isRequired,
|
|
|
|
handleSubmit: PropTypes.func.isRequired,
|
2016-11-30 01:18:11 +01:00
|
|
|
createFile: PropTypes.func.isRequired,
|
2020-08-11 15:56:45 +02:00
|
|
|
focusOnModal: PropTypes.func.isRequired,
|
|
|
|
t: PropTypes.func.isRequired
|
2016-07-13 22:13:28 +02:00
|
|
|
};
|
|
|
|
|
2020-08-11 15:56:45 +02:00
|
|
|
export default withTranslation()(NewFileForm);
|