wip wiring up account forms

This commit is contained in:
cleverbeagle 2017-05-25 16:31:01 -05:00
parent cdc15f019d
commit 3459bf26f8
25 changed files with 413 additions and 53 deletions

View file

@ -0,0 +1,80 @@
import React from 'react';
import PropTypes from 'prop-types';
import { Link } from 'react-router-dom';
import { Table, Alert, Button } from 'react-bootstrap';
import { timeago, monthDayYearAtTime } from '@cleverbeagle/dates';
import { Meteor } from 'meteor/meteor';
import { createContainer } from 'meteor/react-meteor-data';
import { Bert } from 'meteor/themeteorchef:bert';
import DocumentsCollection from '../../../api/Documents/Documents';
import './Documents.scss';
const handleRemove = (documentId) => {
if (confirm('Are you sure? This is permanent!')) {
Meteor.call('documents.remove', documentId, (error) => {
if (error) {
Bert.alert(error.reason, 'danger');
} else {
Bert.alert('Document deleted!', 'success');
}
});
}
};
const Documents = ({ documents, match, history }) => (
<div className="Documents">
<div className="page-header clearfix">
<h4 className="pull-left">Documents</h4>
<Link className="btn btn-success pull-right" to={`${match.url}/new`}>Add Document</Link>
</div>
{documents.length ? <Table responsive>
<thead>
<tr>
<th>Title</th>
<th>Last Updated</th>
<th>Created</th>
<th />
<th />
</tr>
</thead>
<tbody>
{documents.map(({ _id, title, createdAt, updatedAt }) => (
<tr key={_id}>
<td>{title}</td>
<td>{timeago(updatedAt)}</td>
<td>{monthDayYearAtTime(createdAt)}</td>
<td>
<Button
bsStyle="primary"
onClick={() => history.push(`${match.url}/${_id}`)}
block
>View</Button>
</td>
<td>
<Button
bsStyle="danger"
onClick={() => handleRemove(_id)}
block
>Delete</Button>
</td>
</tr>
))}
</tbody>
</Table> : <Alert bsStyle="warning">No documents yet!</Alert>}
</div>
);
Documents.propTypes = {
documents: PropTypes.arrayOf(PropTypes.object).isRequired,
match: PropTypes.object.isRequired,
history: PropTypes.object.isRequired,
};
export default createContainer(() => {
const subscription = Meteor.subscribe('documents');
return {
loading: !subscription.ready(),
documents: DocumentsCollection.find().fetch(),
};
}, Documents);

View file

@ -0,0 +1,3 @@
.Documents table tbody tr td {
vertical-align: middle;
}

View file

@ -0,0 +1,29 @@
import React from 'react';
import PropTypes from 'prop-types';
import { createContainer } from 'meteor/react-meteor-data';
import { Meteor } from 'meteor/meteor';
import Documents from '../../../api/Documents/Documents';
import DocumentEditor from '../../components/DocumentEditor/DocumentEditor';
import NotFound from '../NotFound/NotFound';
const EditDocument = ({ doc, history }) => (doc ? (
<div className="EditDocument">
<h4 className="page-header">{`Editing "${doc.title}"`}</h4>
<DocumentEditor doc={doc} history={history} />
</div>
) : <NotFound />);
EditDocument.propTypes = {
doc: PropTypes.object.isRequired,
history: PropTypes.object.isRequired,
};
export default createContainer(({ match }) => {
const documentId = match.params._id;
const subscription = Meteor.subscribe('documents.view', documentId);
return {
loading: !subscription.ready(),
doc: Documents.findOne(documentId),
};
}, EditDocument);

View file

