15840: Fixes merge
[arvados.git] / src / store / link-account-panel / link-account-panel-reducer.ts
index 93987ff3eaac78b4157f9bb9249aae5f49f8123c..21c2c9ebbc12fda9d92e5621ba6138b5c7243efe 100644 (file)
@@ -6,6 +6,7 @@ import { linkAccountPanelActions, LinkAccountPanelAction } from "~/store/link-ac
 import { UserResource } from "~/models/user";
 
 export enum LinkAccountPanelStatus {
+    NONE,
     INITIAL,
     HAS_SESSION_DATA,
     LINKING,
@@ -14,6 +15,7 @@ export enum LinkAccountPanelStatus {
 
 export enum LinkAccountPanelError {
     NONE,
+    INACTIVE,
     NON_ADMIN,
     SAME_USER
 }
@@ -25,6 +27,7 @@ export enum OriginatingUser {
 }
 
 export interface LinkAccountPanelState {
+    selectedCluster: string | undefined;
     originatingUser: OriginatingUser | undefined;
     targetUser: UserResource | undefined;
     targetUserToken: string | undefined;
@@ -32,15 +35,18 @@ export interface LinkAccountPanelState {
     userToLinkToken: string | undefined;
     status: LinkAccountPanelStatus;
     error: LinkAccountPanelError;
+    isProcessing: boolean;
 }
 
 const initialState = {
-    originatingUser: undefined,
+    selectedCluster: undefined,
+    originatingUser: OriginatingUser.NONE,
     targetUser: undefined,
     targetUserToken: undefined,
     userToLink: undefined,
     userToLinkToken: undefined,
-    status: LinkAccountPanelStatus.INITIAL,
+    isProcessing: false,
+    status: LinkAccountPanelStatus.NONE,
     error: LinkAccountPanelError.NONE
 };
 
@@ -48,13 +54,31 @@ export const linkAccountPanelReducer = (state: LinkAccountPanelState = initialSt
     linkAccountPanelActions.match(action, {
         default: () => state,
         LINK_INIT: ({ targetUser }) => ({
-            ...state, targetUser, status: LinkAccountPanelStatus.INITIAL, error: LinkAccountPanelError.NONE, originatingUser: OriginatingUser.NONE
+            ...state,
+            targetUser, targetUserToken: undefined,
+            userToLink: undefined, userToLinkToken: undefined,
+            status: LinkAccountPanelStatus.INITIAL, error: LinkAccountPanelError.NONE, originatingUser: OriginatingUser.NONE
         }),
         LINK_LOAD: ({ originatingUser, userToLink, targetUser, targetUserToken, userToLinkToken}) => ({
-            ...state, originatingUser, targetUser, targetUserToken, userToLink, userToLinkToken, status: LinkAccountPanelStatus.LINKING, error: LinkAccountPanelError.NONE
+            ...state,
+            originatingUser,
+            targetUser, targetUserToken,
+            userToLink, userToLinkToken,
+            status: LinkAccountPanelStatus.LINKING, error: LinkAccountPanelError.NONE
+        }),
+        LINK_INVALID: ({ originatingUser, targetUser, userToLink, error }) => ({
+            ...state,
+            originatingUser,
+            targetUser, targetUserToken: undefined,
+            userToLink, userToLinkToken: undefined,
+            error, status: LinkAccountPanelStatus.ERROR
+        }),
+        SET_SELECTED_CLUSTER: ({ selectedCluster }) => ({
+            ...state, selectedCluster
         }),
-        LINK_INVALID: ({originatingUser, targetUser, userToLink, error}) => ({
-            ...state, originatingUser, targetUser, userToLink, error, status: LinkAccountPanelStatus.ERROR
+        SET_IS_PROCESSING: ({ isProcessing }) =>({
+            ...state,
+            isProcessing
         }),
         HAS_SESSION_DATA: () => ({
             ...state, status: LinkAccountPanelStatus.HAS_SESSION_DATA