19690: dummy option now displays in colimn-selector
[arvados-workbench2.git] / src / store / link-account-panel / link-account-panel-actions.ts
index 108b77478727c0f3ce45298687580c60bafb7c4d..5ca7494f5e2f4d57b3b95517db72c5100a0f6254 100644 (file)
@@ -3,20 +3,20 @@
 // SPDX-License-Identifier: AGPL-3.0
 
 import { Dispatch } from "redux";
-import { RootState } from "~/store/store";
-import { getUserUuid } from "~/common/getuser";
-import { ServiceRepository, createServices, setAuthorizationHeader } from "~/services/services";
-import { setBreadcrumbs } from "~/store/breadcrumbs/breadcrumbs-actions";
-import { snackbarActions, SnackbarKind } from "~/store/snackbar/snackbar-actions";
-import { LinkAccountType, AccountToLink, LinkAccountStatus } from "~/models/link-account";
-import { authActions, getConfig } from "~/store/auth/auth-action";
-import { unionize, ofType, UnionOf } from '~/common/unionize';
-import { UserResource } from "~/models/user";
-import { GroupResource } from "~/models/group";
+import { RootState } from "store/store";
+import { getUserUuid } from "common/getuser";
+import { ServiceRepository, createServices, setAuthorizationHeader } from "services/services";
+import { setBreadcrumbs } from "store/breadcrumbs/breadcrumbs-actions";
+import { snackbarActions, SnackbarKind } from "store/snackbar/snackbar-actions";
+import { LinkAccountType, AccountToLink, LinkAccountStatus } from "models/link-account";
+import { authActions, getConfig } from "store/auth/auth-action";
+import { unionize, ofType, UnionOf } from 'common/unionize';
+import { UserResource } from "models/user";
+import { GroupResource } from "models/group";
 import { LinkAccountPanelError, OriginatingUser } from "./link-account-panel-reducer";
-import { login, logout } from "~/store/auth/auth-action";
-import { progressIndicatorActions } from "~/store/progress-indicator/progress-indicator-actions";
-import { WORKBENCH_LOADING_SCREEN } from '~/store/workbench/workbench-actions';
+import { login, logout } from "store/auth/auth-action";
+import { progressIndicatorActions } from "store/progress-indicator/progress-indicator-actions";
+import { WORKBENCH_LOADING_SCREEN } from 'store/workbench/workbench-actions';
 
 export const linkAccountPanelActions = unionize({
     LINK_INIT: ofType<{
@@ -73,16 +73,20 @@ export const checkForLinkStatus = () =>
             let msg: string;
             let msgKind: SnackbarKind;
             if (status.valueOf() === LinkAccountStatus.CANCELLED) {
-                msg = "Account link cancelled!", msgKind = SnackbarKind.INFO;
+                msg = "Account link cancelled!";
+                msgKind = SnackbarKind.INFO;
             }
             else if (status.valueOf() === LinkAccountStatus.FAILED) {
-                msg = "Account link failed!", msgKind = SnackbarKind.ERROR;
+                msg = "Account link failed!";
+                msgKind = SnackbarKind.ERROR;
             }
             else if (status.valueOf() === LinkAccountStatus.SUCCESS) {
-                msg = "Account link success!", msgKind = SnackbarKind.SUCCESS;
+                msg = "Account link success!";
+                msgKind = SnackbarKind.SUCCESS;
             }
             else {
-                msg = "Unknown Error!", msgKind = SnackbarKind.ERROR;
+                msg = "Unknown Error!";
+                msgKind = SnackbarKind.ERROR;
             }
             dispatch(snackbarActions.OPEN_SNACKBAR({ message: msg, kind: msgKind, hideDuration: 3000 }));
             services.linkAccountService.removeLinkOpStatus();
@@ -91,7 +95,7 @@ export const checkForLinkStatus = () =>
 
 export const switchUser = (user: UserResource, token: string) =>
     (dispatch: Dispatch<any>, getState: () => RootState, services: ServiceRepository) => {
-        dispatch(authActions.INIT({ user, token }));
+        dispatch(authActions.INIT_USER({ user, token }));
     };
 
 export const linkFailed = () =>
@@ -108,7 +112,7 @@ export const linkFailed = () =>
         }
         services.linkAccountService.removeAccountToLink();
         services.linkAccountService.saveLinkOpStatus(LinkAccountStatus.FAILED);
-        location.reload();
+        window.location.reload();
     };
 
 export const loadLinkAccountPanel = () =>
@@ -204,7 +208,9 @@ export const loadLinkAccountPanel = () =>
 
 export const startLinking = (t: LinkAccountType) =>
     (dispatch: Dispatch<any>, getState: () => RootState, services: ServiceRepository) => {
-        const accountToLink = { type: t, userUuid: getUserUuid(getState()), token: services.authService.getApiToken() } as AccountToLink;
+        const userUuid = getUserUuid(getState());
+        if (!userUuid) { return; }
+        const accountToLink = { type: t, userUuid, token: services.authService.getApiToken() } as AccountToLink;
         services.linkAccountService.saveAccountToLink(accountToLink);
 
         const auth = getState().auth;
@@ -240,7 +246,7 @@ export const cancelLinking = (reload: boolean = false) =>
         }
         finally {
             if (reload) {
-                location.reload();
+                window.location.reload();
             }
             else {
                 dispatch(progressIndicatorActions.STOP_WORKING(WORKBENCH_LOADING_SCREEN));
@@ -275,7 +281,7 @@ export const linkAccount = () =>
                 dispatch(switchUser(linkState.targetUser, linkState.targetUserToken));
                 services.linkAccountService.removeAccountToLink();
                 services.linkAccountService.saveLinkOpStatus(LinkAccountStatus.SUCCESS);
-                location.reload();
+                window.location.reload();
             }
             catch (e) {
                 // If the link operation fails, delete the previously made project