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-08-30 05:23:10 +02:00
|
|
|
|
2020-04-26 11:52:12 +02:00
|
|
|
import Button from '../../../common/Button';
|
|
|
|
|
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 {
|
2020-07-24 23:11:10 +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">
|
2020-07-24 23:11:10 +02:00
|
|
|
<label className="new-folder-form__name-label" htmlFor="name">
|
|
|
|
Name:
|
|
|
|
</label>
|
2019-09-26 21:06:43 +02:00
|
|
|
<input
|
|
|
|
className="new-folder-form__name-input"
|
|
|
|
id="name"
|
|
|
|
type="text"
|
2020-04-06 18:46:17 +02:00
|
|
|
maxLength="128"
|
2019-09-26 21:06:43 +02:00
|
|
|
placeholder="Name"
|
2020-07-24 23:11:10 +02:00
|
|
|
ref={(element) => {
|
|
|
|
this.fileName = element;
|
|
|
|
}}
|
2019-09-26 21:06:43 +02:00
|
|
|
{...domOnlyProps(name)}
|
|
|
|
/>
|
2020-07-24 23:11:10 +02:00
|
|
|
<Button type="submit">Add Folder</Button>
|
2019-09-26 21:06:43 +02:00
|
|
|
</div>
|
2020-07-24 23:11:10 +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({
|
2020-07-28 16:17:49 +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-07-24 23:11:10 +02:00
|
|
|
pristine: PropTypes.bool,
|
2018-10-22 21:41:35 +02:00
|
|
|
};
|
|
|
|
NewFolderForm.defaultProps = {
|
|
|
|
submitting: false,
|
2020-07-24 23:11:10 +02:00
|
|
|
pristine: true,
|
2016-08-30 05:23:10 +02:00
|
|
|
};
|
|
|
|
export default NewFolderForm;
|