-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #14 from joeblas/globalUI
Global ui
- Loading branch information
Showing
6 changed files
with
122 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
/* eslint-disable max-len, no-return-assign */ | ||
|
||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import { FormGroup, ControlLabel, 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, please.', | ||
}, | ||
body: { | ||
required: 'This needs 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()}> | ||
<FormGroup> | ||
<ControlLabel>Title</ControlLabel> | ||
<input | ||
type="text" | ||
className="form-control" | ||
name="title" | ||
ref={title => (this.title = title)} | ||
defaultValue={doc && doc.title} | ||
placeholder="Oh, The Places You'll Go!" | ||
/> | ||
</FormGroup> | ||
<FormGroup> | ||
<ControlLabel>Body</ControlLabel> | ||
<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!" | ||
/> | ||
</FormGroup> | ||
<Button type="submit" bsStyle="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; |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.