PluginProbe ʕ •ᴥ•ʔ
Presto Player / 4.3.3
Presto Player v4.3.3
4.4.0 4.3.3 4.3.2 4.3.1 4.3.0 4.2.4 4.2.3 4.2.2 4.2.0 4.2.1 trunk 1.10.0 1.10.1 1.10.2 1.11.0 1.12.0 1.13.0 1.14.0 1.14.1 1.5.10 1.5.11 1.5.12 1.5.13 1.5.14 1.5.15 1.5.5 1.5.6 1.5.7 1.5.8 1.5.9 1.6.0 1.6.1 1.6.10 1.6.11 1.6.12 1.6.13 1.6.2 1.6.3 1.6.4 1.6.5 1.6.6 1.6.7 1.6.8 1.6.9 1.7.0 1.7.1 1.7.2 1.8.0 1.8.1 1.8.2 1.8.3 1.8.4 1.8.5 1.8.6 1.9.0 1.9.1 1.9.10 1.9.11 1.9.12 1.9.13 1.9.14 1.9.2 1.9.3 1.9.4 1.9.5 1.9.6 1.9.7 1.9.8 1.9.9 2.0.0 2.0.1 2.0.10 2.0.11 2.0.12 2.0.13 2.0.14 2.0.15 2.0.16 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 2.0.7 2.0.8 2.0.9 2.1.0 2.2.0 2.2.1 2.2.2 2.2.3 2.2.3-beta1 2.3.0 2.3.1 2.3.2 2.3.3 3.0.0 3.0.0-beta1 3.0.1 3.0.2 3.0.3 3.0.4 3.0.5 3.0.6 3.0.7 3.0.8 3.1.0 3.1.1 3.1.2 3.1.3 4.0.0 4.0.1 4.0.2 4.0.3 4.0.4 4.0.5 4.0.6 4.0.7 4.0.8 4.1.0 4.1.1 4.1.2 4.1.3 4.1.4
presto-player / src / admin / dashboard / components / Popup / ConfirmPopup.js
presto-player / src / admin / dashboard / components / Popup Last commit date
ConfirmPopup.js 3 months ago EmailFormPopup.js 3 months ago EmailFormPopupUtils.js 3 months ago
ConfirmPopup.js
117 lines
1 import { useEffect, useRef, useState } from "react";
2 import { __ } from "@wordpress/i18n";
3 import { CircleX } from "lucide-react";
4
5 import { Dialog, Button, Badge } from "@bsf/force-ui";
6
7 const ConfirmPopup = ({
8 openConfirmPopup: openPopup,
9 setOpenConfirmPopup: setOpenPopup,
10 title = __("Popup Title", "presto-player"),
11 description = "",
12 confirmText = __("Confirm", "presto-player"),
13 cancelText = __("Cancel", "presto-player"),
14 confirmCallback = null,
15 cancelCallback = null,
16 ErrorMessage = "",
17 postsDeletionMessageList = false,
18 destructive = false,
19 }) => {
20 const cancelButtonRef = useRef(null);
21 const [loading, setLoading] = useState(false);
22 const onCancelClick = () => {
23 if (cancelCallback) {
24 cancelCallback();
25 return;
26 }
27 setOpenPopup(false);
28 };
29
30 const onConfirmClick = async () => {
31 if (!confirmCallback) {
32 return;
33 }
34 setLoading(true);
35 try {
36 // Awaits the callback's promise (if any). Synchronous callbacks
37 // resolve immediately. After success the popup self-closes; on
38 // error the popup stays open so the caller can show ErrorMessage.
39 await confirmCallback();
40 setOpenPopup(false);
41 } finally {
42 setLoading(false);
43 }
44 };
45
46 useEffect(() => {
47 if (ErrorMessage) {
48 setLoading(false);
49 }
50 }, [ErrorMessage]);
51
52 return (
53 <Dialog
54 design="simple"
55 exitOnClickOutside
56 exitOnEsc
57 scrollLock
58 open={openPopup}
59 setOpen={setOpenPopup}
60 >
61 <Dialog.Backdrop />
62 <Dialog.Panel>
63 <Dialog.Header>
64 {ErrorMessage && (
65 <Badge
66 icon={<CircleX />}
67 label={ErrorMessage}
68 size="md"
69 type="rounded"
70 variant="red"
71 className="py-6 px-4 justify-start"
72 />
73 )}
74 <Dialog.Title>{title}</Dialog.Title>
75 </Dialog.Header>
76
77 {(description || postsDeletionMessageList) && (
78 // py-3 balances the vertical rhythm: Dialog.Header has pb-1 but
79 // Dialog.Body has no default vertical padding, so without this the
80 // description sits visually closer to the title than to the footer.
81 <Dialog.Body className="py-3">
82 <Dialog.Description>
83 {description}
84 {postsDeletionMessageList && (
85 <ul className="list-disc pl-5">
86 <li className="text-sm">
87 {__(
88 "Posts content under this space will be deleted permanently.",
89 "presto-player"
90 )}
91 </li>
92 </ul>
93 )}
94 </Dialog.Description>
95 </Dialog.Body>
96 )}
97
98 <Dialog.Footer>
99 <Button variant="ghost" onClick={onCancelClick} ref={cancelButtonRef}>
100 {cancelText}
101 </Button>
102 <Button
103 onClick={onConfirmClick}
104 disabled={loading}
105 loading={loading}
106 destructive={destructive}
107 >
108 {confirmText}
109 </Button>
110 </Dialog.Footer>
111 </Dialog.Panel>
112 </Dialog>
113 );
114 };
115
116 export default ConfirmPopup;
117