@ -80,7 +80,10 @@ class Login extends React.Component {
/>
</FormGroup>
<FormGroup>
<ControlLabel>Password</ControlLabel>
<ControlLabel className="clearfix">
<span className="pull-left">Password</span>
<Link className="pull-right" to="/recover-password">Forgot password?</Link>
</ControlLabel>
<input
type="password"
name="password"
@ -100,7 +103,7 @@ class Login extends React.Component {
}
Login.propTypes = {
history: PropTypes.object.isRequired, // eslint-disable-line react/forbid-prop-types
history: PropTypes.object.isRequired,
};
export default Login;

View file

@ -2,10 +2,6 @@
@import '../../stylesheets/colors';
.Login {
.page-header {
margin-top: 0;
}
form {
position: relative;
border-top: 1px solid $gray-lighter;
@ -29,19 +25,3 @@
}
}
}
@include breakpoint(tablet) {
.Login {
.page-header {
margin-top: 10px;
}
}
}
@include breakpoint(desktop) {
.Login {
.page-header {
margin-top: 20px;
}
}
}

View file

@ -0,0 +1,16 @@
import React from 'react';
import PropTypes from 'prop-types';
import DocumentEditor from '../../components/DocumentEditor/DocumentEditor';
const NewDocument = ({ history }) => (
<div className="NewDocument">
<h4 className="page-header">New Document</h4>
<DocumentEditor history={history} />
</div>
);
NewDocument.propTypes = {
history: PropTypes.object.isRequired,
};
export default NewDocument;

View file

@ -0,0 +1,12 @@
import React from 'react';
import { Alert } from 'react-bootstrap';
const NotFound = () => (
<div className="NotFound">
<Alert bsStyle="danger">
<p><strong>Error [404]</strong>: {window.location.pathname} does not exist.</p>
</Alert>
</div>
);
export default NotFound;

View file

@ -149,7 +149,7 @@ class Signup extends React.Component {
}
Signup.propTypes = {
history: PropTypes.object.isRequired, // eslint-disable-line react/forbid-prop-types
history: PropTypes.object.isRequired,
};
export default Signup;

View file

@ -1,11 +1,6 @@
@import '../../stylesheets/mixins';
@import '../../stylesheets/colors';
.Signup {
.page-header {
margin-top: 0;
}
form {
position: relative;
border-top: 1px solid $gray-lighter;
@ -29,19 +24,3 @@
}
}
}
@include breakpoint(tablet) {
.Signup {
.page-header {
margin-top: 10px;
}
}
}
@include breakpoint(desktop) {
.Signup {
.page-header {
margin-top: 20px;
}
}
}

View file

@ -0,0 +1,54 @@
import React from 'react';
import PropTypes from 'prop-types';
import { ButtonToolbar, ButtonGroup, Button } from 'react-bootstrap';
import { createContainer } from 'meteor/react-meteor-data';
import { Meteor } from 'meteor/meteor';
import { Bert } from 'meteor/themeteorchef:bert';
import Documents from '../../../api/Documents/Documents';
import NotFound from '../NotFound/NotFound';
const handleRemove = (documentId, history) => {
if (confirm('Are you sure? This is permanent!')) {
Meteor.call('documents.remove', documentId, (error) => {
if (error) {
Bert.alert(error.reason, 'danger');
} else {
Bert.alert('Document deleted!', 'success');
history.push('/documents');
}
});
}
};
const ViewDocument = ({ doc, match, history }) => (doc ? (
<div className="ViewDocument">
<div className="page-header clearfix">
<h4 className="pull-left">{ doc && doc.title }</h4>
<ButtonToolbar className="pull-right">
<ButtonGroup bsSize="small">
<Button onClick={() => history.push(`${match.url}/edit`)}>Edit</Button>
<Button onClick={() => handleRemove(doc._id, history)} className="text-danger">
Delete
</Button>
</ButtonGroup>
</ButtonToolbar>
</div>
{ doc && doc.body }
</div>
) : <NotFound />);
ViewDocument.propTypes = {
doc: PropTypes.object.isRequired,
match: PropTypes.object.isRequired,
history: PropTypes.object.isRequired,
};
export default createContainer(({ match }) => {
const documentId = match.params._id;
const subscription = Meteor.subscribe('documents.view', documentId);
return {
loading: !subscription.ready(),
doc: Documents.findOne(documentId),
};
}, ViewDocument);