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-17 15:47:20 +02:00
|
|
|
import { ErrorNotification, Subtitle } from "@scm-manager/ui-components";
|
2019-05-16 13:36:11 +02:00
|
|
|
import type { RepositoryRole } from "@scm-manager/ui-types";
|
2019-05-17 15:47:20 +02:00
|
|
|
import type { History } from "history";
|
2019-05-17 08:50:32 +02:00
|
|
|
import DeleteRepositoryRole from "./DeleteRepositoryRole";
|
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
|
|
|
|
2019-05-17 15:47:20 +02:00
|
|
|
// context objects
|
|
|
|
|
t: string => string,
|
|
|
|
|
history: History,
|
|
|
|
|
|
2019-05-15 17:30:42 +02:00
|
|
|
//dispatch function
|
2019-05-17 16:31:01 +02:00
|
|
|
updateRole: (role: RepositoryRole, callback?: () => void) => void
|
2019-05-15 17:30:42 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class EditRepositoryRole extends React.Component<Props> {
|
2019-05-17 16:31:01 +02:00
|
|
|
repositoryRoleUpdated = () => {
|
|
|
|
|
this.props.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-17 16:31:01 +02:00
|
|
|
this.props.updateRole(role, this.repositoryRoleUpdated);
|
2019-05-15 17:30:42 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
render() {
|
2019-05-17 15:47:20 +02:00
|
|
|
const { error, t } = this.props;
|
2019-05-16 12:17:18 +02:00
|
|
|
|
|
|
|
|
if (error) {
|
|
|
|
|
return <ErrorNotification error={error} />;
|
|
|
|
|
}
|
|
|
|
|
|
2019-05-15 17:30:42 +02:00
|
|
|
return (
|
|
|
|
|
<>
|
2019-05-17 15:47:20 +02:00
|
|
|
<Subtitle subtitle={t("repositoryRole.editSubtitle")} />
|
2019-05-15 17:30:42 +02:00
|
|
|
<RepositoryRoleForm
|
|
|
|
|
role={this.props.role}
|
|
|
|
|
submitForm={role => this.updateRepositoryRole(role)}
|
|
|
|
|
/>
|
2019-05-17 08:50:32 +02:00
|
|
|
<hr/>
|
|
|
|
|
<DeleteRepositoryRole role={this.props.role}/>
|
2019-05-15 17:30:42 +02:00
|
|
|
</>
|
|
|
|
|
);
|
2019-05-16 12:17:18 +02:00
|
|
|
}
|
2019-05-15 17:30:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const mapStateToProps = (state, ownProps) => {
|
2019-05-17 16:31:01 +02:00
|
|
|
const loading = isModifyRolePending(state, ownProps.role.name);
|
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));
|