mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-11 16:05:44 +01:00
add Errorhandling to CreateRepoRole & EditRepoRole
This commit is contained in:
@@ -3,9 +3,10 @@ import React from "react";
|
|||||||
import RepositoryRoleForm from "./RepositoryRoleForm";
|
import RepositoryRoleForm from "./RepositoryRoleForm";
|
||||||
import { connect } from "react-redux";
|
import { connect } from "react-redux";
|
||||||
import { translate } from "react-i18next";
|
import { translate } from "react-i18next";
|
||||||
import { Title } from "@scm-manager/ui-components";
|
import { ErrorNotification, Title } from "@scm-manager/ui-components";
|
||||||
import {
|
import {
|
||||||
createRole,
|
createRole,
|
||||||
|
getCreateRoleFailure,
|
||||||
getFetchVerbsFailure,
|
getFetchVerbsFailure,
|
||||||
isFetchVerbsPending
|
isFetchVerbsPending
|
||||||
} from "../modules/roles";
|
} from "../modules/roles";
|
||||||
@@ -18,6 +19,7 @@ import {
|
|||||||
type Props = {
|
type Props = {
|
||||||
disabled: boolean,
|
disabled: boolean,
|
||||||
repositoryRolesLink: string,
|
repositoryRolesLink: string,
|
||||||
|
error?: Error,
|
||||||
|
|
||||||
//dispatch function
|
//dispatch function
|
||||||
addRole: (link: string, role: Role, callback?: () => void) => void,
|
addRole: (link: string, role: Role, callback?: () => void) => void,
|
||||||
@@ -27,7 +29,6 @@ type Props = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
class CreateRepositoryRole extends React.Component<Props> {
|
class CreateRepositoryRole extends React.Component<Props> {
|
||||||
|
|
||||||
repositoryRoleCreated = (role: Role) => {
|
repositoryRoleCreated = (role: Role) => {
|
||||||
const { history } = this.props;
|
const { history } = this.props;
|
||||||
history.push("/config/role/" + role.name + "/info");
|
history.push("/config/role/" + role.name + "/info");
|
||||||
@@ -40,7 +41,12 @@ class CreateRepositoryRole extends React.Component<Props> {
|
|||||||
};
|
};
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const { t } = this.props;
|
const { t, error } = this.props;
|
||||||
|
|
||||||
|
if (error) {
|
||||||
|
return <ErrorNotification error={error} />;
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<Title title={t("repositoryRole.title")} />
|
<Title title={t("repositoryRole.title")} />
|
||||||
@@ -55,7 +61,7 @@ class CreateRepositoryRole extends React.Component<Props> {
|
|||||||
|
|
||||||
const mapStateToProps = (state, ownProps) => {
|
const mapStateToProps = (state, ownProps) => {
|
||||||
const loading = isFetchVerbsPending(state);
|
const loading = isFetchVerbsPending(state);
|
||||||
const error = getFetchVerbsFailure(state);
|
const error = getFetchVerbsFailure(state) || getCreateRoleFailure(state);
|
||||||
const verbsLink = getRepositoryVerbsLink(state);
|
const verbsLink = getRepositoryVerbsLink(state);
|
||||||
const repositoryRolesLink = getRepositoryRolesLink(state);
|
const repositoryRolesLink = getRepositoryRolesLink(state);
|
||||||
|
|
||||||
|
|||||||
@@ -6,35 +6,38 @@ import { translate } from "react-i18next";
|
|||||||
import {
|
import {
|
||||||
getModifyRoleFailure,
|
getModifyRoleFailure,
|
||||||
isModifyRolePending,
|
isModifyRolePending,
|
||||||
modifyRole,
|
modifyRole
|
||||||
} from "../modules/roles";
|
} from "../modules/roles";
|
||||||
|
import { ErrorNotification } from "@scm-manager/ui-components";
|
||||||
import type { Role } from "@scm-manager/ui-types";
|
import type { Role } from "@scm-manager/ui-types";
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
disabled: boolean,
|
disabled: boolean,
|
||||||
role: Role,
|
role: Role,
|
||||||
repositoryRolesLink: string,
|
repositoryRolesLink: string,
|
||||||
|
error?: Error,
|
||||||
|
|
||||||
//dispatch function
|
//dispatch function
|
||||||
updateRole: (link: string, role: Role, callback?: () => void) => void
|
updateRole: (link: string, role: Role, callback?: () => void) => void
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class EditRepositoryRole extends React.Component<Props> {
|
class EditRepositoryRole extends React.Component<Props> {
|
||||||
|
|
||||||
repositoryRoleUpdated = (role: Role) => {
|
repositoryRoleUpdated = (role: Role) => {
|
||||||
const { history } = this.props;
|
const { history } = this.props;
|
||||||
history.push("/config/roles/");
|
history.push("/config/roles/");
|
||||||
};
|
};
|
||||||
|
|
||||||
updateRepositoryRole = (role: Role) => {
|
updateRepositoryRole = (role: Role) => {
|
||||||
this.props.updateRole(role, () =>
|
this.props.updateRole(role, () => this.repositoryRoleUpdated(role));
|
||||||
this.repositoryRoleUpdated(role)
|
|
||||||
);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
|
const { error } = this.props;
|
||||||
|
|
||||||
|
if (error) {
|
||||||
|
return <ErrorNotification error={error} />;
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<RepositoryRoleForm
|
<RepositoryRoleForm
|
||||||
@@ -44,16 +47,16 @@ class EditRepositoryRole extends React.Component<Props> {
|
|||||||
/>
|
/>
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
}w
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const mapStateToProps = (state, ownProps) => {
|
const mapStateToProps = (state, ownProps) => {
|
||||||
const loading = isModifyRolePending(state);
|
const loading = isModifyRolePending(state);
|
||||||
const error = getModifyRoleFailure(state);
|
const error = getModifyRoleFailure(state, ownProps.role.name);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
loading,
|
loading,
|
||||||
error,
|
error
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user