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-17 15:08:58 +02:00
|
|
|
import type { User } from "../types/User";
|
2018-07-25 14:29:43 +02:00
|
|
|
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,
|
2018-07-18 09:35:16 +02:00
|
|
|
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-12 14:23:09 +02:00
|
|
|
|
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
|
|
|
};
|
|
|
|
|
|
2018-07-18 09:35:16 +02:00
|
|
|
confirmDelete = () => {
|
2018-07-24 16:04:55 +02:00
|
|
|
const { t } = this.props;
|
2018-07-18 09:35:16 +02:00
|
|
|
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"),
|
2018-07-12 16:35:19 +02:00
|
|
|
onClick: () => this.deleteUser()
|
|
|
|
|
},
|
|
|
|
|
{
|
2018-07-24 16:04:55 +02:00
|
|
|
label: t("delete-user-button.confirm-alert.cancel"),
|
2018-07-12 16:35:19 +02:00
|
|
|
onClick: () => null
|
|
|
|
|
}
|
|
|
|
|
]
|
2018-07-17 15:08:58 +02:00
|
|
|
});
|
|
|
|
|
};
|
2018-07-12 16:35:19 +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;
|
|
|
|
|
|
2018-07-12 16:35:19 +02:00
|
|
|
if (!this.isDeletable()) {
|
2018-07-18 09:48:59 +02:00
|
|
|
return null;
|
2018-07-12 16:35:19 +02:00
|
|
|
}
|
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);
|