Skip to content

Commit

Permalink
minor change to small error container, added relog error message, mov…
Browse files Browse the repository at this point in the history
…ed commit hash to right spot
  • Loading branch information
danielfang97 committed Mar 13, 2024
1 parent 04406ac commit ab95079
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 8 deletions.
35 changes: 33 additions & 2 deletions frontend/components/Error/ErrorClearer.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,40 @@
import { useDispatch } from 'react-redux';
import styles from '../../styles/error.module.css';
import { clearErrors, removeErrorByIndex } from '../../redux/actions';
import { useRouter } from 'next/router';
import { clearErrors, removeErrorByIndex, logoutUser } from '../../redux/actions';

export default function ErrorClearer({ index, setIndex }) {
export default function ErrorClearer({ index, setIndex, size }) {
const dispatch = useDispatch();
const router = useRouter();
if (size === 'relog') {
return (
<div
className={styles.clearButton}
onClick={() => {
dispatch(clearErrors());
dispatch(logoutUser());
router.push('/');
}}
>
Return to Login
</div>
);
}
if (size === 'small') {
return (
<div
className={styles.clearButton}
onClick={() => {
dispatch(removeErrorByIndex(index));
if (index > 0) {
setIndex(index - 1);
}
}}
>
Dismiss
</div>
);
}
return (
<div className={styles.sideBySide}>
<div
Expand Down
20 changes: 19 additions & 1 deletion frontend/components/Error/Errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,24 @@ export default function Errors() {
const error = errors[viewIndex];
const toggleExpand = () => setIsExpanded(!isExpanded);

console.log(error.response.data);

if (error.response.data === "Error: Cannot access other users' graphs.") {
return (
<div className={styles.smallErrorContainer}>
<div className={styles.errorHeaderContainer}>
<div className={styles.errorTitle}>
<FontAwesomeIcon icon={faExclamationCircle} color="#f00" size="1x" />
<h1 className={styles.header}>{error.message = "User token is expired. Please relog."}</h1>
</div>
<div>
<ErrorClearer index={viewIndex} setIndex={setViewIndex} size={'relog'} />
</div>
</div>
</div>
);
}

return (
<div className={isExpanded ? styles.errorContainer : styles.smallErrorContainer}>
<div className={styles.errorHeaderContainer}>
Expand All @@ -32,7 +50,7 @@ export default function Errors() {
<div>
{!isExpanded && (
<>
<ErrorClearer index={viewIndex} setIndex={setViewIndex} />
<ErrorClearer index={viewIndex} setIndex={setViewIndex} size={'small'} />
</>
)}
</div>
Expand Down
7 changes: 3 additions & 4 deletions frontend/components/Footer.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,12 @@ export default function Footer() {
useEffect(() => {
fetch('/commitHash.txt')
.then(response => response.text())
.then(hash => setCommitHash(hash));
.then(hash => setCommitHash(hash.slice(0, 8)));
}, []);

return (
<footer className={styles.footer}>
<div className={styles.copyrightcontainer}>
<div>Commit Hash: {commitHash}</div>
<Image
alt="logo"
width={80}
Expand Down Expand Up @@ -61,11 +60,11 @@ export default function Footer() {
API
</a>
<a
href="https://github.com/SynBioHub/synbiohub3"
href={`https://github.com/SynBioHub/synbiohub3/commit/${commitHash}`} // Incorporate the commit hash into the link
target="_blank"
rel="noreferrer"
>
Github Repo
Github Repo ({commitHash}) {/* Display the trimmed commit hash */}
</a>
<a
href="https://github.com/SynBioHub/synbiohub3/issues"
Expand Down
3 changes: 3 additions & 0 deletions frontend/components/Viewing/Collection/Members.js
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,10 @@ const fetcher = (url, token, dispatch) =>
// Check if the error is 401 Unauthorized or 400 Bad Request
if (error.response && (error.response.status === 401 || error.response.status === 400)) {
// Check if the user is logged in by looking for 'userToken' in local storage
console.log(localStorage);
console.log(error.response);
if (!localStorage.getItem('userToken')) {
console.log('Missing user token');
// User is not logged in, redirect to the login page
// window.location.href = '/login';
}
Expand Down
2 changes: 1 addition & 1 deletion frontend/public/commitHash.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
f27ae7cb93ecca6fa995aebc9d914df8246a4260
04406ac7fab2d01ace9ce75e3006610919ce8c86

0 comments on commit ab95079

Please sign in to comment.