add Errorhandling to CreateRepoRole & EditRepoRole

This commit is contained in:
Eduard Heimbuch
2019-05-16 12:17:18 +02:00
parent 3461f6680b
commit 46456d0390
2 changed files with 23 additions and 14 deletions

View File

@@ -6,35 +6,38 @@ import { translate } from "react-i18next";
import {
getModifyRoleFailure,
isModifyRolePending,
modifyRole,
modifyRole
} from "../modules/roles";
import { ErrorNotification } from "@scm-manager/ui-components";
import type { Role } from "@scm-manager/ui-types";
type Props = {
disabled: boolean,
role: Role,
repositoryRolesLink: string,
error?: Error,
//dispatch function
updateRole: (link: string, role: Role, callback?: () => void) => void
};
class EditRepositoryRole extends React.Component<Props> {
repositoryRoleUpdated = (role: Role) => {
const { history } = this.props;
history.push("/config/roles/");
};
updateRepositoryRole = (role: Role) => {
this.props.updateRole(role, () =>
this.repositoryRoleUpdated(role)
);
this.props.updateRole(role, () => this.repositoryRoleUpdated(role));
};
render() {
const { error } = this.props;
if (error) {
return <ErrorNotification error={error} />;
}
return (
<>
<RepositoryRoleForm
@@ -44,16 +47,16 @@ class EditRepositoryRole extends React.Component<Props> {
/>
</>
);
}w
}
}
const mapStateToProps = (state, ownProps) => {
const loading = isModifyRolePending(state);
const error = getModifyRoleFailure(state);
const error = getModifyRoleFailure(state, ownProps.role.name);
return {
loading,
error,
error
};
};