import classnames from 'classnames'; import React from 'react'; import { Button } from './Button'; import { useLogEvent } from './logging'; import type { IModalComponentProps } from '../../presentation'; import { FormikFormField, ModalBody, ModalFooter, ModalHeader, SpinFormik, TextAreaInput, ValidationMessage, } from '../../presentation'; export interface IArtifactActionModalProps extends IModalComponentProps { title: string; actionName: string; withComment?: boolean; logCategory?: string; onAction: (comment?: string) => Promise | PromiseLike; onSuccess?: () => void; error?: string; className?: string; } export const ActionModal: React.FC = ({ title, dismissModal, closeModal, onAction, onSuccess, actionName, withComment = true, logCategory, className, children, }) => { const logEvent = useLogEvent(logCategory || 'ActionModal', actionName); return ( <> {title} initialValues={{}} onSubmit={async ({ comment }, { setSubmitting, setStatus }) => { if (withComment && !comment) return; logEvent(); try { await onAction(comment); onSuccess?.(); closeModal?.(); } catch (error) { setStatus({ error }); } finally { setSubmitting(false); } }} render={({ status, isValid, isSubmitting, submitForm }) => { return ( <>
{children} {withComment && ( ( )} /> )} {status?.error && (
Something went wrong: {status.error.message && {status.error.message}} } />
)}
} /> ); }} /> ); };