Restore current-token-dialog
[arvados-workbench2.git] / src / store / current-token-dialog / current-token-dialog-actions.tsx
diff --git a/src/store/current-token-dialog/current-token-dialog-actions.tsx b/src/store/current-token-dialog/current-token-dialog-actions.tsx
new file mode 100644 (file)
index 0000000..030b18e
--- /dev/null
@@ -0,0 +1,26 @@
+// Copyright (C) The Arvados Authors. All rights reserved.
+//
+// SPDX-License-Identifier: AGPL-3.0
+
+import { dialogActions } from "~/store/dialog/dialog-actions";
+import { getProperty } from '../properties/properties';
+import { propertiesActions } from '~/store/properties/properties-actions';
+import { RootState } from '~/store/store';
+
+export const CURRENT_TOKEN_DIALOG_NAME = 'currentTokenDialog';
+const API_HOST_PROPERTY_NAME = 'apiHost';
+
+export interface CurrentTokenDialogData {
+    currentToken: string;
+    apiHost: string;
+}
+
+export const setCurrentTokenDialogApiHost = (apiHost: string) =>
+    propertiesActions.SET_PROPERTY({ key: API_HOST_PROPERTY_NAME, value: apiHost });
+
+export const getCurrentTokenDialogData = (state: RootState): CurrentTokenDialogData => ({
+    apiHost: getProperty<string>(API_HOST_PROPERTY_NAME)(state.properties) || '',
+    currentToken: state.auth.apiToken || '',
+});
+
+export const openCurrentTokenDialog = dialogActions.OPEN_DIALOG({ id: CURRENT_TOKEN_DIALOG_NAME, data: {} });