-
Notifications
You must be signed in to change notification settings - Fork 2
BEG-223: Add session expiry warning modal #15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
c879472
a519ccc
8e8e90a
ac78bb8
f388141
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Aligent\Pci4Compatibility\ViewModel; | ||
|
||
use Magento\Framework\App\Config\ScopeConfigInterface; | ||
use Magento\Framework\View\Element\Block\ArgumentInterface; | ||
|
||
class Modal implements ArgumentInterface | ||
{ | ||
/** | ||
* Constructor | ||
* @param ScopeConfigInterface $scopeConfig | ||
*/ | ||
public function __construct( | ||
private readonly ScopeConfigInterface $scopeConfig, | ||
) { | ||
} | ||
|
||
/** | ||
* Returns the duration in ms after refresh when the session expiry warning modal should appear | ||
* | ||
* @return int | ||
*/ | ||
public function getModalPopupTimeout(): int | ||
{ | ||
// This value is in seconds | ||
$sessionTimeout = $this->scopeConfig->getValue( | ||
'admin/security/session_lifetime', | ||
ScopeConfigInterface::SCOPE_TYPE_DEFAULT | ||
); | ||
|
||
// Then we want the popup to appear one minute before timeout | ||
return ($sessionTimeout - 60) * 1000; | ||
} | ||
} |
brettlaishley marked this conversation as resolved.
Show resolved
Hide resolved
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<?xml version="1.0" ?> | ||
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd"> | ||
<body> | ||
<referenceContainer name="page.main.actions"> | ||
<block class="Magento\Backend\Block\Template" name="session.expiry.modal" as="modal" template="Aligent_Pci4Compatibility::modal.phtml"> | ||
<arguments> | ||
<argument name="view_model" xsi:type="object">Aligent\Pci4Compatibility\ViewModel\Modal</argument> | ||
</arguments> | ||
</block> | ||
</referenceContainer> | ||
</body> | ||
</page> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
<?php | ||
|
||
use CountryCareGroup\Service\ViewModel\Modal; | ||
use Magento\Catalog\Block\Product\View; | ||
use Magento\Framework\Escaper; | ||
|
||
/** | ||
* @var View $block | ||
* @var Escaper $escaper | ||
* @var Modal $viewModel | ||
*/ | ||
$viewModel = $block->getViewModel(); | ||
$modalTimeout = $viewModel->getModalPopupTimeout(); | ||
|
||
?> | ||
|
||
<div id="session-expire-warning-modal"> | ||
<p style="font-size:48px;color:#FF0000">⚠</p> | ||
<p>Your admin session will expire in one minute, please save your changes or refresh the page.</p> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we want to actually give the option to extend the session asynchronously? It would be more user-friendly. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm happy to, but I might need a bit more guidance on how to do that. Just exploring options now, I added a button to refresh the page, but what would be the best way to refresh the session without refreshing the entire page and potentially losing any unsvaed changes? So far I just added this to the phtml:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The trouble with just reloading the page is that the user is likely to lose whatever changes they've got. We should be able to execute an AJAX request that can renew their session, but remain on the page they're currently on. |
||
</div> | ||
|
||
<script> | ||
require( | ||
[ | ||
'jquery', | ||
'Magento_Ui/js/modal/modal', | ||
], | ||
function( | ||
$, | ||
modal | ||
) { | ||
var options = { | ||
type: 'popup', | ||
innerScroll: true, | ||
title: false, | ||
modalClass:'modal-admintimeout', | ||
buttons: [{ | ||
text: $.mage.__('Close'), | ||
class: '', | ||
click: function () { | ||
this.closeModal(); | ||
} | ||
}] | ||
}; | ||
$(document).ready(function(){ | ||
modal(options, $('#session-expire-warning-modal')); | ||
setTimeout( | ||
function() { | ||
$('#session-expire-warning-modal').modal('openModal') | ||
}, | ||
<?= $modalTimeout ?> | ||
); | ||
}); | ||
} | ||
); | ||
</script> |
Uh oh!
There was an error while loading. Please reload this page.