Skip to content
This repository was archived by the owner on Apr 5, 2020. It is now read-only.

Commit 0f53a2e

Browse files
committed
Lint warning fixes
clearn up form and widget code. Form is now a pure component cleaned up syntax in PaymentForm broke down APIClient into smaller methods refactored error messages into components if dispatch is not provided, then return early broke down permission methods and removed unnecessary functions apiClient set on object not on state formatting updates cleaning up formatting more linting fixes
1 parent 1c32fc0 commit 0f53a2e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+568
-546
lines changed

.eslintrc.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
},
99
"extends": "airbnb",
1010
"plugins": [
11-
"react",
12-
"jsx-a11y",
13-
"import"
11+
"react",
12+
"jsx-a11y",
13+
"import"
1414
]
1515
}

src/auth.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import APIClient from "./http/requests";
1+
import { APIClient } from "./http/requests";
22

33
module.exports = {
44

src/components/Dashboard/ActiveUsersWidget.js

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import Gravatar from '../Menu/AdminMenu/Gravatar';
44
import { List, ListItem } from 'material-ui/List';
55
import LensIcon from 'material-ui/svg-icons/image/lens';
66
import { lightGreenA400 } from 'material-ui/styles/colors';
7-
import APIClient from '../../http/requests';
7+
import { APIClient } from '../../http/requests';
88
import CircularProgress from 'material-ui/CircularProgress';
99
import withStyles from 'isomorphic-style-loader/lib/withStyles';
1010
import s from './Widget.scss';
@@ -17,24 +17,26 @@ class ActiveUsersWidget extends React.Component {
1717
data: [],
1818
};
1919
}
20+
2021
componentDidMount() {
2122
const client = new APIClient(this.props.dispatch);
2223
client.get('users/active').then((res) => {
2324
if (res.statusCode !== 200) {
24-
// Couldn't get the active users for some reason. Likely something wrong with the API server.
25+
console.warn('error', res);
2526
} else {
2627
client.updateToken(res.header.authorization);
2728
this.setState({ data: res.body.data });
2829
}
2930
}).catch((res) => {
30-
console.log('error', res);
31+
console.warn('error', res);
3132
});
3233
}
34+
3335
render() {
3436
let usersSection = null;
3537

3638
if (this.state.data && (this.state.data.length > 0)) {
37-
usersSection = this.state.data.map((user, i) => {
39+
const userListItems = this.state.data.map((user, i) => {
3840
return (
3941
<ListItem
4042
key={`user-${i}`}
@@ -51,7 +53,7 @@ class ActiveUsersWidget extends React.Component {
5153
<h2 className="widget-title">{this.props.name}</h2>
5254
{this.state.data.length === 0 ? (<CircularProgress />) :
5355
<List>
54-
{usersSection}
56+
{ userListItems }
5557
</List>
5658
}
5759
</div>
@@ -62,6 +64,5 @@ class ActiveUsersWidget extends React.Component {
6264
}
6365
}
6466

65-
export default withStyles(s)(
66-
connect()(ActiveUsersWidget) // call connect so that we have access to dispatch in props.
67-
);
67+
// call connect so that we have access to dispatch in props
68+
export default withStyles(s)(connect()(ActiveUsersWidget));

src/components/Dashboard/Widget.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@ import Paper from 'material-ui/Paper';
55
const Widget = (props) => ({
66

77
render() {
8-
9-
// Will be blank if there are no other users online, otherwise will show widget.
108
return (
119
<Paper zDepth={2} className="widget-wrapper">
1210
{props.children}

src/components/Editor/Editor.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// src/components/Editor/Editor.js
2-
import APIClient from '../../http/requests'
2+
import { APIClient } from '../../http/requests'
33
import ContentTools from 'ContentTools';
44
import {ImageUploader, buildCloudinaryURL, parseCloudinaryURL} from './ImageUploader';
55

src/components/Editor/Quote.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,7 @@ const makeQuote = (_super) => {
2121
ContentTools.ToolShelf.stow(Quote, 'quote');
2222

2323
Quote.label = 'Quote';
24-
2524
Quote.icon = 'subheading';
26-
2725
Quote.tagName = 'quote';
2826

2927
return Quote;

src/components/Form/AddButton.js

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,15 @@ import FloatingActionButton from 'material-ui/FloatingActionButton';
22
import ContentAdd from 'material-ui/svg-icons/content/add';
33

44
const AddButton = (props) => {
5-
6-
handleAddClick(e){
5+
handleAddClick(e) {
76
e.preventDefault();
8-
9-
},
7+
}
8+
109
return (
1110
<FloatingActionButton onClick={handleAddClick}>
1211
<ContentAdd />
1312
</FloatingActionButton>
14-
)
15-
}
13+
);
14+
};
1615

1716
export default AddButton;

src/components/Form/Form.js

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,10 @@
11
// src/components/Form/Form.js
22
import React from 'react';
33

4-
const Form = () => ({
5-
render() {
6-
return (
7-
<form onSubmit={this.props.onSubmit}>
8-
{this.props.children}
9-
</form>
10-
);
11-
}
12-
});
4+
const Form = (props) => (
5+
<form onSubmit={props.onSubmit}>
6+
{ props.children }
7+
</form>
8+
);
139

1410
export { Form };

src/components/Form/SubmitButton.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import React from 'react';
33
import RaisedButton from 'material-ui/RaisedButton';
44
import SendIcon from 'material-ui/svg-icons/content/send';
55

6-
const SubmitButton = (props) => (
6+
const SubmitButton = props => (
77
<RaisedButton
88
className="submit-btn"
99
primary

src/components/Form/TextInput.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { updateFormValidationStatus } from '../../redux/actions/form';
77

88
const style = {
99
display: 'block'
10-
}
10+
};
1111

1212
const TextInput = () => ({
1313
updateValue(value) {
@@ -104,7 +104,7 @@ const mapStateToProps = (state, ownProps) => {
104104
value: state.forms[ownProps.formName].fields[ownProps.name].value,
105105
errors: state.forms[ownProps.formName].fields[ownProps.name].errors
106106
}
107-
}
107+
};
108108

109109
const mapDispatchToProps = (dispatch) => {
110110
return {
@@ -123,11 +123,11 @@ const mapDispatchToProps = (dispatch) => {
123123
dispatch(updateFormValidationStatus(valid, formName));
124124
}
125125
};
126-
}
126+
};
127127

128128
const TextInputRedux = connect(
129129
mapStateToProps,
130130
mapDispatchToProps
131-
)(TextInput)
131+
)(TextInput);
132132

133-
export {TextInputRedux as TextInput}
133+
export { TextInputRedux as TextInput };

src/components/Form/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
export { Form } from './Form';
22
export { TextInput } from './TextInput';
3-
export {default as SubmitButton} from './SubmitButton';
3+
export { default as SubmitButton } from './SubmitButton';

src/components/Forms/ContactForm.js

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// src/componetns/Forms/ContactForm.js
22
import React from 'react';
3-
import APIClient from '../../http/requests'
3+
import { APIClient } from '../../http/requests'
44
import { connect } from 'react-redux';
55

66
// mui components
@@ -9,12 +9,11 @@ import { Form, TextInput, SubmitButton } from '../Form/index';
99
import validations from '../../form-validation/validations'
1010
import NotificationSnackbar from '../Notifications/Snackbar/Snackbar'
1111

12+
const formName = "contactForm";
1213
const listItemStyle = {
1314
padding: "0 16px"
1415
};
1516

16-
const formName = "contactForm";
17-
1817
class ContactForm extends React.Component {
1918

2019
componentDidMount(){
@@ -45,14 +44,13 @@ class ContactForm extends React.Component {
4544

4645
submitToServer(){
4746
const client = new APIClient(this.props.dispatch)
48-
var formInputValues = {};
47+
const httpMethod = 'post';
48+
let formInputValues = {};
4949

5050
Object.keys(this.props.formFields).forEach((key) => {
5151
formInputValues[key] = this.props.formFields[key].value;
5252
})
5353

54-
let httpMethod = 'post';
55-
5654
client[httpMethod]('contact', false, {data: formInputValues})
5755
.then(this.submitResolve, this.submitReject)
5856
.catch(this.handleRequestException)
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import React from "react";
2+
import { redA700 } from 'material-ui/styles/colors';
3+
4+
const ErrorDiv = (props) => (
5+
<div className="payment-content">
6+
<h3 style={{color: redA700}} className="payment-header">{props.title}</h3>
7+
<p>{ props.message }</p>
8+
</div>
9+
);
10+
11+
export default ErrorDiv;
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import React from "react";
2+
import ErrorDiv from "./ErrorDiv";
3+
4+
const LoadingError = () => (
5+
<ErrorDiv
6+
title="Error While Loading Payment System"
7+
message="Please try refreshing the page."
8+
/>
9+
);
10+
11+
export default LoadingError;

0 commit comments

Comments
 (0)