X-Git-Url: https://git.arvados.org/arvados-workbench2.git/blobdiff_plain/62ff5a943865229c1630c66366f824511048ce63..7e323d0c3e6734e6ca698c6bffcb9c24ef5acd13:/src/store/auth/auth-reducer.ts?ds=sidebyside diff --git a/src/store/auth/auth-reducer.ts b/src/store/auth/auth-reducer.ts index 8a30a2a6..a8e4340a 100644 --- a/src/store/auth/auth-reducer.ts +++ b/src/store/auth/auth-reducer.ts @@ -5,12 +5,12 @@ import { authActions, AuthAction } from "./auth-action"; import { User } from "~/models/user"; import { ServiceRepository } from "~/services/services"; -import { SshKey } from '~/models/ssh-key'; +import { SshKeyResource } from '~/models/ssh-key'; export interface AuthState { user?: User; apiToken?: string; - sshKeys?: SshKey[]; + sshKeys: SshKeyResource[]; } const initialState: AuthState = { @@ -19,13 +19,13 @@ const initialState: AuthState = { sshKeys: [] }; -export const authReducer = (services: ServiceRepository) => (state: AuthState = initialState, action: AuthAction) => { +export const authReducer = (services: ServiceRepository) => (state = initialState, action: AuthAction) => { return authActions.match(action, { SAVE_API_TOKEN: (token: string) => { return {...state, apiToken: token}; }, INIT: ({ user, token }) => { - return { user, apiToken: token }; + return { ...state, user, apiToken: token }; }, LOGIN: () => { return state; @@ -36,11 +36,14 @@ export const authReducer = (services: ServiceRepository) => (state: AuthState = USER_DETAILS_SUCCESS: (user: User) => { return {...state, user}; }, - SET_SSH_KEYS: (sshKeys: SshKey[]) => { + SET_SSH_KEYS: (sshKeys: SshKeyResource[]) => { return {...state, sshKeys}; }, - ADD_SSH_KEY: (sshKey: SshKey) => { - return { ...state, sshKeys: state.sshKeys!.concat(sshKey) }; + ADD_SSH_KEY: (sshKey: SshKeyResource) => { + return { ...state, sshKeys: state.sshKeys.concat(sshKey) }; + }, + REMOVE_SSH_KEY: (uuid: string) => { + return { ...state, sshKeys: state.sshKeys.filter((sshKey) => sshKey.uuid !== uuid )}; }, default: () => state });