Skip to content

Commit 1165501

Browse files
RopRaptorKamilSznajdrowicz
authored andcommitted
IBX-10609: Enhance notification deletion by integrating modal confirmation.
1 parent 0ebe2b3 commit 1165501

File tree

4 files changed

+44
-11
lines changed

4 files changed

+44
-11
lines changed

src/bundle/Resources/public/js/scripts/admin.notifications.modal.js

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
1+
import { controlZIndex } from './helpers/modal.helper';
2+
13
(function (global, doc, ibexa, Translator, Routing) {
24
let currentPageLink = null;
35
let getNotificationsStatusErrorShowed = false;
46
let lastFailedCountFetchNotificationNode = null;
7+
let selectedNotificationId = null;
58
const SELECTOR_MODAL_ITEM = '.ibexa-notifications-modal__item';
69
const SELECTOR_MODAL_RESULTS = '.ibexa-notifications-modal__results .ibexa-scrollable-wrapper';
710
const SELECTOR_MODAL_TITLE = '.ibexa-side-panel__header';
@@ -214,9 +217,8 @@
214217

215218
currentTarget.textContent.trim() === markAsReadLabel ? markAsRead({ currentTarget }) : markAsUnread({ currentTarget });
216219
};
217-
const deleteNotification = ({ currentTarget }) => {
218-
const { notificationId } = currentTarget.dataset;
219-
const deleteLink = Routing.generate('ibexa.notifications.delete', { notificationId });
220+
const deleteNotification = () => {
221+
const deleteLink = Routing.generate('ibexa.notifications.delete', { notificationId: selectedNotificationId });
220222
const message = Translator.trans(
221223
/* @Desc("Cannot delete notification") */ 'notifications.modal.message.error.delete',
222224
{},
@@ -227,11 +229,10 @@
227229
.then(getJsonFromResponse)
228230
.then((response) => {
229231
if (response.status === 'success') {
230-
const notification = doc.querySelector(`.ibexa-notifications-modal__item[data-notification-id="${notificationId}"]`);
231-
const menuBranch = currentTarget.closest('.ibexa-multilevel-popup-menu__branch');
232-
const menuInstance = ibexa.helpers.objectInstances.getInstance(menuBranch.menuInstanceElement);
232+
const notification = doc.querySelector(
233+
`.ibexa-notifications-modal__item[data-notification-id="${selectedNotificationId}"]`,
234+
);
233235

234-
menuInstance.closeMenu();
235236
notification.remove();
236237
getNotificationsStatus();
237238
} else {
@@ -245,15 +246,26 @@
245246
const attachActionsListeners = () => {
246247
const attachListener = (node, callback) => node.addEventListener('click', callback, false);
247248
const markAsButtons = doc.querySelectorAll('.ibexa-notifications-modal--mark-as');
248-
const deleteButtons = doc.querySelectorAll('.ibexa-notifications-modal--delete');
249+
const deleteButtons = doc.querySelectorAll('.ibexa-notifications-open-modal-button');
250+
const confirmDeleteButton = doc.querySelector('.ibexa-notifications-modal--delete--confirm');
251+
const setNotificationId = ({ currentTarget }) => {
252+
const deleteModal = doc.querySelector('.modal-backdrop.show.fade');
253+
controlZIndex(deleteModal, '199');
254+
255+
selectedNotificationId = currentTarget.dataset.notificationId;
256+
};
249257

250258
markAsButtons.forEach((markAsButton) => {
251259
attachListener(markAsButton, handleMarkAsAction);
252260
});
253261

254262
deleteButtons.forEach((deleteButton) => {
255-
attachListener(deleteButton, deleteNotification);
263+
attachListener(deleteButton, setNotificationId);
256264
});
265+
266+
if (confirmDeleteButton) {
267+
confirmDeleteButton.addEventListener('click', deleteNotification);
268+
}
257269
};
258270
const showNotificationPage = (pageHtml) => {
259271
const modalResults = panel.querySelector(SELECTOR_MODAL_RESULTS);

src/bundle/Resources/public/js/scripts/helpers/modal.helper.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
const controlZIndex = (container) => {
1+
const controlZIndex = (container, ZIndexValue) => {
22
const initialZIndex = container.style.zIndex;
3+
container.style.zIndex = ZIndexValue;
34

45
container.addEventListener('show.bs.modal', () => {
56
container.style.zIndex = 'initial';

src/bundle/Resources/translations/ibexa_notifications.en.xliff

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,11 @@
9696
<target state="new">Mark as unread</target>
9797
<note>key: notification.mark_as_unread</note>
9898
</trans-unit>
99+
<trans-unit id="1b5f287ab1b01d5f0402378d633e8924aad59c98" resname="notification.modal.delete.confirm_message">
100+
<source>Are you sure you want to delete this notification?</source>
101+
<target state="new">Are you sure you want to delete this notification?</target>
102+
<note>key: notification.modal.delete.confirm_message</note>
103+
</trans-unit>
99104
<trans-unit id="5b03625b8de51d296ad7f4bc980e631c964185d8" resname="notification.no_longer_available">
100105
<source>The Content item is no longer available</source>
101106
<target state="new">The Content item is no longer available</target>

src/bundle/Resources/views/themes/admin/account/notifications/list_item.html.twig

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,11 @@
4747

4848
{% set popup_items = popup_items|merge([{
4949
label: 'notification.delete'|trans|desc('Delete'),
50-
action_attr: { class: 'ibexa-notifications-modal--delete', 'data-notification-id': notification.id },
50+
action_attr: {
51+
class: 'ibexa-notifications-open-modal-button',
52+
'data-notification-id': notification.id,
53+
'data-bs-toggle': 'modal',
54+
'data-bs-target': '#delete-notification-modal', }
5155
}]) %}
5256

5357
{% embed '@ibexadesign/ui/component/table/table_body_row.html.twig' with {
@@ -103,3 +107,14 @@
103107
{% endembed %}
104108
{% endblock %}
105109
{% endembed %}
110+
111+
{% embed '@ibexadesign/ui/modal/delete_confirmation.html.twig' with {
112+
id: 'delete-notification-modal',
113+
message: 'notification.modal.delete.confirm_message'|trans|desc('Are you sure you want to delete this notification?'),
114+
} %}
115+
{% block confirm_button %}
116+
<button class="btn ibexa-btn ibexa-btn--primary ibexa-notifications-modal--delete--confirm" data-bs-dismiss="modal">
117+
{{ 'modal.delete'|trans|desc('Delete') }}
118+
</button>
119+
{% endblock %}
120+
{% endembed %}

0 commit comments

Comments
 (0)