15088: Saves account link data in session storage and logs out
authorEric Biagiotti <ebiagiotti@veritasgenetics.com>
Thu, 25 Apr 2019 19:16:09 +0000 (15:16 -0400)
committerEric Biagiotti <ebiagiotti@veritasgenetics.com>
Fri, 26 Apr 2019 14:26:14 +0000 (10:26 -0400)
Arvados-DCO-1.1-Signed-off-by: Eric Biagiotti <ebiagiotti@veritasgenetics.com>

src/models/link-account.ts [new file with mode: 0644]
src/store/link-account-panel/link-account-panel-actions.ts [moved from src/store/link-account/link-account-panel-actions.ts with 53% similarity]
src/store/workbench/workbench-actions.ts
src/views/link-account-panel/link-account-panel-root.tsx
src/views/link-account-panel/link-account-panel.tsx

diff --git a/src/models/link-account.ts b/src/models/link-account.ts
new file mode 100644 (file)
index 0000000..dd22bc9
--- /dev/null
@@ -0,0 +1,13 @@
+// Copyright (C) The Arvados Authors. All rights reserved.
+//
+// SPDX-License-Identifier: AGPL-3.0
+
+export enum LinkAccountType {
+    ADD_OTHER_LOGIN,
+    ACCESS_OTHER_ACCOUNT
+}
+
+export interface AccountToLink {
+    type: LinkAccountType;
+    userToken: string;
+}
similarity index 53%
rename from src/store/link-account/link-account-panel-actions.ts
rename to src/store/link-account-panel/link-account-panel-actions.ts
index 9d0b6a0552853e90a7a35791f45cbcb3387cea87..ff7df9b40b359557ed27d16362f41dec531d3882 100644 (file)
@@ -4,13 +4,19 @@
 
 import { Dispatch } from "redux";
 import { RootState } from "~/store/store";
-import { initialize } from "redux-form";
 import { ServiceRepository } from "~/services/services";
 import { setBreadcrumbs } from "~/store/breadcrumbs/breadcrumbs-actions";
-import { authActions } from "~/store/auth/auth-action";
-import { snackbarActions, SnackbarKind } from "~/store/snackbar/snackbar-actions";
+import { LinkAccountType, AccountToLink } from "~/models/link-account";
+import { logout } from "~/store/auth/auth-action";
 
 export const loadLinkAccountPanel = () =>
-    (dispatch: Dispatch<any>, getState: () => RootState, services: ServiceRepository) => {
+    (dispatch: Dispatch<any>) => {
        dispatch(setBreadcrumbs([{ label: 'Link account'}]));
     };
+
+export const saveAccountLinkData = (t: LinkAccountType) =>
+    (dispatch: Dispatch<any>, getState: () => RootState, services: ServiceRepository) => {
+        const accountToLink = {type: t, userToken: services.authService.getApiToken()} as AccountToLink;
+        sessionStorage.setItem("accountToLink", JSON.stringify(accountToLink));
+        dispatch(logout());
+    };
\ No newline at end of file
index 10f86a68087e08d64505eaae5eb2c0ef3d228ab1..163a18858b407b3fd612113a1877076f3d821ca6 100644 (file)
@@ -59,7 +59,7 @@ import { CopyFormDialogData } from '~/store/copy-dialog/copy-dialog';
 import { loadWorkflowPanel, workflowPanelActions } from '~/store/workflow-panel/workflow-panel-actions';
 import { loadSshKeysPanel } from '~/store/auth/auth-action-ssh';
 import { loadMyAccountPanel } from '~/store/my-account/my-account-panel-actions';
-import { loadLinkAccountPanel } from '~/store/link-account/link-account-panel-actions';
+import { loadLinkAccountPanel } from '~/store/link-account-panel/link-account-panel-actions';
 import { loadSiteManagerPanel } from '~/store/auth/auth-action-session';
 import { workflowPanelColumns } from '~/views/workflow-panel/workflow-panel-view';
 import { progressIndicatorActions } from '~/store/progress-indicator/progress-indicator-actions';
index ceb3ffaeb21ce0ef53ece5219c6252ea45037b6d..ce27d2658b7d4a04276c091d6d4f57c9b9fd4909 100644 (file)
@@ -15,6 +15,7 @@ import {
 } from '@material-ui/core';
 import { ArvadosTheme } from '~/common/custom-theme';
 import { User } from "~/models/user";
+import { LinkAccountType } from "~/models/link-account";
 import { formatDate }from "~/common/formatters";
 
 type CssRules = 'root';// | 'gridItem' | 'label' | 'title' | 'actions';
@@ -30,12 +31,14 @@ export interface LinkAccountPanelRootDataProps {
     user?: User;
 }
 
-export interface LinkAccountPanelRootActionProps { }
+export interface LinkAccountPanelRootActionProps {
+    saveAccountLinkData: (type: LinkAccountType) => void;
+}
 
 type LinkAccountPanelRootProps = LinkAccountPanelRootDataProps & LinkAccountPanelRootActionProps & WithStyles<CssRules>;
 
 export const LinkAccountPanelRoot = withStyles(styles) (
-    ({classes, user}: LinkAccountPanelRootProps) => {
+    ({classes, user, saveAccountLinkData}: LinkAccountPanelRootProps) => {
         return <Card className={classes.root}>
             <CardContent>
             <Grid container spacing={24}>
@@ -49,10 +52,14 @@ export const LinkAccountPanelRoot = withStyles(styles) (
             </Grid> }
             <Grid container item direction="row" spacing={24}>
                 <Grid item>
-                    <Button color="primary" variant="contained">Add another login to this account</Button>
+                    <Button color="primary" variant="contained" onClick={() => saveAccountLinkData(LinkAccountType.ADD_OTHER_LOGIN)}>
+                        Add another login to this account
+                    </Button>
                 </Grid>
                 <Grid item>
-                    <Button color="primary" variant="contained">Use this login to access another account</Button>
+                    <Button color="primary" variant="contained" onClick={() => saveAccountLinkData(LinkAccountType.ACCESS_OTHER_ACCOUNT)}>
+                        Use this login to access another account
+                    </Button>
                 </Grid>
             </Grid>
             </Grid>
index c49b511d65d94976f944269a9d6b54e6fbd6b0e0..eff8ca80a488d842839067e8ec477a91670a7c0b 100644 (file)
@@ -4,12 +4,9 @@
 
 import { RootState } from '~/store/store';
 import { Dispatch } from 'redux';
-import { compose } from 'redux';
-import { reduxForm } from 'redux-form';
 import { connect } from 'react-redux';
-import { getResource, ResourcesState } from '~/store/resources/resources';
-import { Resource } from '~/models/resource';
-import { User, UserResource } from '~/models/user';
+import { saveAccountLinkData } from '~/store/link-account-panel/link-account-panel-actions';
+import { LinkAccountType } from '~/models/link-account';
 import {
     LinkAccountPanelRoot,
     LinkAccountPanelRootDataProps,
@@ -22,6 +19,8 @@ const mapStateToProps = (state: RootState): LinkAccountPanelRootDataProps => {
     };
 };
 
-const mapDispatchToProps = (dispatch: Dispatch): LinkAccountPanelRootActionProps => ({});
+const mapDispatchToProps = (dispatch: Dispatch): LinkAccountPanelRootActionProps => ({
+    saveAccountLinkData: (type: LinkAccountType) => dispatch<any>(saveAccountLinkData(type))
+});
 
 export const LinkAccountPanel = connect(mapStateToProps, mapDispatchToProps)(LinkAccountPanelRoot);