Files
SCM-Manager/scm-ui/src/users/containers/DeleteUserButton.js
Maren Süwer d95e272b6b refactoring
2018-07-17 15:08:58 +02:00

59 lines
1.2 KiB
JavaScript

// @flow
import React from "react";
import type { User } from "../types/User";
import { confirmAlert } from '../../components/ConfirmAlert';
type Props = {
user: User,
confirmDialog?: boolean,
deleteUser: (link: string) => void,
};
class DeleteUserButton extends React.Component<Props> {
static defaultProps = {
confirmDialog: true
};
deleteUser = () => {
this.props.deleteUser(this.props.user._links.delete.href);
};
confirmDelete = () =>{
confirmAlert({
title: 'Delete user',
message: 'Do you really want to delete the user?',
buttons: [
{
label: 'Yes',
onClick: () => this.deleteUser()
},
{
label: 'No',
onClick: () => null
}
]
});
};
isDeletable = () => {
return this.props.user._links.delete;
};
render() {
const { confirmDialog } = this.props;
const action = confirmDialog ? this.confirmDelete : this.deleteUser;
if (!this.isDeletable()) {
return;
}
return (
<button type="button" onClick={(e) => { action() } }>
Delete User
</button>
);
}
}
export default DeleteUserButton;