1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
5 import { linkAccountPanelActions, LinkAccountPanelAction } from "store/link-account-panel/link-account-panel-actions";
6 import { UserResource } from "models/user";
8 export enum LinkAccountPanelStatus {
16 export enum LinkAccountPanelError {
23 export enum OriginatingUser {
29 export interface LinkAccountPanelState {
30 selectedCluster: string | undefined;
31 originatingUser: OriginatingUser | undefined;
32 targetUser: UserResource | undefined;
33 targetUserToken: string | undefined;
34 userToLink: UserResource | undefined;
35 userToLinkToken: string | undefined;
36 status: LinkAccountPanelStatus;
37 error: LinkAccountPanelError;
38 isProcessing: boolean;
41 const initialState = {
42 selectedCluster: undefined,
43 originatingUser: OriginatingUser.NONE,
44 targetUser: undefined,
45 targetUserToken: undefined,
46 userToLink: undefined,
47 userToLinkToken: undefined,
49 status: LinkAccountPanelStatus.NONE,
50 error: LinkAccountPanelError.NONE
53 export const linkAccountPanelReducer = (state: LinkAccountPanelState = initialState, action: LinkAccountPanelAction) =>
54 linkAccountPanelActions.match(action, {
56 LINK_INIT: ({ targetUser }) => ({
58 targetUser, targetUserToken: undefined,
59 userToLink: undefined, userToLinkToken: undefined,
60 status: LinkAccountPanelStatus.INITIAL, error: LinkAccountPanelError.NONE, originatingUser: OriginatingUser.NONE
62 LINK_LOAD: ({ originatingUser, userToLink, targetUser, targetUserToken, userToLinkToken}) => ({
65 targetUser, targetUserToken,
66 userToLink, userToLinkToken,
67 status: LinkAccountPanelStatus.LINKING, error: LinkAccountPanelError.NONE
69 LINK_INVALID: ({ originatingUser, targetUser, userToLink, error }) => ({
72 targetUser, targetUserToken: undefined,
73 userToLink, userToLinkToken: undefined,
74 error, status: LinkAccountPanelStatus.ERROR
76 SET_SELECTED_CLUSTER: ({ selectedCluster }) => ({
77 ...state, selectedCluster
79 SET_IS_PROCESSING: ({ isProcessing }) =>({
83 HAS_SESSION_DATA: () => ({
84 ...state, status: LinkAccountPanelStatus.HAS_SESSION_DATA