X-Git-Url: https://git.arvados.org/arvados-workbench2.git/blobdiff_plain/0240e28950f94b0911f2b22d55cc719d94bdff0e..10ce16c28de952f6533ca3cc9df909269e3d2a53:/src/views-components/create-project-dialog/create-project-dialog.tsx

diff --git a/src/views-components/create-project-dialog/create-project-dialog.tsx b/src/views-components/create-project-dialog/create-project-dialog.tsx
index c1d4e063..43621bf7 100644
--- a/src/views-components/create-project-dialog/create-project-dialog.tsx
+++ b/src/views-components/create-project-dialog/create-project-dialog.tsx
@@ -3,22 +3,38 @@
 // SPDX-License-Identifier: AGPL-3.0
 
 import { connect } from "react-redux";
-import { Dispatch } from "../../../node_modules/redux";
+import { Dispatch } from "redux";
+import { SubmissionError } from "redux-form";
+
 import { RootState } from "../../store/store";
-import DialogProjectCreate from "../dialog-create/dialog-project-create";
-import actions, { createProject } from "../../store/project/project-action";
+import  DialogProjectCreate from "../dialog-create/dialog-project-create";
+import { projectActions, createProject, getProjectList } from "../../store/project/project-action";
+import { dataExplorerActions } from "../../store/data-explorer/data-explorer-action";
+import { PROJECT_PANEL_ID } from "../../views/project-panel/project-panel";
 
 const mapStateToProps = (state: RootState) => ({
     open: state.projects.creator.opened
 });
 
+export const addProject = (data: { name: string, description: string }) =>
+    (dispatch: Dispatch, getState: () => RootState) => {
+        const { ownerUuid } = getState().projects.creator;
+        return dispatch<any>(createProject(data)).then(() => {
+            dispatch(dataExplorerActions.REQUEST_ITEMS({ id: PROJECT_PANEL_ID }));
+            dispatch<any>(getProjectList(ownerUuid));
+        });
+    };
+
 const mapDispatchToProps = (dispatch: Dispatch) => ({
     handleClose: () => {
-        dispatch(actions.CLOSE_PROJECT_CREATOR());
+        dispatch(projectActions.CLOSE_PROJECT_CREATOR());
     },
     onSubmit: (data: { name: string, description: string }) => {
-        dispatch<any>(createProject(data));
+        return dispatch<any>(addProject(data))
+            .catch((e: any) => {
+                throw new SubmissionError({ name: e.errors.join("").includes("UniqueViolation") ? "Project with this name already exists." : "" });
+            });
     }
 });
 
-export default connect(mapStateToProps, mapDispatchToProps)(DialogProjectCreate);
+export const CreateProjectDialog = connect(mapStateToProps, mapDispatchToProps)(DialogProjectCreate);
