Prevent leaving unsaved automation

[MAILPOET-4776]
This commit is contained in:
Brezo Cordero
2022-11-08 16:40:51 +03:00
committed by Jan Jakeš
parent 9a72e361b1
commit d34a265ac2
2 changed files with 73 additions and 0 deletions

View File

@@ -72,6 +72,25 @@ function updatingActiveWorkflowNotPossible() {
);
}
function onUnload(event) {
if (!globalSelect(storeName).getWorkflowSaved()) {
// eslint-disable-next-line no-param-reassign
event.returnValue = __(
'There are unsaved changes that will be lost. Do you want to continue?',
'mailpoet',
);
return event.returnValue;
}
return '';
}
function useConfirmUnsaved() {
useEffect(() => {
window.addEventListener('beforeunload', onUnload);
return () => window.removeEventListener('beforeunload', onUnload);
}, []);
}
function Editor(): JSX.Element {
const {
isFullscreenActive,
@@ -93,6 +112,8 @@ function Editor(): JSX.Element {
);
const [isBooting, setIsBooting] = useState(true);
useConfirmUnsaved();
useEffect(() => {
if (!isBooting) {
return;

View File

@@ -0,0 +1,52 @@
<?php
namespace MailPoet\Test\Acceptance;
use MailPoet\Automation\Engine\Migrations\Migrator;
use MailPoet\DI\ContainerWrapper;
use MailPoet\Features\FeaturesController;
use MailPoet\Test\DataFactories\Features;
class ConfirmLeaveWhenUnsavedChangesCest
{
public function _before() {
// @ToDo Remove once MVP is released.
$features = new Features();
$features->withFeatureEnabled(FeaturesController::AUTOMATION);
$container = ContainerWrapper::getInstance();
$migrator = $container->get(Migrator::class);
$migrator->deleteSchema();
$migrator->createSchema();
}
public function confirmationIsRequiredIfWorkflowNotSaved(\AcceptanceTester $i) {
$i->wantTo('Edit a new workflow draft');
$i->login();
$i->amOnMailpoetPage('Automation');
$i->see('Automations');
$i->waitForText('Better engagement begins with automation');
$i->dontSee('Active');
$i->dontSee('Entered');
$i->click('Start with a template');
$i->see('Choose your automation template');
$i->click('Simple welcome email');
$i->waitForText('Draft');
$i->click('Trigger');
$i->fillField('When someone subscribes to the following lists:', 'Newsletter mailing list');
$i->click('Delay');
$i->fillField('Wait for', '5');
$i->wantTo('Leave the page without saving.');
$i->reloadPage();
$i->cancelPopup();
$i->wantTo('Leave the page after saving.');
$i->click('Save');
$i->waitForText('saved');
$i->reloadPage();
$i->waitForText('Draft');
}
}