Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions client/src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import SignUp from './components/SignUp';
import ItemDetails from './components/ItemDetails';
import ItemList from './components/ItemList';
import Feedback from './components/Feedback';
import Error from './components/Shared/Error';

function App() {
return (
Expand All @@ -21,6 +22,8 @@ function App() {
<Route path="/item-details/:id" component={ItemDetails} />
<Route path="/item-list" component={ItemList} />
<Route path="/feedback" component={Feedback} />
<Route path="/error" component={Error} />

</div>
</Router>
);
Expand Down
14 changes: 10 additions & 4 deletions client/src/components/Feedback/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ class Feedback extends Component {
const { history } = this.props;
history.push('/');
}
}).catch(() => {
const { history } = this.props;
history.push('/error');
});
axios
.get('/get-feedback')
Expand All @@ -48,8 +51,10 @@ class Feedback extends Component {
}
this.setState({ loading: false });
}
})
.catch(err => console.log(err));
}).catch(() => {
const { history } = this.props;
history.push('/error');
});
}

updateOptions = (feedbacks) => {
Expand Down Expand Up @@ -127,8 +132,9 @@ class Feedback extends Component {
if (data.success) {
history.push('/item-list');
}
})
.catch(() => history.push('/error'));
}).catch(() => {
history.push('/error');
});
}
history.push('/item-list');
};
Expand Down
18 changes: 18 additions & 0 deletions client/src/components/GetDetails/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,9 @@ class GetDetails extends Component {
brands,
});
}
}).catch(() => {
const { history } = this.props;
history.push('/error');
});

axios.get('/checkcookie').then(({ data: { cookie, logged } }) => {
Expand All @@ -96,6 +99,9 @@ class GetDetails extends Component {
} else {
this.setState({ title: 'LOGIN TO SAVE YOUR ITEM' });
}
}).catch(() => {
const { history } = this.props;
history.push('/error');
});
} else {
const { history } = this.props;
Expand All @@ -107,6 +113,9 @@ class GetDetails extends Component {
const airtableNames = type.map(item => item.name);
const filtered = this.state.itemType.filter(item => !airtableNames.includes(item.name));
this.setState({ itemType: [...filtered, ...type] });
}).catch(() => {
const { history } = this.props;
history.push('/error');
});
}

Expand Down Expand Up @@ -206,6 +215,9 @@ class GetDetails extends Component {
if (data.success) {
history.push({ pathname: '/item-list', logged });
}
}).catch(() => {
const { history } = this.props;
history.push('/error');
});
} else {
history.push({ pathname: '/login-form', data: inputs });
Expand All @@ -220,6 +232,9 @@ class GetDetails extends Component {
} else {
history.push({ pathname: '/login-form', data: inputs });
}
}).catch(() => {
const { history } = this.props;
history.push('/error');
});
}
};
Expand Down Expand Up @@ -257,6 +272,9 @@ class GetDetails extends Component {
} else {
history.push({ pathname: '/login-form', data: inputs });
}
}).catch(() => {
const { history } = this.props;
history.push('/error');
});
}
};
Expand Down
18 changes: 14 additions & 4 deletions client/src/components/ItemDetails/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,17 @@ class ItemDetails extends Component {
const brands = this.removeDuplicate(data.data, this.state.selected_brands);
this.setState({ brands: [this.state.selected_brands, ...brands] });
}
}).catch(() => {
const { history } = this.props;
history.push('/error');
});

axios.get('/get-types').then(({ data }) => {
const types = this.removeDuplicate(data.itemType, this.state.selected_itemType);
this.setState({ itemType: [this.state.selected_itemType, ...types] });
}).catch(() => {
const { history } = this.props;
history.push('/error');
});
}

Expand All @@ -110,8 +116,10 @@ class ItemDetails extends Component {
if (data.success) {
history.push('/item-list');
}
})
.catch(() => history.push('/error'));
}).catch(() => {
const { history } = this.props;
history.push('/error');
});
};

toggleOpen = (e) => {
Expand Down Expand Up @@ -255,8 +263,10 @@ class ItemDetails extends Component {
if (data.success) {
history.push('/item-list');
}
})
.catch(() => history.push('/error'));
}).catch(() => {
const { history } = this.props;
history.push('/error');
});
}
history.push('/item-list');
};
Expand Down
8 changes: 7 additions & 1 deletion client/src/components/ItemList/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,18 @@ class ItemList extends Component {
const { history } = this.props;
history.push('/');
}
}).catch(() => {
const { history } = this.props;
history.push('/error');
});

axios
.get('/items')
.then(({ data }) => this.setState({ itemlist: data.data, loading: false }))
.catch(err => console.log(err));
.catch(() => {
const { history } = this.props;
history.push('/error');
});
}

goItemDetails = (id, index) => {
Expand Down
7 changes: 7 additions & 0 deletions client/src/components/Login/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ class Login extends Component {
const { history } = this.props;
history.push('/item-list');
}
}).catch(() => {
const { history } = this.props;
history.push('/error');
});
}

Expand Down Expand Up @@ -82,13 +85,17 @@ class Login extends Component {
} else {
history.push('/error');
}
}).catch(() => {
history.push('/error');
});
} else {
history.push('/item-list');
}
} else {
this.setState({ passwordError: 'Username or password is incorrect.', isErrorUsername: true, isErrorPassword: true });
}
}).catch(() => {
history.push('/error');
});
}
};
Expand Down
12 changes: 12 additions & 0 deletions client/src/components/Shared/Error/error.style.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import styled from 'styled-components';

export default styled.h1`
font-size: 20px;
font-family:'Assistant';
background-color:#FAFAFA;
padding: 22px 0px;
text-align:center;
@media (max-width: 650px) {
font-size: 16px;
}
`;
9 changes: 9 additions & 0 deletions client/src/components/Shared/Error/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import React from 'react';
import StyledErrorr from './error.style';

const Error = () => (
<StyledErrorr>
SERVER ERROR!
</StyledErrorr>
);
export default Error;
5 changes: 5 additions & 0 deletions client/src/components/Shared/Title/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ class Title extends Component {
axios.get('/checkcookie')
.then(({ data: { cookie } }) => {
if (cookie) { this.setState({ logged: true }); } else { this.setState({ logged: false }); }
}).catch(() => {
const { history } = this.props;
history.push('/error');
});
}

Expand All @@ -23,6 +26,8 @@ class Title extends Component {
axios.get('/logout')
.then(() => {
history.push('/login-form');
}).catch(() => {
history.push('/error');
});
};

Expand Down
5 changes: 5 additions & 0 deletions client/src/components/SignUp/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ class signUp extends Component {
const { history } = this.props;
history.push('/item-list');
}
}).catch(() => {
const { history } = this.props;
history.push('/error');
});
}

Expand Down Expand Up @@ -93,6 +96,8 @@ class signUp extends Component {
} else {
this.setState({ usernameError: 'This username already exists.', isErrorUsername: true });
}
}).catch(() => {
history.push('/error');
});
}
};
Expand Down
3 changes: 3 additions & 0 deletions client/src/components/SplashPage/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ class Splash extends Component {
const { history } = this.props;
history.push('/item-list');
}
}).catch(() => {
const { history } = this.props;
history.push('/error');
});
}

Expand Down
3 changes: 3 additions & 0 deletions client/src/components/Upload/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ class Upload extends Component {
axios.post('/add-to-amazon', img).then(({ data }) => {
this.setState({ details: data });
this.props.history.push({ pathname: '/get-details', details: this.state.details });
}).catch(() => {
const { history } = this.props;
history.push('/error');
});
};

Expand Down