Open fershibli opened 4 years ago
I need onClose to run when the user clicks outside the sweet alert or on confirm, but not on cancel. The cancel button makes an async call, which calls another sweet alert. I have tried the following setups: First this:
MySwal.fire({ type: 'success', showCancelButton: userId === 'new', onClose: () => { if (userId === 'new') { history.push(`/users`); } }, }) .then(myswallResult => { if (myswallResult.dismiss === MySwal.DismissReason.cancel) { return sendWelcomeEmail(result.data.id); } }) .then(emailResult => { MySwal.fire({ type: 'success', onClose: () => { if (userId === 'new') { history.push(`/users`); } }, }); }) .catch(err => { MySwal.fire({ type: 'error', onClose: () => { if (userId === 'new') { history.push(`/users`); } }, }); });
Then this:
MySwal.fire({ type: 'success', showCancelButton: userId === 'new', onClose: () => { if (userId === 'new') { history.push(`/users`); } }, }) .then(myswallResult => { if (myswallResult.dismiss === MySwal.DismissReason.cancel) { sendWelcomeEmail(result.data.id) .then(emailResult => { MySwal.fire({ type: 'success', onClose: () => { if (userId === 'new') { history.push(`/users`); } }, }); }) .catch(err => { MySwal.fire({ type: 'error', onClose: () => { if (userId === 'new') { history.push(`/users`); } }, }); }); } });
But instead of waiting the second sweet alert, it pushes to '/users' before.
I need onClose to run when the user clicks outside the sweet alert or on confirm, but not on cancel. The cancel button makes an async call, which calls another sweet alert. I have tried the following setups: First this:
Then this:
But instead of waiting the second sweet alert, it pushes to '/users' before.