Skip to content

Commit 1d7ee73

Browse files
committed
Handled all responses
1 parent 6bd4ade commit 1d7ee73

File tree

3 files changed

+57
-36
lines changed

3 files changed

+57
-36
lines changed

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

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,21 +12,22 @@
1212
];
1313
const markAllAsRead = () => {
1414
const markAllAsReadLink = Routing.generate('ibexa.notifications.mark_all_as_read');
15+
const message = Translator.trans(
16+
/* @Desc("Cannot mark all notifications as read") */ 'notifications.modal.message.error.mark_all_as_read',
17+
{},
18+
'ibexa_notifications',
19+
);
1520

1621
fetch(markAllAsReadLink, { mode: 'same-origin', credentials: 'same-origin' })
1722
.then(getJsonFromResponse)
1823
.then((response) => {
1924
if (response.status === 'success') {
2025
global.location.reload();
26+
} else {
27+
showErrorNotification(message);
2128
}
2229
})
2330
.catch(() => {
24-
const message = Translator.trans(
25-
/* @Desc("Cannot mark all notifications as read") */ 'notifications.modal.message.error.mark_all_as_read',
26-
{},
27-
'ibexa_notifications',
28-
);
29-
3031
showErrorNotification(message);
3132
});
3233
};
@@ -48,21 +49,23 @@
4849
ids: selectedNotifications,
4950
}),
5051
});
52+
const message = Translator.trans(
53+
/* @Desc("Cannot mark selected notifications as read") */
54+
'notifications.modal.message.error.mark_selected_as_read',
55+
{},
56+
'ibexa_notifications',
57+
);
5158

5259
fetch(request)
5360
.then(getJsonFromResponse)
5461
.then((response) => {
5562
if (response.status === 'success') {
5663
global.location.reload();
64+
} else {
65+
showErrorNotification(message);
5766
}
5867
})
5968
.catch(() => {
60-
const message = Translator.trans(
61-
/* @Desc("Cannot mark notifications as read") */
62-
'notifications.modal.message.error.mark_as_read',
63-
{},
64-
'ibexa_notifications',
65-
);
6669
showErrorNotification(message);
6770
});
6871
};
@@ -106,6 +109,15 @@
106109
if (!isToggle && response.redirect) {
107110
global.location = response.redirect;
108111
}
112+
} else {
113+
const message = Translator.trans(
114+
/* @Desc("Cannot update this notification") */
115+
'notifications.modal.message.error.update',
116+
{},
117+
'ibexa_notifications',
118+
);
119+
120+
showErrorNotification(message);
109121
}
110122
})
111123
.catch(showErrorNotification);

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

