diff --git a/packages/bruno-app/src/providers/ReduxStore/slices/notifications.js b/packages/bruno-app/src/providers/ReduxStore/slices/notifications.js index 60b4e2df7f..5d139765c8 100644 --- a/packages/bruno-app/src/providers/ReduxStore/slices/notifications.js +++ b/packages/bruno-app/src/providers/ReduxStore/slices/notifications.js @@ -9,6 +9,7 @@ const getReadNotificationIds = () => { return readNotificationIds; } catch (err) { toast.error('An error occurred while fetching read notifications'); + return []; } }; @@ -58,14 +59,16 @@ export const notificationSlice = createSlice({ }); }, markNotificationAsRead: (state, action) => { - if (state.readNotificationIds.includes(action.payload.notificationId)) return; + const { notificationId } = action.payload; + + if (state.readNotificationIds.includes(notificationId)) return; const notification = state.notifications.find( - (notification) => notification.id === action.payload.notificationId + (notification) => notification.id === notificationId ); if (!notification) return; - state.readNotificationIds.push(action.payload.notificationId); + state.readNotificationIds.push(notificationId); setReadNotificationsIds(state.readNotificationIds); notification.read = true; }, diff --git a/packages/bruno-app/src/utils/common/index.js b/packages/bruno-app/src/utils/common/index.js index 893c6f7fed..1244966b7c 100644 --- a/packages/bruno-app/src/utils/common/index.js +++ b/packages/bruno-app/src/utils/common/index.js @@ -151,7 +151,15 @@ export const relativeDate = (dateString) => { export const humanizeDate = (dateString) => { // See this discussion for why .split is necessary // https://stackoverflow.com/questions/7556591/is-the-javascript-date-object-always-one-day-off - const date = new Date(dateString.split('-')); + + if (!dateString || typeof dateString !== 'string') { + return 'Invalid Date'; + } + const date = new Date(dateString); + if (isNaN(date.getTime())) { + return 'Invalid Date'; + } + return date.toLocaleDateString('en-US', { year: 'numeric', month: 'long', diff --git a/packages/bruno-app/src/utils/common/index.spec.js b/packages/bruno-app/src/utils/common/index.spec.js index c4055c5d1c..39f3dff0ab 100644 --- a/packages/bruno-app/src/utils/common/index.spec.js +++ b/packages/bruno-app/src/utils/common/index.spec.js @@ -58,6 +58,18 @@ describe('common utils', () => { it('should return invalid date if the date is invalid', () => { expect(humanizeDate('9999-99-99')).toBe('Invalid Date'); }); + + it('should return "Invalid Date" if the date is null', () => { + expect(humanizeDate(null)).toBe('Invalid Date'); + }); + + it('should return a humanized date for a valid date in ISO format', () => { + expect(humanizeDate('2024-11-28T00:00:00Z')).toBe('November 28, 2024'); + }); + + it('should return "Invalid Date" for a non-date string', () => { + expect(humanizeDate('some random text')).toBe('Invalid Date'); + }); }); describe('relativeDate', () => {