mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-14 09:25:43 +01:00
first try on delete user
This commit is contained in:
56
scm-ui/src/users/components/DeleteUser.js
Normal file
56
scm-ui/src/users/components/DeleteUser.js
Normal file
@@ -0,0 +1,56 @@
|
||||
// @flow
|
||||
import React from "react";
|
||||
import { translate } from "react-i18next";
|
||||
import type { User } from "@scm-manager/ui-types";
|
||||
import { DeleteButton, confirmAlert } from "@scm-manager/ui-components";
|
||||
|
||||
type Props = {
|
||||
user: User,
|
||||
confirmDialog?: boolean,
|
||||
t: string => string,
|
||||
deleteUser: (user: User) => void
|
||||
};
|
||||
|
||||
class DeleteUser extends React.Component<Props> {
|
||||
static defaultProps = {
|
||||
confirmDialog: true
|
||||
};
|
||||
|
||||
deleteUser = () => {
|
||||
this.props.deleteUser(this.props.user);
|
||||
};
|
||||
|
||||
confirmDelete = () => {
|
||||
const { t } = this.props;
|
||||
confirmAlert({
|
||||
title: t("delete-user-button.confirm-alert.title"),
|
||||
message: t("delete-user-button.confirm-alert.message"),
|
||||
buttons: [
|
||||
{
|
||||
label: t("delete-user-button.confirm-alert.submit"),
|
||||
onClick: () => this.deleteUser()
|
||||
},
|
||||
{
|
||||
label: t("delete-user-button.confirm-alert.cancel"),
|
||||
onClick: () => null
|
||||
}
|
||||
]
|
||||
});
|
||||
};
|
||||
|
||||
isDeletable = () => {
|
||||
return this.props.user._links.delete;
|
||||
};
|
||||
|
||||
render() {
|
||||
const { confirmDialog, t } = this.props;
|
||||
const action = confirmDialog ? this.confirmDelete : this.deleteUser;
|
||||
|
||||
if (!this.isDeletable()) {
|
||||
return null;
|
||||
}
|
||||
return <DeleteButton label={t("user-form.deleteUser")} action={action} />;
|
||||
}
|
||||
}
|
||||
|
||||
export default translate("users")(DeleteUser);
|
||||
Reference in New Issue
Block a user