import PropTypes from "prop-types"; import React from "react"; class Modal extends React.Component { static propTypes = { title: PropTypes.string.isRequired, show: PropTypes.bool.isRequired, onSubmit: PropTypes.func.isRequired, onCancel: PropTypes.func.isRequired, }; static idCounter = 0; constructor() { super(); this.id = "modal-" + Modal.idCounter; } componentDidMount() { this.openOrCloseModal(); } componentDidUpdate() { this.openOrCloseModal(); } onSubmit() { this.props.onSubmit(); this.closeModal(); } onCancel() { this.props.onCancel(); this.closeModal(); } openModal() { window["$"]("#" + this.id).modal("show"); } closeModal() { window["$"]("#" + this.id).modal("hide"); } openOrCloseModal() { if (this.props.show) { this.openModal(); } else { this.closeModal(); } } render() { return (