X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/13700efea8cd742fbb4888252f3d06788f5fd845..c6314ca47008f1ffd0fe70fe025a57475b64e773:/src/store/link-account-panel/link-account-panel-reducer.ts diff --git a/src/store/link-account-panel/link-account-panel-reducer.ts b/src/store/link-account-panel/link-account-panel-reducer.ts index 7f7e3eb38c..21c2c9ebbc 100644 --- a/src/store/link-account-panel/link-account-panel-reducer.ts +++ b/src/store/link-account-panel/link-account-panel-reducer.ts @@ -6,48 +6,81 @@ import { linkAccountPanelActions, LinkAccountPanelAction } from "~/store/link-ac 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 { - user: UserResource | undefined; - userToken: string | 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 = { - user: undefined, - userToken: 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 }; export const linkAccountPanelReducer = (state: LinkAccountPanelState = initialState, action: LinkAccountPanelAction) => linkAccountPanelActions.match(action, { default: () => state, - INIT: ({ user }) => ({ - ...state, user, state: LinkAccountPanelStatus.INITIAL, error: LinkAccountPanelError.NONE + 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 }), - LOAD: ({ userToLink, user, userToken, userToLinkToken}) => ({ - ...state, user, userToken, userToLink, userToLinkToken, status: LinkAccountPanelStatus.LINKING, error: LinkAccountPanelError.NONE + SET_SELECTED_CLUSTER: ({ selectedCluster }) => ({ + ...state, selectedCluster }), - RESET: () => ({ - ...state, userToken: undefined, userToLink: undefined, userToLinkToken: undefined, status: LinkAccountPanelStatus.INITIAL, error: LinkAccountPanelError.NONE + SET_IS_PROCESSING: ({ isProcessing }) =>({ + ...state, + isProcessing }), - INVALID: ({user, userToLink, error}) => ({ - ...state, user, userToLink, error, status: LinkAccountPanelStatus.ERROR + HAS_SESSION_DATA: () => ({ + ...state, status: LinkAccountPanelStatus.HAS_SESSION_DATA }) }); \ No newline at end of file