| 1 |
import cx from 'classnames'; |
| 2 |
import {__} from '@wordpress/i18n' |
| 3 |
import ModalDialog from '@givewp/components/AdminUI/ModalDialog'; |
| 4 |
import {ErrorIcon, WarningIcon} from './Icons'; |
| 5 |
import styles from './AdminDetailsPage.module.scss' |
| 6 |
import { Spinner } from '@wordpress/components'; |
| 7 |
import ArcSpinner from '@givewp/src/Admin/components/Spinner/ArcSpinner'; |
| 8 |
|
| 9 |
export type ConfirmationDialogProps = { |
| 10 |
isOpen: boolean; |
| 11 |
handleClose: () => void; |
| 12 |
handleConfirm: () => void; |
| 13 |
title: string; |
| 14 |
icon?: React.ReactElement; |
| 15 |
variant?: 'error' | 'regular' | 'syncing'; |
| 16 |
className?: string; |
| 17 |
actionLabel: string; |
| 18 |
showCancelButton?: boolean; |
| 19 |
children: React.ReactNode; |
| 20 |
isConfirming?: boolean; |
| 21 |
spinner?: 'regular' | 'arc' | 'none'; |
| 22 |
footer?: React.ReactNode; |
| 23 |
} |
| 24 |
|
| 25 |
/** |
| 26 |
* @since 4.8.0 Add showCancelButton prop |
| 27 |
* @since 4.4.0 |
| 28 |
*/ |
| 29 |
export default function ConfirmationDialog({ |
| 30 |
isOpen, |
| 31 |
title, |
| 32 |
icon, |
| 33 |
variant = 'error', |
| 34 |
handleClose, |
| 35 |
handleConfirm, |
| 36 |
className, |
| 37 |
actionLabel, |
| 38 |
showCancelButton = true, |
| 39 |
children, |
| 40 |
isConfirming = false, |
| 41 |
spinner ='none', |
| 42 |
footer, |
| 43 |
}: ConfirmationDialogProps) { |
| 44 |
return ( |
| 45 |
<ModalDialog |
| 46 |
icon={icon || (variant === 'error' && <ErrorIcon />)} |
| 47 |
isOpen={isOpen} |
| 48 |
showHeader={true} |
| 49 |
handleClose={handleClose} |
| 50 |
title={title} |
| 51 |
wrapperClassName={className} |
| 52 |
> |
| 53 |
<> |
| 54 |
<div className={styles.confirmationDialogContent}> |
| 55 |
{children} |
| 56 |
</div> |
| 57 |
<div className={styles.confirmationDialogButtons}> |
| 58 |
{showCancelButton && ( |
| 59 |
<button |
| 60 |
className={styles.cancelButton} |
| 61 |
onClick={handleClose} |
| 62 |
> |
| 63 |
{__('Cancel', 'give')} |
| 64 |
</button> |
| 65 |
)} |
| 66 |
<button |
| 67 |
className={cx(styles.confirmButton, styles[`confirmButton--${variant}`])} |
| 68 |
onClick={handleConfirm} |
| 69 |
disabled={isConfirming} |
| 70 |
> |
| 71 |
{actionLabel} |
| 72 |
{isConfirming ? (spinner === 'arc' ? <ArcSpinner /> : <Spinner />) : null} |
| 73 |
</button> |
| 74 |
</div> |
| 75 |
<div className={styles.confirmationDialogFooter}> |
| 76 |
{footer} |
| 77 |
</div> |
| 78 |
</> |
| 79 |
</ModalDialog> |
| 80 |
); |
| 81 |
} |
| 82 |
|