1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
5 import { Dispatch } from "redux";
14 import { RootState } from "store/store";
15 import { dialogActions } from "store/dialog/dialog-actions";
17 getCommonResourceServiceError,
18 CommonResourceServiceError
19 } from "services/common-service/common-resource-service";
20 import { ServiceRepository } from "services/services";
21 import { projectPanelActions } from 'store/project-panel/project-panel-action';
22 import { GroupClass } from "models/group";
23 import { Participant } from "views-components/sharing-dialog/participant-select";
24 import { ProjectProperties } from "./project-create-actions";
25 import { getResource } from "store/resources/resources";
26 import { ProjectResource } from "models/project";
28 export interface ProjectUpdateFormDialogData {
31 users?: Participant[];
33 properties?: ProjectProperties;
36 export const PROJECT_UPDATE_FORM_NAME = 'projectUpdateFormName';
37 export const PROJECT_UPDATE_PROPERTIES_FORM_NAME = 'projectUpdatePropertiesFormName';
38 export const PROJECT_UPDATE_FORM_SELECTOR = formValueSelector(PROJECT_UPDATE_FORM_NAME);
40 export const openProjectUpdateDialog = (resource: ProjectUpdateFormDialogData) =>
41 (dispatch: Dispatch, getState: () => RootState) => {
42 // Get complete project resource from store to handle consumers passing in partial resources
43 const project = getResource<ProjectResource>(resource.uuid)(getState().resources);
44 dispatch(initialize(PROJECT_UPDATE_FORM_NAME, project));
45 dispatch(dialogActions.OPEN_DIALOG({
46 id: PROJECT_UPDATE_FORM_NAME,
48 sourcePanel: GroupClass.PROJECT,
53 export const updateProject = (project: ProjectUpdateFormDialogData) =>
54 async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
55 const uuid = project.uuid || '';
56 dispatch(startSubmit(PROJECT_UPDATE_FORM_NAME));
58 const updatedProject = await services.projectService.update(
62 description: project.description,
63 properties: project.properties,
65 dispatch(projectPanelActions.REQUEST_ITEMS());
66 dispatch(reset(PROJECT_UPDATE_FORM_NAME));
67 dispatch(dialogActions.CLOSE_DIALOG({ id: PROJECT_UPDATE_FORM_NAME }));
68 return updatedProject;
70 const error = getCommonResourceServiceError(e);
71 if (error === CommonResourceServiceError.UNIQUE_NAME_VIOLATION) {
72 dispatch(stopSubmit(PROJECT_UPDATE_FORM_NAME, { name: 'Project with the same name already exists.' } as FormErrors));