import type { FieldProps } from 'formik'; import { Field, Form, Formik } from 'formik'; import React from 'react'; import { Modal } from 'react-bootstrap'; import { ModalClose, SubmitButton } from '../modal'; import { Markdown, ReactModal } from '../presentation'; export interface ICancelModalProps { body?: string; buttonText: string; cancelButtonText?: string; header: string; submitMethod: (reason: string, force?: boolean) => PromiseLike; closeModal?(result?: any): void; // provided by ReactModal dismissModal?(rejection?: any): void; // provided by ReactModal } export interface ICancelModalState { isSubmitting: boolean; error: boolean; errorMessage?: string; } export interface ICancelModalValues { reason?: string; } export class CancelModal extends React.Component { public static defaultProps: Partial = { cancelButtonText: 'Cancel', }; public state: ICancelModalState = { isSubmitting: false, error: false }; public static confirm(props: ICancelModalProps): Promise { return ReactModal.show(CancelModal, props); } private close = (args?: any): void => { this.props.dismissModal.apply(null, args); }; private showError = (exception: string): void => { this.setState({ error: true, errorMessage: exception, isSubmitting: false, }); }; private submitConfirmation = (values: ICancelModalValues): void => { this.setState({ isSubmitting: true }); this.props.submitMethod(values.reason).then(this.close, this.showError); }; public render() { const { header, body, buttonText, cancelButtonText } = this.props; const { isSubmitting } = this.state; const error = this.state.error ? (

An exception occurred:

{this.state.errorMessage || 'No details provided.'}

) : null; return ( { const wrappedBody = body ? : null; return (
{header} {wrappedBody} {error}
Reason
) => (