Restore current-token-dialog
[arvados.git] / src / store / current-token-dialog / current-token-dialog-actions.tsx
1 // Copyright (C) The Arvados Authors. All rights reserved.
2 //
3 // SPDX-License-Identifier: AGPL-3.0
4
5 import { dialogActions } from "~/store/dialog/dialog-actions";
6 import { getProperty } from '../properties/properties';
7 import { propertiesActions } from '~/store/properties/properties-actions';
8 import { RootState } from '~/store/store';
9
10 export const CURRENT_TOKEN_DIALOG_NAME = 'currentTokenDialog';
11 const API_HOST_PROPERTY_NAME = 'apiHost';
12
13 export interface CurrentTokenDialogData {
14     currentToken: string;
15     apiHost: string;
16 }
17
18 export const setCurrentTokenDialogApiHost = (apiHost: string) =>
19     propertiesActions.SET_PROPERTY({ key: API_HOST_PROPERTY_NAME, value: apiHost });
20
21 export const getCurrentTokenDialogData = (state: RootState): CurrentTokenDialogData => ({
22     apiHost: getProperty<string>(API_HOST_PROPERTY_NAME)(state.properties) || '',
23     currentToken: state.auth.apiToken || '',
24 });
25
26 export const openCurrentTokenDialog = dialogActions.OPEN_DIALOG({ id: CURRENT_TOKEN_DIALOG_NAME, data: {} });