2018-02-07 19:06:07 +01:00
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
import React from 'react';
|
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"
|
|
|
|
placeholder="Name"
|
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"
|
|
|
|
>Add File
|
|
|
|
</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({
|
2020-07-24 22:01:48 +02:00
|
|
|
name: PropTypes.object.isRequired // eslint-disable-line
|
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,
|
|
|
|
focusOnModal: PropTypes.func.isRequired
|
2016-07-13 22:13:28 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
export default NewFileForm;
|