import { FC, ReactNode } from 'react' import { Modal, Button, Input, Alert, Form } from 'ui' interface Props { loading: boolean visible: boolean title: string size?: 'tiny' | 'small' | 'medium' | 'large' | 'xlarge' | 'xxlarge' confirmLabel: string confirmPlaceholder: string confirmString: string alert?: string text?: string | ReactNode children?: ReactNode onConfirm: () => void onCancel: () => void } const TextConfirmModal: FC = ({ title, size = 'small', onConfirm, visible, onCancel, loading, confirmLabel, confirmPlaceholder, confirmString, alert, text, children, }) => { // [Joshen] Have to keep the loading prop here as this component itself doesn't // directly trigger any potential async job that follows onConfirm. It only triggers // the onConfirm callback function, and hence if anything fails in the callback, // have to depend on loading prop to unfreeze the UI state const validate = (values: any) => { const errors: any = {} if (values.confirmValue.length === 0) { errors.confirmValue = 'Enter the required value.' } else if (values.confirmValue !== confirmString) { errors.confirmValue = 'Value entered does not match.' } return errors } return (
{() => (
{children && ( <> {children} )} {alert && ( )} {text !== undefined && (

{text}

)} Type {confirmString} to confirm. } placeholder={confirmPlaceholder} />
)}
) } export default TextConfirmModal