19567: Add cypress test for local resource copy to clipboard
[arvados-workbench2.git] / src / store / link-account-panel / link-account-panel-reducer.ts
index 4515cff44d2b66f7850dbb7374f1842e153a86bf..15d07810cd6b64064f936334409655e6a1965d4f 100644 (file)
@@ -2,19 +2,85 @@
 //
 // SPDX-License-Identifier: AGPL-3.0
 
-import { linkAccountPanelActions, LinkAccountPanelAction } from "~/store/link-account-panel/link-account-panel-actions";
-import { AccountToLink } from "~/models/link-account";
+import { linkAccountPanelActions, LinkAccountPanelAction } from "store/link-account-panel/link-account-panel-actions";
+import { UserResource } from "models/user";
+
+export enum LinkAccountPanelStatus {
+    NONE,
+    INITIAL,
+    HAS_SESSION_DATA,
+    LINKING,
+    ERROR
+}
+
+export enum LinkAccountPanelError {
+    NONE,
+    INACTIVE,
+    NON_ADMIN,
+    SAME_USER
+}
+
+export enum OriginatingUser {
+    NONE,
+    TARGET_USER,
+    USER_TO_LINK
+}
 
 export interface LinkAccountPanelState {
-    accountToLink: AccountToLink | undefined;
+    selectedCluster: string | undefined;
+    originatingUser: OriginatingUser | undefined;
+    targetUser: UserResource | undefined;
+    targetUserToken: string | undefined;
+    userToLink: UserResource | undefined;
+    userToLinkToken: string | undefined;
+    status: LinkAccountPanelStatus;
+    error: LinkAccountPanelError;
+    isProcessing: boolean;
 }
 
 const initialState = {
-    accountToLink: undefined
+    selectedCluster: undefined,
+    originatingUser: OriginatingUser.NONE,
+    targetUser: undefined,
+    targetUserToken: undefined,
+    userToLink: undefined,
+    userToLinkToken: undefined,
+    isProcessing: false,
+    status: LinkAccountPanelStatus.NONE,
+    error: LinkAccountPanelError.NONE
 };
 
 export const linkAccountPanelReducer = (state: LinkAccountPanelState = initialState, action: LinkAccountPanelAction) =>
     linkAccountPanelActions.match(action, {
         default: () => state,
-        LOAD_LINKING: (accountToLink) => ({ ...state, accountToLink }),
+        LINK_INIT: ({ targetUser }) => ({
+            ...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
+        }),
+        LINK_INVALID: ({ originatingUser, targetUser, userToLink, error }) => ({
+            ...state,
+            originatingUser,
+            targetUser, targetUserToken: undefined,
+            userToLink, userToLinkToken: undefined,
+            error, status: LinkAccountPanelStatus.ERROR
+        }),
+        SET_SELECTED_CLUSTER: ({ selectedCluster }) => ({
+            ...state, selectedCluster
+        }),
+        SET_IS_PROCESSING: ({ isProcessing }) =>({
+            ...state,
+            isProcessing
+        }),
+        HAS_SESSION_DATA: () => ({
+            ...state, status: LinkAccountPanelStatus.HAS_SESSION_DATA
+        })
     });
\ No newline at end of file