moved funcs from singleuser to deleteuser + renamed edit to general

This commit is contained in:
Florian Scholdei
2019-01-18 15:26:55 +01:00
parent c6b43ec460
commit b1b38276ab
4 changed files with 63 additions and 29 deletions

View File

@@ -38,8 +38,8 @@
"navigationLabel": "User Navigation", "navigationLabel": "User Navigation",
"informationNavLink": "Information", "informationNavLink": "Information",
"settingsNavLink": "Settings", "settingsNavLink": "Settings",
"editNavLink": "Edit", "editNavLink": "General",
"setPasswordNavLink": "Set password", "setPasswordNavLink": "Password",
"errorTitle": "Error", "errorTitle": "Error",
"errorSubtitle": "Unknown user error" "errorSubtitle": "Unknown user error"
}, },

View File

@@ -3,15 +3,37 @@ import React from "react";
import { translate } from "react-i18next"; import { translate } from "react-i18next";
import type { User } from "@scm-manager/ui-types"; import type { User } from "@scm-manager/ui-types";
import { DeleteButton, confirmAlert } from "@scm-manager/ui-components"; import { DeleteButton, confirmAlert } from "@scm-manager/ui-components";
import {connect} from "react-redux";
import {
deleteUser, fetchUserByName,
getDeleteUserFailure,
getUserByName,
isDeleteUserPending,
} from "../modules/users";
import type {History} from "history";
type Props = { type Props = {
user: User, user: User,
confirmDialog?: boolean, confirmDialog?: boolean,
// dispatcher functions
fetchUserByName: (string, string) => void,
deleteUser: (user: User, callback?: () => void) => void,
// context objects
t: string => string, t: string => string,
deleteUser: (user: User) => void history: History
}; };
class DeleteUser extends React.Component<Props> { class DeleteUser extends React.Component<Props> {
userDeleted = () => {
this.props.history.push("/users");
};
deleteUser = (user: User) => {
this.props.deleteUser(user, this.userDeleted);
};
static defaultProps = { static defaultProps = {
confirmDialog: true confirmDialog: true
}; };
@@ -53,4 +75,34 @@ class DeleteUser extends React.Component<Props> {
} }
} }
/*
const mapStateToProps = (state, ownProps) => {
const name = ownProps.match.params.name;
const user = getUserByName(state, name);
const loading = isDeleteUserPending(state, name);
const error = getDeleteUserFailure(state, name);
return {
name,
user,
loading,
error
};
};
const mapDispatchToProps = dispatch => {
return {
fetchUserByName: (link: string, name: string) => {
dispatch(fetchUserByName(link, name));
},
deleteUser: (user: User, callback?: () => void) => {
dispatch(deleteUser(user, callback));
}
};
};
export default connect(
mapStateToProps,
mapDispatchToProps
)(translate("users")(DeleteUser));
*/
export default translate("users")(DeleteUser); export default translate("users")(DeleteUser);

View File

@@ -2,7 +2,7 @@ import React from "react";
import { mount, shallow } from "enzyme"; import { mount, shallow } from "enzyme";
import "../../tests/enzyme"; import "../../tests/enzyme";
import "../../../tests/i18n"; import "../../../tests/i18n";
import DeleteUser from "../DeleteUser"; import DeleteUser from "./DeleteUser";
import { confirmAlert } from "@scm-manager/ui-components"; import { confirmAlert } from "@scm-manager/ui-components";
jest.mock("@scm-manager/ui-components", () => ({ jest.mock("@scm-manager/ui-components", () => ({

View File

@@ -17,14 +17,10 @@ import type { User } from "@scm-manager/ui-types";
import type { History } from "history"; import type { History } from "history";
import { import {
fetchUserByName, fetchUserByName,
deleteUser,
getUserByName, getUserByName,
isFetchUserPending, isFetchUserPending,
getFetchUserFailure, getFetchUserFailure
isDeleteUserPending,
getDeleteUserFailure
} from "../modules/users"; } from "../modules/users";
import { import {
EditUserNavLink, EditUserNavLink,
SetPasswordNavLink SetPasswordNavLink
@@ -40,8 +36,7 @@ type Props = {
error: Error, error: Error,
usersLink: string, usersLink: string,
// dispatcher functions // dispatcher function
deleteUser: (user: User, callback?: () => void) => void,
fetchUserByName: (string, string) => void, fetchUserByName: (string, string) => void,
// context objects // context objects
@@ -55,14 +50,6 @@ class SingleUser extends React.Component<Props> {
this.props.fetchUserByName(this.props.usersLink, this.props.name); this.props.fetchUserByName(this.props.usersLink, 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);
@@ -99,7 +86,7 @@ class SingleUser extends React.Component<Props> {
<div className="column is-three-quarters"> <div className="column is-three-quarters">
<Route path={url} exact component={() => <Details user={user} />} /> <Route path={url} exact component={() => <Details user={user} />} />
<Route <Route
path={`${url}/settings/edit`} path={`${url}/settings/general`}
component={() => <EditUser user={user} />} component={() => <EditUser user={user} />}
/> />
<Route <Route
@@ -115,10 +102,10 @@ class SingleUser extends React.Component<Props> {
label={t("single-user.informationNavLink")} label={t("single-user.informationNavLink")}
/> />
<SubNavigation <SubNavigation
to={`${url}/settings/edit`} to={`${url}/settings/general`}
label={t("single-user.settingsNavLink")} label={t("single-user.settingsNavLink")}
> >
<EditUserNavLink user={user} editUrl={`${url}/settings/edit`} /> <EditUserNavLink user={user} editUrl={`${url}/settings/general`} />
<SetPasswordNavLink <SetPasswordNavLink
user={user} user={user}
passwordUrl={`${url}/settings/password`} passwordUrl={`${url}/settings/password`}
@@ -136,10 +123,8 @@ class SingleUser extends React.Component<Props> {
const mapStateToProps = (state, ownProps) => { const mapStateToProps = (state, ownProps) => {
const name = ownProps.match.params.name; const name = ownProps.match.params.name;
const user = getUserByName(state, name); const user = getUserByName(state, name);
const loading = const loading = isFetchUserPending(state, name);
isFetchUserPending(state, name) || isDeleteUserPending(state, name); const error = getFetchUserFailure(state, name);
const error =
getFetchUserFailure(state, name) || getDeleteUserFailure(state, name);
const usersLink = getUsersLink(state); const usersLink = getUsersLink(state);
return { return {
usersLink, usersLink,
@@ -154,9 +139,6 @@ const mapDispatchToProps = dispatch => {
return { return {
fetchUserByName: (link: string, name: string) => { fetchUserByName: (link: string, name: string) => {
dispatch(fetchUserByName(link, name)); dispatch(fetchUserByName(link, name));
},
deleteUser: (user: User, callback?: () => void) => {
dispatch(deleteUser(user, callback));
} }
}; };
}; };