X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/b6a5b173cd4e9f325f371d26204dfe156d911c20..838af71bfe460c7f5a03121acf8a4d239893cdac:/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 2f3e0b7fe3..43f56ed894 100644
--- a/src/views-components/create-project-dialog/create-project-dialog.tsx
+++ b/src/views-components/create-project-dialog/create-project-dialog.tsx
@@ -4,21 +4,27 @@
 
 import { connect } from "react-redux";
 import { Dispatch } from "redux";
-import { RootState } from "../../store/store";
-import { DialogProjectCreate as DialogProjectCreateComponent } 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";
+import { SubmissionError } from "redux-form";
+
+import { RootState } from "~/store/store";
+import { DialogProjectCreate } from "../dialog-create/dialog-project-create";
+import { projectActions, createProject, getProjectList } from "~/store/project/project-action";
+import { projectPanelActions } from "~/store/project-panel/project-panel-action";
+import { snackbarActions } from "~/store/snackbar/snackbar-actions";
 
 const mapStateToProps = (state: RootState) => ({
     open: state.projects.creator.opened
 });
 
-const submit = (data: { name: string, description: string }) =>
+const addProject = (data: { name: string, description: string }) =>
     (dispatch: Dispatch, getState: () => RootState) => {
         const { ownerUuid } = getState().projects.creator;
-        dispatch<any>(createProject(data)).then(() => {
-            dispatch(dataExplorerActions.REQUEST_ITEMS({ id: PROJECT_PANEL_ID }));
+        return dispatch<any>(createProject(data)).then(() => {
+            dispatch(snackbarActions.OPEN_SNACKBAR({
+                message: "Project has been successfully created.",
+                hideDuration: 2000
+            }));
+            dispatch(projectPanelActions.REQUEST_ITEMS());
             dispatch<any>(getProjectList(ownerUuid));
         });
     };
@@ -28,8 +34,11 @@ const mapDispatchToProps = (dispatch: Dispatch) => ({
         dispatch(projectActions.CLOSE_PROJECT_CREATOR());
     },
     onSubmit: (data: { name: string, description: string }) => {
-        dispatch<any>(submit(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 const CreateProjectDialog = connect(mapStateToProps, mapDispatchToProps)(DialogProjectCreateComponent);
+export const CreateProjectDialog = connect(mapStateToProps, mapDispatchToProps)(DialogProjectCreate);
