add confirm dialog after click on button

This commit is contained in:
Maren Süwer
2018-07-12 16:35:19 +02:00
parent 84ae2248b2
commit 8d34bc398f
6 changed files with 204 additions and 7 deletions

View File

@@ -1,28 +1,56 @@
// @flow
import React from "react";
import type { User } from "../types/User";
import type {
User
} from "../types/User";
import {
confirmAlert
} from '../../components/ConfirmAlert';
type Props = {
user: User,
deleteUser: (link: string) => void,
};
class DeleteUserButton extends React.Component<Props> {
class DeleteUserButton extends React.Component < Props > {
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() {
return (
<button type="button" onClick={(e) => { if (window.confirm('Are you sure you wish to delete this item?')) this.deleteUser() } }>
Delete User
</button>
if (!this.isDeletable()) {
return;
}
return ( <
button type = "button"
onClick = {
(e) => {
this.confirmDelete()
}
} >
Delete User <
/button>
);
}
}