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";
27 import { snackbarActions, SnackbarKind } from "store/snackbar/snackbar-actions";
29 export interface ProjectUpdateFormDialogData {
32 users?: Participant[];
34 properties?: ProjectProperties;
37 export const PROJECT_UPDATE_FORM_NAME = 'projectUpdateFormName';
38 export const PROJECT_UPDATE_PROPERTIES_FORM_NAME = 'projectUpdatePropertiesFormName';
39 export const PROJECT_UPDATE_FORM_SELECTOR = formValueSelector(PROJECT_UPDATE_FORM_NAME);
41 export const openProjectUpdateDialog = (resource: ProjectUpdateFormDialogData) =>
42 (dispatch: Dispatch, getState: () => RootState) => {
43 // Get complete project resource from store to handle consumers passing in partial resources
44 const project = getResource<ProjectResource>(resource.uuid)(getState().resources);
45 dispatch(initialize(PROJECT_UPDATE_FORM_NAME, project));
46 dispatch(dialogActions.OPEN_DIALOG({
47 id: PROJECT_UPDATE_FORM_NAME,
49 sourcePanel: GroupClass.PROJECT,
54 export const updateProject = (project: ProjectUpdateFormDialogData) =>
55 async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
56 const uuid = project.uuid || '';
57 dispatch(startSubmit(PROJECT_UPDATE_FORM_NAME));
59 const updatedProject = await services.projectService.update(
63 description: project.description,
64 properties: project.properties,
67 dispatch(projectPanelActions.REQUEST_ITEMS());
68 dispatch(reset(PROJECT_UPDATE_FORM_NAME));
69 dispatch(dialogActions.CLOSE_DIALOG({ id: PROJECT_UPDATE_FORM_NAME }));
70 return updatedProject;
72 const error = getCommonResourceServiceError(e);
73 if (error === CommonResourceServiceError.UNIQUE_NAME_VIOLATION) {
74 dispatch(stopSubmit(PROJECT_UPDATE_FORM_NAME, { name: 'Project with the same name already exists.' } as FormErrors));
76 dispatch(dialogActions.CLOSE_DIALOG({ id: PROJECT_UPDATE_FORM_NAME }));
77 const errMsg = e.errors
79 : 'There was an error while updating the project';
80 dispatch(snackbarActions.OPEN_SNACKBAR({
83 kind: SnackbarKind.ERROR }));