17119: the "Move to" dialog should not show filter groups as a potential
[arvados-workbench2.git] / src / store / projects / project-update-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 { FormErrors, initialize, startSubmit, stopSubmit } from 'redux-form';
7 import { RootState } from "~/store/store";
8 import { dialogActions } from "~/store/dialog/dialog-actions";
9 import { getCommonResourceServiceError, CommonResourceServiceError } from "~/services/common-service/common-resource-service";
10 import { ServiceRepository } from "~/services/services";
11 import { projectPanelActions } from '~/store/project-panel/project-panel-action';
12
13 export interface ProjectUpdateFormDialogData {
14     uuid: string;
15     name: string;
16     description?: string;
17 }
18
19 export const PROJECT_UPDATE_FORM_NAME = 'projectUpdateFormName';
20
21 export const openProjectUpdateDialog = (resource: ProjectUpdateFormDialogData) =>
22     (dispatch: Dispatch, getState: () => RootState) => {
23         dispatch(initialize(PROJECT_UPDATE_FORM_NAME, resource));
24         dispatch(dialogActions.OPEN_DIALOG({ id: PROJECT_UPDATE_FORM_NAME, data: {} }));
25     };
26
27 export const updateProject = (project: ProjectUpdateFormDialogData) =>
28     async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
29         const uuid = project.uuid || '';
30         dispatch(startSubmit(PROJECT_UPDATE_FORM_NAME));
31         try {
32             const updatedProject = await services.projectService.update(uuid, { name: project.name, description: project.description });
33             dispatch(projectPanelActions.REQUEST_ITEMS());
34             dispatch(dialogActions.CLOSE_DIALOG({ id: PROJECT_UPDATE_FORM_NAME }));
35             return updatedProject;
36         } catch (e) {
37             const error = getCommonResourceServiceError(e);
38             if (error === CommonResourceServiceError.UNIQUE_NAME_VIOLATION) {
39                 dispatch(stopSubmit(PROJECT_UPDATE_FORM_NAME, { name: 'Project with the same name already exists.' } as FormErrors));
40             }
41             return ;
42         }
43     };