Lines changed: 28 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,11 @@
119119
};
120120
const markAllAsRead = () => {
121121
const markAllAsReadLink = Routing.generate('ibexa.notifications.mark_all_as_read');
122+
const message = Translator.trans(
123+
/* @Desc("Cannot mark all notifications as read") */ 'notifications.modal.message.error.mark_all_as_read',
124+
{},
125+
'ibexa_notifications',
126+
);
122127

123128
fetch(markAllAsReadLink, { mode: 'same-origin', credentials: 'same-origin' })
124129
.then(getJsonFromResponse)
@@ -128,21 +133,22 @@
128133

129134
allUnreadNotifications.forEach((notification) => notification.classList.add('ibexa-notifications-modal__item--read'));
130135
getNotificationsStatus();
136+
} else {
137+
showErrorNotification(message);
131138
}
132139
})
133140
.catch(() => {
134-
const message = Translator.trans(
135-
/* @Desc("Cannot mark all notifications as read") */ 'notifications.modal.message.error.mark_all_as_read',
136-
{},
137-
'ibexa_notifications',
138-
);
139-
140141
showErrorNotification(message);
141142
});
142143
};
143144
const markAsRead = ({ currentTarget }) => {
144145
const { notificationId } = currentTarget.dataset;
145146
const markAsReadLink = Routing.generate('ibexa.notifications.mark_as_read', { notificationId });
147+
const message = Translator.trans(
148+
/* @Desc("Cannot mark notification as read") */ 'notifications.modal.message.error.mark_as_read',
149+
{},
150+
'ibexa_notifications',
151+
);
146152

147153
fetch(markAsReadLink, { mode: 'same-origin', credentials: 'same-origin' })
148154
.then(getJsonFromResponse)
@@ -155,21 +161,22 @@
155161
menuInstance.closeMenu();
156162
notification.classList.add('ibexa-notifications-modal__item--read');
157163
getNotificationsStatus();
164+
} else {
165+
showErrorNotification(message);
158166
}
159167
})
160168
.catch(() => {
161-
const message = Translator.trans(
162-
/* @Desc("Cannot mark notification as read") */ 'notifications.modal.message.error.mark_as_read',
163-
{},
164-
'ibexa_notifications',
165-
);
166-
167169
showErrorNotification(message);
168170
});
169171
};
170172
const markAsUnread = ({ currentTarget }) => {
171173
const { notificationId } = currentTarget.dataset;
172174
const markAsUnreadLink = Routing.generate('ibexa.notifications.mark_as_unread', { notificationId });
175+
const message = Translator.trans(
176+
/* @Desc("Cannot mark notification as unread") */ 'notifications.modal.message.error.mark_as_unread',
177+
{},
178+
'ibexa_notifications',
179+
);
173180

174181
fetch(markAsUnreadLink, { mode: 'same-origin', credentials: 'same-origin' })
175182
.then(getJsonFromResponse)
@@ -182,21 +189,22 @@
182189
menuInstance.closeMenu();
183190
notification.classList.remove('ibexa-notifications-modal__item--read');
184191
getNotificationsStatus();
192+
} else {
193+
showErrorNotification(message);
185194
}
186195
})
187196
.catch(() => {
188-
const message = Translator.trans(
189-
/* @Desc("Cannot mark notification as unread") */ 'notifications.modal.message.error.mark_as_unread',
190-
{},
191-
'ibexa_notifications',
192-
);
193-
194197
showErrorNotification(message);
195198
});
196199
};
197200
const deleteNotification = ({ currentTarget }) => {
198201
const { notificationId } = currentTarget.dataset;
199202
const deleteLink = Routing.generate('ibexa.notifications.delete', { notificationId });
203+
const message = Translator.trans(
204+
/* @Desc("Cannot delete notification") */ 'notifications.modal.message.error.delete',
205+
{},
206+
'ibexa_notifications',
207+
);
200208

201209
fetch(deleteLink, { mode: 'same-origin', credentials: 'same-origin' })
202210
.then(getJsonFromResponse)
@@ -208,15 +216,11 @@
208216

209217
menuInstance.closeMenu();
210218
notification.remove();
219+
} else {
220+
showErrorNotification(message);
211221
}
212222
})
213223
.catch(() => {
214-
const message = Translator.trans(
215-
/* @Desc("Cannot delete notification") */ 'notifications.modal.message.error.delete',
216-
{},
217-
'ibexa_notifications',
218-
);
219-
220224
showErrorNotification(message);
221225
});
222226
};

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,11 @@
151151
<target state="new">Cannot mark selected notifications as read</target>
152152
<note>key: notifications.modal.message.error.mark_selected_as_read</note>
153153
</trans-unit>
154+
<trans-unit id="3474521689fc84daab1c58d9dcd260402f8d1563" resname="notifications.modal.message.error.update">
155+
<source>Cannot update this notification</source>
156+
<target state="new">Cannot update this notification</target>
157+
<note>key: notifications.modal.message.error.update</note>
158+
</trans-unit>
154159
</body>
155160
</file>
156161
</xliff>

0 commit comments

Comments
 (0)