Skip to content

Commit 68d5772

Browse files
authored
Merge pull request #4278 from bbc/conal/IMAGEDAM-1674-notificationBannerWithModal
IMAGEDAM-1674: Notification banner displays messages about send to PhotoSales success/failure
2 parents 7eee32a + 30cf186 commit 68d5772

File tree

5 files changed

+50
-17
lines changed

5 files changed

+50
-17
lines changed

kahuna/public/js/components/gr-notifications-banner/gr-notifications-banner.tsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,11 @@ const NotificationsBanner: React.FC = () => {
151151
});
152152
};
153153

154+
const newNotification = (event:any) => {
155+
const notification = event.detail;
156+
setNotifications(prev_notifs => mergeArraysByKey(prev_notifs, [notification], 'announceId'));
157+
};
158+
154159
useEffect(() => {
155160
const announce = window._clientConfig.announcements;
156161
const tdy = todayStr();
@@ -169,6 +174,7 @@ const NotificationsBanner: React.FC = () => {
169174
document.addEventListener("mouseup", autoHideListener);
170175
document.addEventListener("scroll", autoHideListener);
171176
document.addEventListener("keydown", autoHideListener);
177+
window.addEventListener("newNotification", newNotification);
172178

173179
// clean up cookie
174180
if (notif_cookie) {
@@ -183,6 +189,7 @@ const NotificationsBanner: React.FC = () => {
183189
document.removeEventListener("mouseup", autoHideListener);
184190
document.removeEventListener("scroll", autoHideListener);
185191
document.removeEventListener("keydown", autoHideListener);
192+
window.removeEventListener("newNotification", newNotification);
186193
clearInterval(checkNotificationsRef);
187194
};
188195

@@ -220,7 +227,7 @@ const NotificationsBanner: React.FC = () => {
220227
key={"notification-inner-" + notification.announceId}>
221228
{notification.description} 
222229
</span>
223-
{(notification.url != "") &&
230+
{(notification.url && notification.url != "") &&
224231
<span tabIndex={0}
225232
key={"notification-url-" + notification.announceId}
226233
role="link"
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
<div ng-if="notifctrl.hasNotifications" class="global-notifications">
1+
<div class="global-notifications">
22
<notifications-banner class="notifications-banner"></notifications-banner>
33
</div>

kahuna/public/js/notifications/notifications.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ notifications.controller('NotificationsCtrl',
1313
const notifctrl = this;
1414
notifctrl.$onInit = () => {
1515
notifctrl.notifications = window._clientConfig.announcements;
16-
notifctrl.hasNotifications = notifctrl.notifications.length > 0;
1716
};
1817
}
1918
]);

kahuna/public/js/search/results.js

Lines changed: 38 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ import '../components/gr-confirmation-modal/gr-confirmation-modal';
2323
import {
2424
INVALIDIMAGES,
2525
sendToCaptureAllValid, sendToCaptureCancelBtnTxt, sendToCaptureConfirmBtnTxt, sendToCaptureInvalid,
26-
sendToCaptureMixed, sendToCaptureSingleBtnTxt,
26+
sendToCaptureSuccess, sendToCaptureFailure, announcementId,
27+
sendToCaptureMixed,
2728
sendToCaptureTitle,
2829
VALIDIMAGES
2930
} from "../util/constants/sendToCapture-config";
@@ -419,18 +420,42 @@ results.controller('SearchResultsCtrl', [
419420
};
420421

421422
ctrl.sendToPhotoSales = () => {
422-
const validImages = validatePhotoSalesSelection(ctrl.selectedImages)[0];
423-
validImages.map(image => {
424-
mediaApi.syndicateImage(image.data.id, "Capture", "true");
425-
});
426-
ctrl.clearSelection();
423+
try {
424+
const validImages = validatePhotoSalesSelection(ctrl.selectedImages)[0];
425+
validImages.map(image => {
426+
mediaApi.syndicateImage(image.data.id, "Capture", "true");
427+
});
428+
ctrl.clearSelection();
429+
const notificationEvent = new CustomEvent("newNotification", {
430+
detail: {
431+
announceId: announcementId,
432+
description: sendToCaptureSuccess,
433+
category: "success",
434+
lifespan: "transient"
435+
},
436+
bubbles: true
437+
});
438+
window.dispatchEvent(notificationEvent);
439+
} catch (err) {
440+
console.log(err);
441+
const notificationEvent = new CustomEvent("newNotification", {
442+
detail: {
443+
announceId: announcementId,
444+
description: sendToCaptureFailure,
445+
category: "error",
446+
lifespan: "transient"
447+
},
448+
bubbles: true
449+
});
450+
window.dispatchEvent(notificationEvent);
451+
}
427452
};
428453

429-
ctrl.displayConfirmationModal = () => { // rename to display send to photosales once banner used?
454+
ctrl.displayConfirmationModal = () => {
430455

431456
const [validImages, invalidImages] = validatePhotoSalesSelection(ctrl.selectedImages);
432457
const title = sendToCaptureTitle;
433-
let eventType; /// required once banner event is in use
458+
let eventType;
434459
let detailObj;
435460

436461
if (validImages.length !== 0 && invalidImages.length === 0) {
@@ -457,13 +482,12 @@ results.controller('SearchResultsCtrl', [
457482

458483
} else if (validImages.length === 0 && invalidImages.length !== 0) {
459484
// No valid images selected
460-
eventType = "displayModal"; //banner event in final version
485+
eventType = "newNotification";
461486
detailObj = {
462-
title: title,
463-
message: sendToCaptureInvalid,
464-
confirmBtnTxt: sendToCaptureSingleBtnTxt,
465-
showSingleBtn: true,
466-
okayFn: () => {}
487+
announceId: announcementId,
488+
description: sendToCaptureInvalid,
489+
category: "warning",
490+
lifespan: "transient"
467491
};
468492
}
469493

kahuna/public/js/util/constants/sendToCapture-config.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ export const sendToCaptureTitle = "Are you sure?";
22
export const sendToCaptureAllValid = "Do you want to send these images to Photo Sales?";
33
export const sendToCaptureMixed = "Do you want to send these images to Photo Sales?; #VALIDIMAGES# of these images will be sent through to Photo Sales; #INVALIDIMAGES# are already in Photo Sales and will not be sent again; Look out for the Photo Sales logo which will identify these images";
44
export const sendToCaptureInvalid = "The image(s) selected are already in Photo Sales. If an image has the Photo Sales logo it already exists there";
5+
export const sendToCaptureSuccess = "The image(s) is being sent to Photo Sales. Check in Photo Sales that the image has been received.";
6+
export const sendToCaptureFailure = "Sending the image(s) to Photo Sales has failed. Try again and if the problem continues, contact bbc-images-support@bbc.co.uk.";
7+
export const announcementId = "sendToCaptureNotification";
58
export const VALIDIMAGES = "#VALIDIMAGES#";
69
export const INVALIDIMAGES = "#INVALIDIMAGES#";
710
export const sendToCaptureCancelBtnTxt = "No";

0 commit comments

Comments
 (0)