mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-18 03:01:05 +01:00
navigate back to users page after delete
This commit is contained in:
@@ -7,6 +7,7 @@ import { Details } from "./../components/table";
|
|||||||
import EditUser from "./EditUser";
|
import EditUser from "./EditUser";
|
||||||
import type { User } from "../types/User";
|
import type { User } from "../types/User";
|
||||||
import type { UserEntry } from "../types/UserEntry";
|
import type { UserEntry } from "../types/UserEntry";
|
||||||
|
import type { History } from "history";
|
||||||
import { fetchUser, deleteUser } from "../modules/users";
|
import { fetchUser, deleteUser } from "../modules/users";
|
||||||
import Loading from "../../components/Loading";
|
import Loading from "../../components/Loading";
|
||||||
|
|
||||||
@@ -18,8 +19,9 @@ type Props = {
|
|||||||
name: string,
|
name: string,
|
||||||
userEntry?: UserEntry,
|
userEntry?: UserEntry,
|
||||||
match: any,
|
match: any,
|
||||||
deleteUser: (user: User) => void,
|
deleteUser: (user: User, callback?: () => void) => void,
|
||||||
fetchUser: string => void
|
fetchUser: string => void,
|
||||||
|
history: History
|
||||||
};
|
};
|
||||||
|
|
||||||
class SingleUser extends React.Component<Props> {
|
class SingleUser extends React.Component<Props> {
|
||||||
@@ -27,6 +29,14 @@ class SingleUser extends React.Component<Props> {
|
|||||||
this.props.fetchUser(this.props.name);
|
this.props.fetchUser(this.props.name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
userDeleted = () => {
|
||||||
|
this.props.history.push("/users");
|
||||||
|
};
|
||||||
|
|
||||||
|
deleteUser = (user: User) => {
|
||||||
|
this.props.deleteUser(user, this.userDeleted);
|
||||||
|
};
|
||||||
|
|
||||||
stripEndingSlash = (url: string) => {
|
stripEndingSlash = (url: string) => {
|
||||||
if (url.endsWith("/")) {
|
if (url.endsWith("/")) {
|
||||||
return url.substring(0, url.length - 2);
|
return url.substring(0, url.length - 2);
|
||||||
@@ -34,8 +44,12 @@ class SingleUser extends React.Component<Props> {
|
|||||||
return url;
|
return url;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
matchedUrl = () => {
|
||||||
|
return this.stripEndingSlash(this.props.match.url);
|
||||||
|
};
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const { userEntry, match, deleteUser } = this.props;
|
const { userEntry } = this.props;
|
||||||
|
|
||||||
if (!userEntry || userEntry.loading) {
|
if (!userEntry || userEntry.loading) {
|
||||||
return <Loading />;
|
return <Loading />;
|
||||||
@@ -52,7 +66,7 @@ class SingleUser extends React.Component<Props> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const user = userEntry.entry;
|
const user = userEntry.entry;
|
||||||
const url = this.stripEndingSlash(match.url);
|
const url = this.matchedUrl();
|
||||||
|
|
||||||
// TODO i18n
|
// TODO i18n
|
||||||
|
|
||||||
@@ -73,7 +87,7 @@ class SingleUser extends React.Component<Props> {
|
|||||||
<NavLink to={`${url}/edit`} label="Edit" />
|
<NavLink to={`${url}/edit`} label="Edit" />
|
||||||
</Section>
|
</Section>
|
||||||
<Section label="Actions">
|
<Section label="Actions">
|
||||||
<DeleteUserButton user={user} deleteUser={deleteUser} />
|
<DeleteUserButton user={user} deleteUser={this.deleteUser} />
|
||||||
<NavLink to="/users" label="Back" />
|
<NavLink to="/users" label="Back" />
|
||||||
</Section>
|
</Section>
|
||||||
</Navigation>
|
</Navigation>
|
||||||
@@ -102,8 +116,8 @@ const mapDispatchToProps = dispatch => {
|
|||||||
fetchUser: (name: string) => {
|
fetchUser: (name: string) => {
|
||||||
dispatch(fetchUser(name));
|
dispatch(fetchUser(name));
|
||||||
},
|
},
|
||||||
deleteUser: (user: User) => {
|
deleteUser: (user: User, callback?: () => void) => {
|
||||||
dispatch(deleteUser(user));
|
dispatch(deleteUser(user, callback));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user