Files
SCM-Manager/scm-ui/ui-components/src/modals/ConfirmAlert.js

70 lines
1.4 KiB
JavaScript
Raw Normal View History

// @flow
import * as React from "react";
2019-02-01 08:47:38 +01:00
import ReactDOM from "react-dom";
2019-02-01 10:02:19 +01:00
import Modal from "./Modal";
2019-02-01 11:09:07 +01:00
type Button = {
label: string,
onClick: () => void | null
};
type Props = {
title: string,
message: string,
2019-02-01 11:09:07 +01:00
buttons: Button[]
};
class ConfirmAlert extends React.Component<Props> {
2019-02-01 11:09:07 +01:00
handleClickButton = (button: Button) => {
if (button.onClick) {
button.onClick();
}
this.close();
};
close = () => {
2019-02-01 08:47:38 +01:00
ReactDOM.unmountComponentAtNode(document.getElementById("modalRoot"));
};
render() {
const { title, message, buttons } = this.props;
2019-02-07 13:53:15 +01:00
const body = <>{message}</>;
const footer = (
<div className="field is-grouped">
{buttons.map((button, i) => (
<p className="control">
<a
className="button is-info"
key={i}
onClick={() => this.handleClickButton(button)}
2019-02-01 10:02:19 +01:00
>
{button.label}
</a>
2019-02-07 13:53:15 +01:00
</p>
))}
</div>
2019-02-01 10:02:19 +01:00
);
2019-01-31 10:50:15 +01:00
2019-02-01 10:02:19 +01:00
return (
2019-02-07 13:53:15 +01:00
<Modal
title={title}
closeFunction={() => this.close()}
body={body}
active={true}
footer={footer}
/>
);
}
}
export function confirmAlert(properties: Props) {
2019-02-01 08:47:38 +01:00
const root = document.getElementById("modalRoot");
2019-02-07 13:53:15 +01:00
if (root) {
ReactDOM.render(<ConfirmAlert {...properties} />, root);
2019-02-01 08:47:38 +01:00
}
}
export default ConfirmAlert;