From bf61ef435591c5497af223930b47a20cb99aefcb Mon Sep 17 00:00:00 2001 From: goemen Date: Mon, 23 Sep 2024 14:41:35 -0700 Subject: [PATCH 1/3] Display error message when download fails Fix: disappearing file on edit save --- .../announcements/AnnouncementForm.vue | 2 + .../announcements/AnnouncementItem.vue | 7 +-- .../announcements/AttachmentResource.vue | 13 ++++- .../__tests__/AttachmentResource.spec.ts | 50 +++++++++++++++++++ admin-frontend/src/constants/index.ts | 3 ++ admin-frontend/src/services/apiService.ts | 10 +++- backend/src/v1/routes/announcement-routes.ts | 3 +- 7 files changed, 78 insertions(+), 10 deletions(-) create mode 100644 admin-frontend/src/components/announcements/__tests__/AttachmentResource.spec.ts diff --git a/admin-frontend/src/components/announcements/AnnouncementForm.vue b/admin-frontend/src/components/announcements/AnnouncementForm.vue index 979cbddb1..1fbcd4dce 100644 --- a/admin-frontend/src/components/announcements/AnnouncementForm.vue +++ b/admin-frontend/src/components/announcements/AnnouncementForm.vue @@ -573,6 +573,7 @@ const handleDeleteLink = () => { }; const handleDeleteFile = () => { + attachment.value = undefined; fileDisplayName.value = undefined; fileDisplayOnly.value = false; }; @@ -841,6 +842,7 @@ const handleSave = handleSubmit(async (values) => { linkUrl: isEmpty(values.linkUrl) ? undefined : values.linkUrl, status: status.value, attachment: attachment.value, + attachmentId: !values.attachment && !values.fileDisplayName ? undefined : values.attachmentId, }); }); diff --git a/admin-frontend/src/components/announcements/AnnouncementItem.vue b/admin-frontend/src/components/announcements/AnnouncementItem.vue index e2c51817a..10e62f327 100644 --- a/admin-frontend/src/components/announcements/AnnouncementItem.vue +++ b/admin-frontend/src/components/announcements/AnnouncementItem.vue @@ -52,6 +52,7 @@ import { sanitizeUrl } from '@braintree/sanitize-url'; import ApiService from '../../services/apiService'; import { saveAs } from 'file-saver'; import { NotificationService } from '../../services/notificationService'; +import { FILE_DOWNLOAD_ERROR } from '../../constants'; defineProps<{ announcement: Announcement; @@ -67,11 +68,7 @@ async function downloadAnnouncementResource( ); } catch (error) { console.error(error); - NotificationService.pushNotificationError( - 'There is a problem with this link/file, please try again later or contact the helpdesk.', - '', - 30000, - ); + NotificationService.pushNotificationError(FILE_DOWNLOAD_ERROR, '', 30000); } } else if (announcementResource.announcement_resource_file) { //When a resource with type ATTACHMENT hasn't yet been uploaded to the diff --git a/admin-frontend/src/components/announcements/AttachmentResource.vue b/admin-frontend/src/components/announcements/AttachmentResource.vue index ae7cbf682..f56821fa7 100644 --- a/admin-frontend/src/components/announcements/AttachmentResource.vue +++ b/admin-frontend/src/components/announcements/AttachmentResource.vue @@ -1,6 +1,6 @@