import { Box, Button, ButtonGroup, Icon, Modal } from '@rocket.chat/fuselage'; import React, { FC, ComponentProps, ReactElement, ReactNode } from 'react'; import { useTranslation } from '../contexts/TranslationContext'; import { withDoNotAskAgain, RequiredModalProps } from './withDoNotAskAgain'; type VariantType = 'danger' | 'warning' | 'info' | 'success'; type GenericModalProps = RequiredModalProps & { variant?: VariantType; children?: ReactNode; cancelText?: string; confirmText?: string; title?: string | ReactElement; icon?: ComponentProps['name'] | ReactElement | null; confirmDisabled?: boolean; onCancel?: () => void; onClose: () => void; onConfirm: () => void; }; const iconMap: Record['name']> = { danger: 'modal-warning', warning: 'modal-warning', info: 'info', success: 'check', }; const getButtonProps = (variant: VariantType): ComponentProps => { switch (variant) { case 'danger': return { primary: true, danger: true }; case 'warning': return { primary: true }; default: return {}; } }; const renderIcon = (icon: GenericModalProps['icon'], variant: VariantType): ReactNode => { if (icon === null) { return null; } if (icon === undefined) { return ; } if (typeof icon === 'string') { return ; } return icon; }; const GenericModal: FC = ({ variant = 'info', children, cancelText, confirmText, title, icon, onCancel, onClose = onCancel, onConfirm, dontAskAgain, confirmDisabled, ...props }) => { const t = useTranslation(); return ( {renderIcon(icon, variant)} {title ?? t('Are_you_sure')} {children} {dontAskAgain} {onCancel && ( )} ); }; export const GenericModalDoNotAskAgain = withDoNotAskAgain(GenericModal); export default GenericModal;