Files
SCM-Manager/scm-ui/src/config/roles/containers/EditRepositoryRole.js

79 lines
1.7 KiB
JavaScript
Raw Normal View History

2019-05-15 17:30:42 +02:00
// @flow
import React from "react";
import RepositoryRoleForm from "./RepositoryRoleForm";
import { connect } from "react-redux";
import { translate } from "react-i18next";
import {
getModifyRoleFailure,
isModifyRolePending,
modifyRole
2019-05-15 17:30:42 +02:00
} from "../modules/roles";
import { ErrorNotification } from "@scm-manager/ui-components";
2019-05-16 13:36:11 +02:00
import type { RepositoryRole } from "@scm-manager/ui-types";
2019-05-15 17:30:42 +02:00
type Props = {
disabled: boolean,
2019-05-16 13:36:11 +02:00
role: RepositoryRole,
2019-05-15 17:30:42 +02:00
repositoryRolesLink: string,
error?: Error,
2019-05-15 17:30:42 +02:00
//dispatch function
2019-05-16 13:36:11 +02:00
updateRole: (
link: string,
role: RepositoryRole,
callback?: () => void
) => void
2019-05-15 17:30:42 +02:00
};
class EditRepositoryRole extends React.Component<Props> {
2019-05-16 13:36:11 +02:00
repositoryRoleUpdated = (role: RepositoryRole) => {
2019-05-15 17:30:42 +02:00
const { history } = this.props;
2019-05-16 10:01:33 +02:00
history.push("/config/roles/");
2019-05-15 17:30:42 +02:00
};
2019-05-16 13:36:11 +02:00
updateRepositoryRole = (role: RepositoryRole) => {
this.props.updateRole(role, () => this.repositoryRoleUpdated(role));
2019-05-15 17:30:42 +02:00
};
render() {
const { error } = this.props;
if (error) {
return <ErrorNotification error={error} />;
}
2019-05-15 17:30:42 +02:00
return (
<>
<RepositoryRoleForm
nameDisabled={true}
2019-05-15 17:30:42 +02:00
role={this.props.role}
submitForm={role => this.updateRepositoryRole(role)}
/>
</>
);
}
2019-05-15 17:30:42 +02:00
}
const mapStateToProps = (state, ownProps) => {
const loading = isModifyRolePending(state);
const error = getModifyRoleFailure(state, ownProps.role.name);
2019-05-15 17:30:42 +02:00
return {
loading,
error
2019-05-15 17:30:42 +02:00
};
};
const mapDispatchToProps = dispatch => {
return {
2019-05-16 13:36:11 +02:00
updateRole: (role: RepositoryRole, callback?: () => void) => {
2019-05-15 17:30:42 +02:00
dispatch(modifyRole(role, callback));
}
};
};
export default connect(
mapStateToProps,
mapDispatchToProps
)(translate("config")(EditRepositoryRole));