Commit 8cf95e3a40219e57e5da99d40bfedf5227b0bf81
1 parent
cc7aef11fd
Exists in
master
fix documentation deletion throwing React errors
Showing
1 changed file
with
3 additions
and
3 deletions
Show diff stats
imports/ui/pages/ViewDocument.js
1 | import React from 'react'; | 1 | import React from 'react'; |
2 | import { ButtonToolbar, ButtonGroup, Button } from 'react-bootstrap'; | 2 | import { ButtonToolbar, ButtonGroup, Button } from 'react-bootstrap'; |
3 | import { browserHistory } from 'react-router'; | 3 | import { browserHistory } from 'react-router'; |
4 | import { Bert } from 'meteor/themeteorchef:bert'; | 4 | import { Bert } from 'meteor/themeteorchef:bert'; |
5 | import { removeDocument } from '../../api/documents/methods.js'; | 5 | import { removeDocument } from '../../api/documents/methods.js'; |
6 | 6 | ||
7 | const handleEdit = (_id) => { | 7 | const handleEdit = (_id) => { |
8 | browserHistory.push(`/documents/${_id}/edit`); | 8 | browserHistory.push(`/documents/${_id}/edit`); |
9 | } | 9 | } |
10 | 10 | ||
11 | const handleRemove = (_id) => { | 11 | const handleRemove = (_id) => { |
12 | if (confirm('Are you sure? This is permanent!')) { | 12 | if (confirm('Are you sure? This is permanent!')) { |
13 | removeDocument.call({ _id }, (error) => { | 13 | removeDocument.call({ _id }, (error) => { |
14 | if (error) { | 14 | if (error) { |
15 | Bert.alert(error.reason, 'danger'); | 15 | Bert.alert(error.reason, 'danger'); |
16 | } else { | 16 | } else { |
17 | Bert.alert('Document deleted!', 'success'); | 17 | Bert.alert('Document deleted!', 'success'); |
18 | browserHistory.push('/documents'); | 18 | browserHistory.push('/documents'); |
19 | } | 19 | } |
20 | }); | 20 | }); |
21 | } | 21 | } |
22 | }; | 22 | }; |
23 | 23 | ||
24 | const ViewDocument = ({ doc }) => ( | 24 | const ViewDocument = ({ doc }) => ( |
25 | <div className="ViewDocument"> | 25 | <div className="ViewDocument"> |
26 | <div className="page-header clearfix"> | 26 | <div className="page-header clearfix"> |
27 | <h4 className="pull-left">{ doc.title }</h4> | 27 | <h4 className="pull-left">{ doc && doc.title }</h4> |
28 | <ButtonToolbar className="pull-right"> | 28 | <ButtonToolbar className="pull-right"> |
29 | <ButtonGroup bsSize="small"> | 29 | <ButtonGroup bsSize="small"> |
30 | <Button onClick={ () => handleEdit(doc._id) }>Edit</Button> | 30 | <Button onClick={ () => handleEdit(doc._id) }>Edit</Button> |
31 | <Button onClick={ () => handleRemove(doc._id) } className="text-danger">Delete</Button> | 31 | <Button onClick={ () => handleRemove(doc._id) } className="text-danger">Delete</Button> |
32 | </ButtonGroup> | 32 | </ButtonGroup> |
33 | </ButtonToolbar> | 33 | </ButtonToolbar> |
34 | </div> | 34 | </div> |
35 | { doc.body } | 35 | { doc && doc.body } |
36 | </div> | 36 | </div> |
37 | ); | 37 | ); |
38 | 38 | ||
39 | ViewDocument.propTypes = { | 39 | ViewDocument.propTypes = { |
40 | doc: React.PropTypes.object.isRequired, | 40 | doc: React.PropTypes.object, |
41 | }; | 41 | }; |
42 | 42 | ||
43 | export default ViewDocument; | 43 | export default ViewDocument; |
44 | 44 |