mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-14 09:25:43 +01:00
59 lines
1.2 KiB
JavaScript
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;
|