1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
5 import { connect } from "react-redux";
6 import { Dispatch } from "redux";
7 import { SubmissionError } from "redux-form";
9 import { RootState } from "~/store/store";
10 import { DialogProjectCreate } from "../dialog-create/dialog-project-create";
11 import { projectActions, createProject, getProjectList } from "~/store/project/project-action";
12 import { projectPanelActions } from "~/store/project-panel/project-panel-action";
13 import { snackbarActions } from "~/store/snackbar/snackbar-actions";
15 const mapStateToProps = (state: RootState) => ({
16 open: state.projects.creator.opened
19 const addProject = (data: { name: string, description: string }) =>
20 (dispatch: Dispatch, getState: () => RootState) => {
21 const { ownerUuid } = getState().projects.creator;
22 return dispatch<any>(createProject(data)).then(() => {
23 dispatch(snackbarActions.OPEN_SNACKBAR({
24 message: "Project has been successfully created.",
27 dispatch(projectPanelActions.REQUEST_ITEMS());
28 dispatch<any>(getProjectList(ownerUuid));
32 const mapDispatchToProps = (dispatch: Dispatch) => ({
34 dispatch(projectActions.CLOSE_PROJECT_CREATOR());
36 onSubmit: (data: { name: string, description: string }) => {
37 return dispatch<any>(addProject(data))
39 throw new SubmissionError({ name: e.errors.join("").includes("UniqueViolation") ? "Project with this name already exists." : "" });
44 export const CreateProjectDialog = connect(mapStateToProps, mapDispatchToProps)(DialogProjectCreate);