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