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 {
14 export enum LinkAccountPanelError {
20 export enum OriginatingUser {
26 export interface LinkAccountPanelState {
27 originatingUser: OriginatingUser | undefined;
28 targetUser: UserResource | undefined;
29 targetUserToken: string | undefined;
30 userToLink: UserResource | undefined;
31 userToLinkToken: string | undefined;
32 status: LinkAccountPanelStatus;
33 error: LinkAccountPanelError;
36 const initialState = {
37 originatingUser: undefined,
38 targetUser: undefined,
39 targetUserToken: undefined,
40 userToLink: undefined,
41 userToLinkToken: undefined,
42 status: LinkAccountPanelStatus.INITIAL,
43 error: LinkAccountPanelError.NONE
46 export const linkAccountPanelReducer = (state: LinkAccountPanelState = initialState, action: LinkAccountPanelAction) =>
47 linkAccountPanelActions.match(action, {
49 LINK_INIT: ({ targetUser }) => ({
50 ...state, targetUser, status: LinkAccountPanelStatus.INITIAL, error: LinkAccountPanelError.NONE, originatingUser: OriginatingUser.NONE
52 LINK_LOAD: ({ originatingUser, userToLink, targetUser, targetUserToken, userToLinkToken}) => ({
53 ...state, originatingUser, targetUser, targetUserToken, userToLink, userToLinkToken, status: LinkAccountPanelStatus.LINKING, error: LinkAccountPanelError.NONE
55 LINK_INVALID: ({originatingUser, targetUser, userToLink, error}) => ({
56 ...state, originatingUser, targetUser, userToLink, error, status: LinkAccountPanelStatus.ERROR