Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle unauthorized alert #202

Merged
merged 1 commit into from
Jun 20, 2024
Merged
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
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