| 47 | onFail(); |
| 48 | }; |
| 49 | const handleSuccess = () => { |
| 50 | if (isPending) { |
| 51 | return; |
| 52 | } |
| 53 | |
| 54 | if (!onConfirm) { |
| 55 | onSuccess(); |
| 56 | return; |
| 57 | } |
| 58 | |
| 59 | const settle = (callback: () => void) => { |
| 60 | if (confirmingPrompt.current !== prompt) { |
| 61 | return; |
| 62 | } |
| 63 | |
| 64 | confirmingPrompt.current = null; |
| 65 | setIsConfirming(false); |
| 66 | callback(); |
| 67 | }; |
| 68 | |
| 69 | confirmingPrompt.current = prompt; |
| 70 | setIsConfirming(true); |
| 71 | Promise.resolve(onConfirm()) |
| 72 | .then(() => settle(onSuccess)) |
| 73 | .catch(() => settle(onError)); |
| 74 | }; |
| 75 | |
| 76 | const cancelButtonProps = cancelButton ?? {}; |
| 77 | const cancelActionButtonProps = { |