Skip to content

Commit

Permalink
Merge pull request #202 from microbiomedata/201-handle-unauthorized-a…
Browse files Browse the repository at this point in the history
…lert

Handle unauthorized alert
  • Loading branch information
yxu-lanl authored Jun 20, 2024
2 parents 805bf51 + fa685f2 commit 1a3b415
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 5 deletions.
19 changes: 17 additions & 2 deletions webapp/client/src/common/util.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import axios from 'axios';
import { toast } from 'react-toastify';
import store from "../redux/store/store";
import { logout } from "../redux/actions/userActions";

//action notification
export const notify = (type, msg, timeout) => {
Expand All @@ -18,6 +20,11 @@ export const notify = (type, msg, timeout) => {
}
};

const signOut = (e) => {
store.dispatch(logout());
window.location.href = "/home";
}

//fetch data
export const postData = (url, params) => {
return new Promise(function (resolve, reject) {
Expand All @@ -28,6 +35,10 @@ export const postData = (url, params) => {
resolve(data);
})
.catch(err => {
if (err.response && err.response.status === 401) {
//Unauthorized
signOut();
}
if (err.response) {
reject(err.response.data);
} else {
Expand All @@ -48,6 +59,10 @@ export const getData = (url) => {
resolve(data);
})
.catch(err => {
if (err.response && err.response.status === 401) {
//Unauthorized
signOut();
}
if (err.response) {
reject(err.response.data);
} else {
Expand Down Expand Up @@ -130,8 +145,8 @@ export const popupWindow = (url, windowName, win, w, h) => {

export const validFile = (filename, path) => {
const regexp = new RegExp(/^https?:\/\/(?:www\.)?[-a-zA-Z0-9@:%._+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b(?:[-a-zA-Z0-9()@:%_+.~#?&/=]*)\/[a-zA-Z0-9()]{1}/, 'i');
if(filename === path) {

if (filename === path) {
//text input must be a http(s) url
return regexp.test(filename)
} else {
Expand Down
4 changes: 2 additions & 2 deletions webapp/client/src/containers/SubMenuBar.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ function SubMenuBar(props) {
handleClickClose={handleDialogClose}
/>
<div className="submenu" >
<span className="nmdc-header-no-min" style={{paddingLeft:'150px'}}></span>
<span className="nmdc-header-no-min" style={{paddingLeft:'50px'}}></span>
<CHeaderNavLink className="nmdc-header-no-min btn btn-pill btn-ghost-info" onClick={() => { setOpenDialog(true) }}>Import Old Projects/Uploads with Email/Passsword</CHeaderNavLink>
<CHeaderNavLink className="btn btn-pill btn-ghost-primary" to="/user/projectlist">My Projects</CHeaderNavLink>
<CHeaderNavLink className="btn btn-pill btn-ghost-primary" to="/user/allprojectlist">All Projects Available to Me</CHeaderNavLink>
Expand All @@ -42,7 +42,7 @@ function SubMenuBar(props) {
<CHeaderNavLink className="nmdc-header-no-min btn btn-pill btn-ghost-danger" to="/admin/userlist">Admin Users</CHeaderNavLink>
</>}

<span className="nmdc-header-no-min" style={{paddingRight:'150px'}}></span>
<span className="nmdc-header-no-min" style={{paddingRight:'50px'}}></span>
</div>
<hr />
</div>
Expand Down
4 changes: 3 additions & 1 deletion webapp/client/src/scss/_nmdc.scss
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@ $blue-base: #00aae7;
font-size: 12px;
text-transform: uppercase;
text-decoration: none;

cursor: pointer;

a {
color: #707070;
font-size: 12px;
Expand Down Expand Up @@ -194,6 +195,7 @@ $blue-base: #00aae7;
font-size: 12px;
text-transform: uppercase;
text-decoration: none;
cursor: pointer;

a {
color: #707070;
Expand Down

0 comments on commit 1a3b415

Please sign in to comment.