import type { Icon } from '@rocket.chat/fuselage'; import { Button, Modal } from '@rocket.chat/fuselage'; import { useTranslation } from '@rocket.chat/ui-contexts'; import type { FC, ComponentProps, ReactElement, ReactNode } from 'react'; import React from 'react'; import type { RequiredModalProps } from './withDoNotAskAgain'; import { withDoNotAskAgain } from './withDoNotAskAgain'; type VariantType = 'danger' | 'warning' | 'info' | 'success'; type GenericModalProps = RequiredModalProps & { variant?: VariantType; children?: ReactNode; cancelText?: ReactNode; confirmText?: ReactNode; title?: string | ReactElement; icon?: ComponentProps['name'] | ReactElement | null; confirmDisabled?: boolean; tagline?: ReactNode; onCancel?: () => Promise | void; onClose?: () => Promise | void; } & Omit, 'title'>; const iconMap: Record['name']> = { danger: 'modal-warning', warning: 'modal-warning', info: 'info', success: 'check', }; const getButtonProps = (variant: VariantType): ComponentProps => { switch (variant) { case 'danger': return { 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, tagline, wrapperFunction, ...props }) => { const t = useTranslation(); return ( {renderIcon(icon, variant)} {tagline && {tagline}} {title ?? t('Are_you_sure')} {children} {dontAskAgain} {onCancel && ( )} {wrapperFunction && ( )} {!wrapperFunction && ( )} ); }; export const GenericModalDoNotAskAgain = withDoNotAskAgain(GenericModal); export default GenericModal;