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";
|
2019-01-23 10:08:15 +01:00
|
|
|
import { Subtitle, DeleteButton, confirmAlert } from "@scm-manager/ui-components";
|
2018-09-05 14:32:49 +02:00
|
|
|
import type { User } from "@scm-manager/ui-types";
|
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,
|
2019-01-18 15:26:55 +01:00
|
|
|
|
|
|
|
|
// dispatcher functions
|
2019-01-23 11:55:57 +01:00
|
|
|
deleteUser: (user: User) => void,
|
2019-01-18 15:26:55 +01:00
|
|
|
|
|
|
|
|
// context objects
|
2019-01-23 11:55:57 +01:00
|
|
|
t: string => string
|
2018-07-10 15:18:37 +02:00
|
|
|
};
|
|
|
|
|
|
2019-01-18 13:42:11 +01:00
|
|
|
class DeleteUser extends React.Component<Props> {
|
2019-01-23 10:08:15 +01:00
|
|
|
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
|
|
|
};
|
|
|
|
|
|
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({
|
2019-01-23 11:14:30 +01:00
|
|
|
title: t("delete.confirm-alert.title"),
|
|
|
|
|
message: t("delete.confirm-alert.message"),
|
2018-07-17 15:08:58 +02:00
|
|
|
buttons: [
|
|
|
|
|
{
|
2019-01-23 11:14:30 +01:00
|
|
|
label: t("delete.confirm-alert.submit"),
|
2018-07-12 16:35:19 +02:00
|
|
|
onClick: () => this.deleteUser()
|
|
|
|
|
},
|
|
|
|
|
{
|
2019-01-23 11:14:30 +01:00
|
|
|
label: t("delete.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
|
|
|
}
|
2019-01-18 17:28:38 +01:00
|
|
|
return (
|
|
|
|
|
<>
|
2019-01-23 11:14:30 +01:00
|
|
|
<Subtitle subtitle={t("delete.subtitle")} />
|
2019-01-18 17:28:38 +01:00
|
|
|
<div className="columns">
|
|
|
|
|
<div className="column">
|
|
|
|
|
<DeleteButton
|
2019-01-23 11:14:30 +01:00
|
|
|
label={t("delete.button")}
|
2019-01-18 17:28:38 +01:00
|
|
|
action={action}
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</>
|
|
|
|
|
);
|
2018-07-10 16:37:27 +02:00
|
|
|
}
|
|
|
|
|
}
|
2018-07-10 15:18:37 +02:00
|
|
|
|
2019-01-18 13:42:11 +01:00
|
|
|
export default translate("users")(DeleteUser);
|