Removes the largest batch of React-19-blocking warnings: the 0.31 components (Grid, FormGroup, ControlLabel, Navbar.Header/Brand, Checkbox, SafeAnchor) all leaned on legacy context / defaultProps. 29 files converted: Grid->Container, FormGroup/ControlLabel/FormControl/ HelpBlock -> Form.Group/Label/Control/Text, Checkbox -> Form.Check (label as prop), bsStyle->variant (default->secondary), bsSize->size, pull-right->float-end. Custom Col.js now re-exports v2's Col; custom NavItem.js rewritten self-contained (no SafeAnchor/createChainedFunction); Navigation.js drops react-bootstrap Navbar (raw markup anyway). CSS stays on Bootstrap 4 (alexwine:bootstrap-4) for now: the BS4->5 jump is entangled with the jQuery carousel/swipe + navbar-collapse and is tracked as separate debt in UPGRADE.md. Only .form-label needed a shim (forms.scss). Browser-verified home carousel+navbar, signup form + terms checkbox, login form; REST smoke byte-identical.
97 lines
2.6 KiB
JavaScript
97 lines
2.6 KiB
JavaScript
/* eslint-disable max-len, no-return-assign */
|
|
|
|
import React from 'react';
|
|
import PropTypes from 'prop-types';
|
|
import { Form, Button } from 'react-bootstrap';
|
|
import { Meteor } from 'meteor/meteor';
|
|
import { Bert } from 'meteor/themeteorchef:bert';
|
|
import validate from '../../../modules/validate';
|
|
|
|
class DocumentEditor extends React.Component {
|
|
componentDidMount() {
|
|
const component = this;
|
|
validate(component.form, {
|
|
rules: {
|
|
title: {
|
|
required: true,
|
|
},
|
|
body: {
|
|
required: true,
|
|
},
|
|
},
|
|
messages: {
|
|
title: {
|
|
required: 'Need a title in here, Seuss.',
|
|
},
|
|
body: {
|
|
required: 'This thneeds a body, please.',
|
|
},
|
|
},
|
|
submitHandler() { component.handleSubmit(); },
|
|
});
|
|
}
|
|
|
|
handleSubmit() {
|
|
const { history } = this.props;
|
|
const existingDocument = this.props.doc && this.props.doc._id;
|
|
const methodToCall = existingDocument ? 'documents.update' : 'documents.insert';
|
|
const doc = {
|
|
title: this.title.value.trim(),
|
|
body: this.body.value.trim(),
|
|
};
|
|
|
|
if (existingDocument) doc._id = existingDocument;
|
|
|
|
Meteor.call(methodToCall, doc, (error, documentId) => {
|
|
if (error) {
|
|
Bert.alert(error.reason, 'danger');
|
|
} else {
|
|
const confirmation = existingDocument ? 'Document updated!' : 'Document added!';
|
|
this.form.reset();
|
|
Bert.alert(confirmation, 'success');
|
|
history.push(`/documents/${documentId}`);
|
|
}
|
|
});
|
|
}
|
|
|
|
render() {
|
|
const { doc } = this.props;
|
|
return (<form ref={form => (this.form = form)} onSubmit={event => event.preventDefault()}>
|
|
<Form.Group>
|
|
<Form.Label>Title</Form.Label>
|
|
<input
|
|
type="text"
|
|
className="form-control"
|
|
name="title"
|
|
ref={title => (this.title = title)}
|
|
defaultValue={doc && doc.title}
|
|
placeholder="Oh, The Places You'll Go!"
|
|
/>
|
|
</Form.Group>
|
|
<Form.Group>
|
|
<Form.Label>Body</Form.Label>
|
|
<textarea
|
|
className="form-control"
|
|
name="body"
|
|
ref={body => (this.body = body)}
|
|
defaultValue={doc && doc.body}
|
|
placeholder="Congratulations! Today is your day. You're off to Great Places! You're off and away!"
|
|
/>
|
|
</Form.Group>
|
|
<Button type="submit" variant="success">
|
|
{doc && doc._id ? 'Save Changes' : 'Add Document'}
|
|
</Button>
|
|
</form>);
|
|
}
|
|
}
|
|
|
|
DocumentEditor.defaultProps = {
|
|
doc: { title: '', body: '' },
|
|
};
|
|
|
|
DocumentEditor.propTypes = {
|
|
doc: PropTypes.object,
|
|
history: PropTypes.object.isRequired,
|
|
};
|
|
|
|
export default DocumentEditor;
|