Fix errors

This commit is contained in:
Daniel Mason 2021-03-27 12:29:11 +13:00
parent 50154a009c
commit fc1d6fc567
5 changed files with 27 additions and 35 deletions

View file

@ -5,23 +5,6 @@ import { Button } from 'reactstrap';
import { useToasts } from 'react-toast-notifications';
// const FormWithToasts = () => {
// const { addToast } = useToasts();
// const onSubmit = async value => {
// // const { error } = await dataPersistenceLayer(value);
// if (error) {
// addToast(error.message, { appearance: 'error' });
// } else {
// addToast('Saved Successfully', { appearance: 'success' });
// }
// };
// return <form onSubmit={this.handleSubmit}>...</form>;
// };
// const { addToast } = useToasts();
function withToast(Component) {
return function WrappedComponent(props) {
const toastFuncs = useToasts()
@ -52,6 +35,7 @@ class Login extends React.Component {
const requestOptions = {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
timeout: 5000,
body: JSON.stringify({
username: this.state.username,
password: this.state.password,
@ -67,7 +51,11 @@ class Login extends React.Component {
this.props.addToast(data.token, { appearance: 'success' });
}
this.setState({loading: false});
}).bind(this))
}).bind(this))
.catch(() => {
this.props.addToast('Error submitting form. Please try again', { appearance: 'error' });
this.setState({loading: false});
});
}
render() {

View file

@ -47,10 +47,10 @@ class Register extends React.Component {
return
}
if (this.state.password.len < 8) {
this.props.addToast('Passwords do not match', { appearance: 'error' });
return
}
// if (this.state.password.len < 8) {
// this.props.addToast('Password must be at least 8 characters', { appearance: 'error' });
// return
// }
this.setState({loading: true});
const requestOptions = {
@ -67,6 +67,7 @@ class Register extends React.Component {
fetch(apiUrl, requestOptions)
.then((response) => response.json())
.then((function(data) {
console.log(data);
if (data.error) {
this.props.addToast(data.error, { appearance: 'error' });
} else {