1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
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';
13 export interface ProjectUpdateFormDialogData {
19 export const PROJECT_UPDATE_FORM_NAME = 'projectUpdateFormName';
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: {} }));
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));
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;
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));