Merge branch '21448-menu-reorder' into 21224-project-details
[arvados.git] / services / workbench2 / src / store / projects / project-lock-actions.ts
1 // Copyright (C) The Arvados Authors. All rights reserved.
2 //
3 // SPDX-License-Identifier: AGPL-3.0
4
5 import { Dispatch } from "redux";
6 import { ServiceRepository } from "services/services";
7 import { projectPanelActions } from "store/project-panel/project-panel-action-bind";
8 import { loadResource } from "store/resources/resources-actions";
9 import { RootState } from "store/store";
10 import { ContextMenuActionNames } from "views-components/context-menu/context-menu-action-set"; 
11 import { addDisabledButton, removeDisabledButton } from "store/multiselect/multiselect-actions";
12 import { snackbarActions, SnackbarKind } from "store/snackbar/snackbar-actions";
13
14 export const freezeProject = (uuid: string) => async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
15     dispatch<any>(addDisabledButton(ContextMenuActionNames.FREEZE_PROJECT))
16     const userUUID = getState().auth.user!.uuid;
17     let updatedProject;
18
19     try {
20         updatedProject = await services.projectService.update(uuid, {
21             frozenByUuid: userUUID,
22         });
23     } catch (e) {
24         console.error(e);
25         dispatch(snackbarActions.OPEN_SNACKBAR({ message: 'Could not freeze project', hideDuration: 4000, kind: SnackbarKind.ERROR }));
26     }
27
28     dispatch(projectPanelActions.REQUEST_ITEMS());
29     dispatch<any>(loadResource(uuid, false));
30     dispatch<any>(removeDisabledButton(ContextMenuActionNames.FREEZE_PROJECT))
31     return updatedProject;
32 };
33
34
35 export const unfreezeProject = (uuid: string) => async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
36     dispatch<any>(addDisabledButton(ContextMenuActionNames.FREEZE_PROJECT))
37     const updatedProject = await services.projectService.update(uuid, {
38         frozenByUuid: null,
39     });
40
41     dispatch(projectPanelActions.REQUEST_ITEMS());
42     dispatch<any>(loadResource(uuid, false));
43     dispatch<any>(removeDisabledButton(ContextMenuActionNames.FREEZE_PROJECT))
44     return updatedProject;
45 };