@@ -101,7 +101,9 @@ class TransactionList extends React.Component {
{bill.payments.map(payment => {
- const label = `${payment.from} owes ${payment.to} $${payment.amount.toFixed(2)}`;
+ const label = `${payment.from} owes ${payment.to} $${Number(
+ payment.amount
+ ).toFixed(2)}`;
return (
diff --git a/split-webapp/split/src/pages/Login.js b/split-webapp/split/src/pages/Login.js
index 63e3595..82cfd0a 100644
--- a/split-webapp/split/src/pages/Login.js
+++ b/split-webapp/split/src/pages/Login.js
@@ -22,24 +22,27 @@ class Login extends Component {
}
handleOnChangeUser = event => {
- this.state.username = event.target.value;
+ this.setState({ username: event.target.value });
};
handleOnChangePassword = event => {
- this.state.password = event.target.value;
+ this.setState({ password: event.target.value });
};
handleAuth = () => {
this.setState({ failedAuth: true });
};
- // creates user and passes it to the api call.
createDetails() {
- const user = this.state;
+ const { username, password, failedAuth } = this.state;
+ const user = {
+ username,
+ password,
+ failedAuth
+ };
this.authenticate(user);
}
- // api call to the back-end
authenticate(user) {
const { history } = this.props;
fetch("/api/account/login", {
diff --git a/split-webapp/split/src/pages/SignUp.js b/split-webapp/split/src/pages/SignUp.js
index 06d7750..0d6ed88 100644
--- a/split-webapp/split/src/pages/SignUp.js
+++ b/split-webapp/split/src/pages/SignUp.js
@@ -31,8 +31,8 @@ class SignUp extends Component {
this.setState({ user, failed: false });
};
- // Creates a new user JSON and sends to the create account end point. On success routes
- // user to the create a bill page. User should get logged in as well as session created.
+ // Creates a new user JSON and sends to the create account end point.
+ // User should get logged in as well as session created.
createUser() {
const { user } = this.state;
@@ -58,8 +58,6 @@ class SignUp extends Component {
})
.then(data => {
if (data.success === true) {
- // If the POST returns success, route user to the split page
- // eslint-ignore
history.push("/home/split");
} else {
this.setState({
@@ -72,15 +70,11 @@ class SignUp extends Component {
}
}
- // Checks that the two passwords match
-
validatePassword() {
const { user } = this.state;
return user.password === user.confPassword;
}
- // Check the username is non empty
-
validateUsername() {
const { user } = this.state;
return user.username !== "";
diff --git a/split-webapp/split/src/pages/Split.js b/split-webapp/split/src/pages/Split.js
index c426cf3..63fa1d4 100644
--- a/split-webapp/split/src/pages/Split.js
+++ b/split-webapp/split/src/pages/Split.js
@@ -13,6 +13,20 @@ import {
} from "@material-ui/core";
import PropTypes from "prop-types";
+const createBill = data => {
+ fetch("/api/bill_exec/create_bill", {
+ method: "POST",
+ body: JSON.stringify(data),
+ headers: {
+ "Content-Type": "application/json"
+ }
+ })
+ .then(res => {
+ return res;
+ })
+ .catch(err => console.log(err));
+};
+
class Split extends Component {
constructor(props) {
super(props);
@@ -88,15 +102,17 @@ class Split extends Component {
outstanding_payments: paymentArray
};
- this.createBill(bill);
+ createBill(bill);
if (!title) {
alert("Please enter a title description for this bill.");
return;
- } if (!cost) {
+ }
+ if (!cost) {
alert("Please enter an amount for this bill.");
return;
- } if (transaction.users.length < 2) {
+ }
+ if (transaction.users.length < 2) {
alert(
"There is not enough people to split a bill. Please make sure at least 2 people are on the list."
);
@@ -110,22 +126,6 @@ class Split extends Component {
history.push("/home/transactions");
}
- createBill(data) {
- fetch("/api/bill_exec/create_bill", {
- method: "POST",
- body: JSON.stringify(data),
- headers: {
- "Content-Type": "application/json"
- }
- })
- .then(res => {
- // If "this" is not called in the createBill method, you may have to create the function outside of the class (es-lint rule)
- this.setState({});
- return res;
- })
- .catch(err => console.log(err));
- }
-
render() {
const { transaction } = this.state;
return (