refactoring

This commit is contained in:
Maren Süwer
2018-07-17 15:08:58 +02:00
parent ad1aaccfac
commit d95e272b6b

View File

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