Files
SCM-Manager/scm-ui/src/users/components/buttons/DeleteUserButton.js

58 lines
1.4 KiB
JavaScript
Raw Normal View History

2018-07-10 15:18:37 +02:00
// @flow
import React from "react";
2018-07-24 16:04:55 +02:00
import { translate } from "react-i18next";
2018-07-25 15:04:19 +02:00
import type { User } from "../../types/User";
import { confirmAlert } from "../../../components/modals/ConfirmAlert";
import { NavAction } from "../../../components/navigation";
2018-07-10 15:18:37 +02:00
type Props = {
2018-07-25 13:21:49 +02:00
user: User,
2018-07-17 15:08:58 +02:00
confirmDialog?: boolean,
2018-07-24 16:04:55 +02:00
t: string => string,
deleteUser: (user: User) => void
2018-07-10 15:18:37 +02:00
};
2018-07-17 15:08:58 +02:00
class DeleteUserButton extends React.Component<Props> {
static defaultProps = {
confirmDialog: true
};
2018-07-10 15:18:37 +02:00
deleteUser = () => {
2018-07-25 13:21:49 +02:00
this.props.deleteUser(this.props.user);
2018-07-10 15:18:37 +02:00
};
confirmDelete = () => {
2018-07-24 16:04:55 +02:00
const { t } = this.props;
confirmAlert({
2018-07-24 16:04:55 +02:00
title: t("delete-user-button.confirm-alert.title"),
message: t("delete-user-button.confirm-alert.message"),
2018-07-17 15:08:58 +02:00
buttons: [
{
2018-07-24 16:04:55 +02:00
label: t("delete-user-button.confirm-alert.submit"),
onClick: () => this.deleteUser()
},
{
2018-07-24 16:04:55 +02:00
label: t("delete-user-button.confirm-alert.cancel"),
onClick: () => null
}
]
2018-07-17 15:08:58 +02:00
});
};
2018-07-10 16:37:27 +02:00
isDeletable = () => {
2018-07-25 13:21:49 +02:00
return this.props.user._links.delete;
2018-07-10 15:18:37 +02:00
};
2018-07-10 16:37:27 +02:00
render() {
2018-07-25 13:21:49 +02:00
const { confirmDialog, t } = this.props;
2018-07-17 15:08:58 +02:00
const action = confirmDialog ? this.confirmDelete : this.deleteUser;
if (!this.isDeletable()) {
2018-07-18 09:48:59 +02:00
return null;
}
2018-07-25 13:21:49 +02:00
return <NavAction label={t("delete-user-button.label")} action={action} />;
2018-07-10 16:37:27 +02:00
}
}
2018-07-10 15:18:37 +02:00
2018-07-24 16:04:55 +02:00
export default translate("users")(DeleteUserButton);