UNPKG

@magicbell/react-headless

Version:

Hooks to build a notification inbox

40 lines 1.72 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = useNotificationFactory; const ramda_1 = require("ramda"); const date_js_1 = require("../lib/date.js"); const json_js_1 = require("../lib/json.js"); const index_js_1 = require("../stores/notifications/index.js"); /** * Hook that builds a notification object. * * @param data Notification data. */ function useNotificationFactory(data) { const { markNotificationAsRead, markNotificationAsSeen, markNotificationAsUnread, deleteNotification, archiveNotification, unarchiveNotification, } = (0, index_js_1.useNotificationStoresCollection)(); const markAsSeen = () => markNotificationAsSeen(data); const markAsRead = () => markNotificationAsRead(data); const markAsUnread = () => markNotificationAsUnread(data); const deleteSelf = () => deleteNotification(data); const archive = () => archiveNotification(data); const unarchive = () => unarchiveNotification(data); return { ...data, customAttributes: (0, json_js_1.parseJSON)(data.customAttributes), readAt: (0, date_js_1.secondsToDate)(data.readAt), seenAt: (0, date_js_1.secondsToDate)(data.seenAt), sentAt: (0, date_js_1.secondsToDate)(data.sentAt), archivedAt: (0, date_js_1.secondsToDate)(data.archivedAt), isSeen: !(0, ramda_1.isNil)(data.seenAt), isRead: !(0, ramda_1.isNil)(data.readAt), isArchived: !(0, ramda_1.isNil)(data.archivedAt), sanitizedContent: data.content, markAsSeen, markAsRead, markAsUnread, delete: deleteSelf, archive, unarchive, }; } //# sourceMappingURL=useNotificationFactory.js.map