{paginatedGroupedNotifications.length === 0 && (
You don't have any notifications. Try changing your settings to see
more.
)}
{paginatedGroupedNotifications.map((notification) =>
notification.type === 'income' ? (
) : notification.notifications.length === 1 ? (
) : (
)
)}
{paginatedGroupedNotifications.length > 0 &&
allGroupedNotifications.length > NOTIFICATIONS_PER_PAGE && (
)}
)
}
function IncomeNotificationGroupItem(props: {
notificationGroup: NotificationGroup
className?: string
}) {
const { notificationGroup, className } = props
const { notifications } = notificationGroup
const numSummaryLines = 3
const [expanded, setExpanded] = useState(false)
const [highlighted, setHighlighted] = useState(
notifications.some((n) => !n.isSeen)
)
useEffect(() => {
setNotificationsAsSeen(notifications)
}, [notifications])
useEffect(() => {
if (expanded) setHighlighted(false)
}, [expanded])
const totalIncome = sum(
notifications.map((notification) =>
notification.sourceText ? parseInt(notification.sourceText) : 0
)
)
// Loop through the contracts and combine the notification items into one
function combineNotificationsByAddingNumericSourceTexts(
notifications: Notification[]
) {
const newNotifications = []
const groupedNotificationsBySourceType = groupBy(
notifications,
(n) => n.sourceType
)
for (const sourceType in groupedNotificationsBySourceType) {
const groupedNotificationsByContractId = groupBy(
groupedNotificationsBySourceType[sourceType],
(notification) => {
return notification.sourceContractId
}
)
for (const contractId in groupedNotificationsByContractId) {
const notificationsForContractId =
groupedNotificationsByContractId[contractId]
if (notificationsForContractId.length === 1) {
newNotifications.push(notificationsForContractId[0])
continue
}
let sum = 0
notificationsForContractId.forEach(
(notification) =>
notification.sourceText &&
(sum = parseInt(notification.sourceText) + sum)
)
const uniqueUsers = uniq(
notificationsForContractId.map((notification) => {
return notification.sourceUserUsername
})
)
const newNotification = {
...notificationsForContractId[0],
sourceText: sum.toString(),
sourceUserUsername:
uniqueUsers.length > 1
? MULTIPLE_USERS_KEY
: notificationsForContractId[0].sourceType,
}
newNotifications.push(newNotification)
}
}
return newNotifications
}
const combinedNotifs =
combineNotificationsByAddingNumericSourceTexts(notifications)
return (