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";
8 import { RootState } from "~/store/store";
9 import { snackbarActions } from "~/store/snackbar/snackbar-actions";
10 import { DialogProjectUpdate } from "../dialog-update/dialog-project-update";
11 import { projectActions, updateProject } from "~/store/project/project-action";
13 const mapStateToProps = (state: RootState) => ({
14 open: state.projects.updater.opened
17 const mapDispatchToProps = (dispatch: Dispatch) => ({
19 dispatch(projectActions.CLOSE_PROJECT_UPDATER());
21 onSubmit: (data: { name: string, description: string }) => {
22 return dispatch<any>(editProject(data))
25 throw new SubmissionError({ name: e.errors.join("").includes("UniqueViolation") ? "Project with this name already exists." : "" });
31 const editProject = (data: { name: string, description: string }) =>
32 (dispatch: Dispatch, getState: () => RootState) => {
33 const { uuid } = getState().projects.updater;
34 return dispatch<any>(updateProject(data)).then(() => {
35 dispatch(snackbarActions.OPEN_SNACKBAR({
36 message: "Project has been successfully updated.",
42 export const UpdateProjectDialog = connect(mapStateToProps, mapDispatchToProps)(DialogProjectUpdate);