Skip to content

Commit 762940d

Browse files
committed
more code removal and refactor
1 parent a51215d commit 762940d

File tree

6 files changed

+27
-39
lines changed

6 files changed

+27
-39
lines changed

dashboard/src/actions/authActions.js

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,8 @@ import * as TYPES from "./types";
44

55
import Cookies from "js-cookie";
66
import { SUCCESS } from "assets/constants/overviewConstants";
7-
import { showToast } from "actions/toastActions";
7+
import { showToast, clearToast } from "actions/toastActions";
88

9-
const maxWait = 50000; // Milliseconds
109
/**
1110
* Wait for the Pbench Server endpoints to be loaded.
1211
* @param {getState} getState object.
@@ -22,7 +21,7 @@ export function waitForEndpoints(getState) {
2221
function check(resolve, reject) {
2322
if (Object.keys(getState().apiEndpoint.endpoints).length !== 0) {
2423
resolve("Endpoints loaded");
25-
} else if (Date.now() - waitStart > maxWait) {
24+
} else if (Date.now() - waitStart > CONSTANTS.MAX_WAIT_MS) {
2625
reject(new Error("Timed out waiting for endpoints request"));
2726
} else {
2827
setTimeout(check, 250, resolve, reject);
@@ -47,11 +46,8 @@ export const authCookies = () => async (dispatch, getState) => {
4746
};
4847

4948
export const movePage = (toPage, navigate) => async (dispatch) => {
50-
// empty the alerts
51-
dispatch({
52-
type: TYPES.USER_NOTION_ALERTS,
53-
payload: [],
54-
});
49+
// clear all the toasts before navigating to another page
50+
dispatch(clearToast());
5551
navigate(toPage);
5652
};
5753

dashboard/src/actions/overviewActions.js

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,13 @@ import API from "../utils/axiosInstance";
55
import { DANGER } from "assets/constants/toastConstants";
66
import { findNoOfDays } from "utils/dateFunctions";
77
import { showToast } from "./toastActions";
8+
import { clearCachedSession } from "./authActions";
89

910
export const getDatasets = () => async (dispatch, getState) => {
1011
const alreadyRendered = getState().overview.loadingDone;
1112
try {
1213
const keycloak = getState().apiEndpoint.keycloak;
13-
const username = keycloak?.idTokenParsed?.preferred_username;
14+
const username = keycloak.idTokenParsed.preferred_username;
1415

1516
if (alreadyRendered) {
1617
dispatch({ type: TYPES.LOADING });
@@ -43,8 +44,14 @@ export const getDatasets = () => async (dispatch, getState) => {
4344
}
4445
}
4546
} catch (error) {
46-
dispatch(showToast(DANGER, error?.response?.data?.message));
47-
dispatch({ type: TYPES.NETWORK_ERROR });
47+
if (!error?.response) {
48+
dispatch(showToast(DANGER, "Not Authenticated"));
49+
dispatch({ type: TYPES.OPENID_ERROR });
50+
dispatch(clearCachedSession());
51+
} else {
52+
dispatch(showToast(DANGER, error?.response?.data?.message));
53+
dispatch({ type: TYPES.NETWORK_ERROR });
54+
}
4855
}
4956
if (alreadyRendered) {
5057
dispatch({ type: TYPES.COMPLETED });
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
11
export const LOGOUT_DELAY_MS = 2000;
2-
export const EXPIRY_KEEPUSER_DAYS = 7;
3-
export const EXPIRY_DEFAULT_DAYS = 0.5;
2+
export const MAX_WAIT_MS = 10000;

dashboard/src/modules/components/ProfileComponent/index.jsx

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,9 @@ const ProfileComponent = () => {
5454
{
5555
<TextContent>
5656
<Text component={TextVariants.h5}>
57-
{keycloak.tokenParsed?.given_name}
57+
{keycloak.tokenParsed?.given_name
58+
? keycloak.tokenParsed?.given_name
59+
: ""}
5860
</Text>
5961
</TextContent>
6062
}
@@ -64,7 +66,9 @@ const ProfileComponent = () => {
6466
{
6567
<TextContent>
6668
<Text component={TextVariants.h5}>
67-
{keycloak.tokenParsed?.family_name}
69+
{keycloak.tokenParsed?.family_name
70+
? keycloak.tokenParsed?.family_name
71+
: ""}
6872
</Text>
6973
</TextContent>
7074
}
@@ -76,7 +80,9 @@ const ProfileComponent = () => {
7680
{
7781
<TextContent>
7882
<Text component={TextVariants.h5}>
79-
{keycloak.tokenParsed?.preferred_username}
83+
{keycloak.tokenParsed?.preferred_username
84+
? keycloak.tokenParsed?.preferred_username
85+
: ""}
8086
</Text>
8187
</TextContent>
8288
}
@@ -86,7 +92,9 @@ const ProfileComponent = () => {
8692
{
8793
<TextContent>
8894
<Text component={TextVariants.h5}>
89-
{keycloak.tokenParsed?.email}
95+
{keycloak.tokenParsed?.email
96+
? keycloak.tokenParsed?.email
97+
: ""}
9098
</Text>
9199
</TextContent>
92100
}

dashboard/src/reducers/authReducer.js

Lines changed: 0 additions & 20 deletions
This file was deleted.

dashboard/src/reducers/index.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import AuthReducer from "./authReducer";
21
import DatasetListReducer from "./datasetListReducer";
32
import EndpointReducer from "./endpointReducer";
43
import LoadingReducer from "./loadingReducer";
@@ -12,7 +11,6 @@ import { combineReducers } from "redux";
1211
export default combineReducers({
1312
toastReducer: ToastReducer,
1413
loading: LoadingReducer,
15-
userAuth: AuthReducer,
1614
navOpen: NavbarReducer,
1715
datasetlist: DatasetListReducer,
1816
apiEndpoint: EndpointReducer,

0 commit comments

Comments
 (0)