1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
5 import { Dispatch } from "redux";
6 import { initialize, startSubmit, stopSubmit } from 'redux-form';
7 import { RootState } from "~/store/store";
8 import { dialogActions } from "~/store/dialog/dialog-actions";
9 import { ContextMenuResource } from '~/store/context-menu/context-menu-reducer';
10 import { getCommonResourceServiceError, CommonResourceServiceError } from "~/common/api/common-resource-service";
11 import { ServiceRepository } from "~/services/services";
12 import { ProjectResource } from '~/models/project';
14 export interface ProjectUpdateFormDialogData {
20 export const PROJECT_UPDATE_FORM_NAME = 'projectUpdateFormName';
22 export const openProjectUpdateDialog = (resource: ContextMenuResource) =>
23 (dispatch: Dispatch) => {
24 dispatch(initialize(PROJECT_UPDATE_FORM_NAME, resource));
25 dispatch(dialogActions.OPEN_DIALOG({ id: PROJECT_UPDATE_FORM_NAME, data: {} }));
28 export const updateProject = (project: Partial<ProjectResource>) =>
29 async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
30 const uuid = project.uuid || '';
31 dispatch(startSubmit(PROJECT_UPDATE_FORM_NAME));
33 const updatedProject = await services.projectService.update(uuid, project);
34 dispatch(dialogActions.CLOSE_DIALOG({ id: PROJECT_UPDATE_FORM_NAME }));
35 return updatedProject;
37 const error = getCommonResourceServiceError(e);
38 if (error === CommonResourceServiceError.UNIQUE_VIOLATION) {
39 dispatch(stopSubmit(PROJECT_UPDATE_FORM_NAME, { name: 'Project with the same name already exists.' }));