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,
|
2019-05-16 12:17:18 +02:00
|
|
|
modifyRole
|
2019-05-15 17:30:42 +02:00
|
|
|
} from "../modules/roles";
|
2019-05-16 12:17:18 +02:00
|
|
|
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,
|
2019-05-16 12:17:18 +02:00
|
|
|
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) => {
|
2019-05-16 12:17:18 +02:00
|
|
|
this.props.updateRole(role, () => this.repositoryRoleUpdated(role));
|
2019-05-15 17:30:42 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
render() {
|
2019-05-16 12:17:18 +02:00
|
|
|
const { error } = this.props;
|
|
|
|
|
|
|
|
|
|
if (error) {
|
|
|
|
|
return <ErrorNotification error={error} />;
|
|
|
|
|
}
|
|
|
|
|
|
2019-05-15 17:30:42 +02:00
|
|
|
return (
|
|
|
|
|
<>
|
|
|
|
|
<RepositoryRoleForm
|
2019-05-16 08:55:31 +02:00
|
|
|
nameDisabled={true}
|
2019-05-15 17:30:42 +02:00
|
|
|
role={this.props.role}
|
|
|
|
|
submitForm={role => this.updateRepositoryRole(role)}
|
|
|
|
|
/>
|
|
|
|
|
</>
|
|
|
|
|
);
|
2019-05-16 12:17:18 +02:00
|
|
|
}
|
2019-05-15 17:30:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const mapStateToProps = (state, ownProps) => {
|
|
|
|
|
const loading = isModifyRolePending(state);
|
2019-05-16 12:17:18 +02:00
|
|
|
const error = getModifyRoleFailure(state, ownProps.role.name);
|
2019-05-15 17:30:42 +02:00
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
loading,
|
2019-05-16 12:17:18 +02:00
|
|
|
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));
|