| 1 |
import { Dialog, Transition } from '@headlessui/react'; |
| 2 |
import { ExclamationTriangleIcon } from '@heroicons/react/24/outline'; |
| 3 |
import { __ } from '@wordpress/i18n'; |
| 4 |
import { Fragment } from 'react'; |
| 5 |
|
| 6 |
const AlertPopup = ({ |
| 7 |
open, |
| 8 |
setOpen, |
| 9 |
onRemove, |
| 10 |
removeBtnTestId = '', |
| 11 |
title = __('Remove Conditions', 'disco'), |
| 12 |
description = __( |
| 13 |
'This action will remove the conditions from the campaign. Are you sure you want to proceed?', |
| 14 |
'disco' |
| 15 |
), |
| 16 |
confirmLabel = __('Remove', 'disco'), |
| 17 |
}) => ( |
| 18 |
<Transition.Root show={open} as={Fragment}> |
| 19 |
<Dialog |
| 20 |
as="div" |
| 21 |
className="disco:relative disco:z-50" |
| 22 |
onClose={setOpen} |
| 23 |
> |
| 24 |
<Transition.Child |
| 25 |
as={Fragment} |
| 26 |
enter="disco:ease-out disco:duration-300" |
| 27 |
enterFrom="disco:opacity-0" |
| 28 |
enterTo="disco:opacity-100" |
| 29 |
leave="disco:ease-in disco:duration-200" |
| 30 |
leaveFrom="disco:opacity-100" |
| 31 |
leaveTo="disco:opacity-0" |
| 32 |
> |
| 33 |
<div className="disco:fixed disco:inset-0 disco:bg-gray-500/50 disco:transition-opacity" /> |
| 34 |
</Transition.Child> |
| 35 |
<div className="disco:fixed disco:inset-0 disco:z-10 disco:w-screen disco:overflow-y-auto"> |
| 36 |
<div className="disco:flex disco:min-h-full disco:items-end disco:justify-center disco:p-4 disco:text-center disco:sm:items-center disco:sm:p-0"> |
| 37 |
<Transition.Child |
| 38 |
as={Fragment} |
| 39 |
enter="disco:ease-out disco:duration-300" |
| 40 |
enterFrom="disco:opacity-0 disco:translate-y-4 disco:sm:translate-y-0 disco:sm:scale-95" |
| 41 |
enterTo="disco:opacity-100 disco:translate-y-0 disco:sm:scale-100" |
| 42 |
leave="disco:ease-in disco:duration-200" |
| 43 |
leaveFrom="disco:opacity-100 disco:translate-y-0 disco:sm:scale-100" |
| 44 |
leaveTo="disco:opacity-0 disco:translate-y-4 disco:sm:translate-y-0 disco:sm:scale-95" |
| 45 |
> |
| 46 |
<Dialog.Panel className="disco:relative disco:transform disco:overflow-hidden disco:rounded-lg disco:bg-white disco:px-4 disco:pb-4 disco:pt-5 disco:text-left disco:shadow disco:transition-all disco:sm:my-8 disco:sm:w-full disco:sm:max-w-lg disco:sm:p-6"> |
| 47 |
<div className="disco:sm:flex disco:sm:items-start"> |
| 48 |
<div className="disco:mx-auto disco:flex disco:h-12 disco:w-12 disco:shrink-0 disco:items-center disco:justify-center disco:rounded-full disco:bg-red-100 disco:sm:mx-0 disco:sm:h-10 disco:sm:w-10"> |
| 49 |
<ExclamationTriangleIcon |
| 50 |
className="disco:h-6 disco:w-6 disco:text-red-600" |
| 51 |
aria-hidden="true" |
| 52 |
/> |
| 53 |
</div> |
| 54 |
<div className="disco:mt-3 disco:text-center disco:sm:ml-4 disco:sm:mt-0 disco:sm:text-left"> |
| 55 |
<Dialog.Title |
| 56 |
as="h3" |
| 57 |
className="disco:text-base disco:font-semibold disco:leading-6 disco:text-gray-900" |
| 58 |
> |
| 59 |
{title} |
| 60 |
</Dialog.Title> |
| 61 |
<div className="disco:mt-2"> |
| 62 |
<p className="disco:text-sm disco:text-gray-500"> |
| 63 |
{description} |
| 64 |
</p> |
| 65 |
</div> |
| 66 |
</div> |
| 67 |
</div> |
| 68 |
<div className="disco:mt-5 disco:sm:mt-4 disco:sm:flex disco:sm:flex-row-reverse"> |
| 69 |
<button |
| 70 |
data-testid={removeBtnTestId} |
| 71 |
type="button" |
| 72 |
className="disco:inline-flex disco:w-full disco:justify-center disco:rounded-md disco:bg-red-600 disco:px-3 disco:py-2 disco:text-sm disco:font-semibold disco:text-white disco:shadow-sm disco:hover:bg-red-500 disco:sm:ml-3 disco:sm:w-auto" |
| 73 |
onClick={() => { |
| 74 |
onRemove && onRemove(); |
| 75 |
setOpen(false); |
| 76 |
}} |
| 77 |
> |
| 78 |
{confirmLabel} |
| 79 |
</button> |
| 80 |
<button |
| 81 |
type="button" |
| 82 |
className="disco:mt-3 disco:inline-flex disco:w-full disco:justify-center disco:rounded-md disco:bg-white disco:px-3 disco:py-2 disco:text-sm disco:font-semibold disco:text-gray-900 disco:shadow-sm disco:ring-1 disco:ring-inset disco:ring-gray-300 disco:hover:bg-gray-50 disco:sm:mt-0 disco:sm:w-auto" |
| 83 |
onClick={() => setOpen(false)} |
| 84 |
> |
| 85 |
{__('Cancel', 'disco')} |
| 86 |
</button> |
| 87 |
</div> |
| 88 |
</Dialog.Panel> |
| 89 |
</Transition.Child> |
| 90 |
</div> |
| 91 |
</div> |
| 92 |
</Dialog> |
| 93 |
</Transition.Root> |
| 94 |
); |
| 95 |
|
| 96 |
export default AlertPopup; |
| 97 |
|