Skip to content

Commit 19e62df

Browse files
committed
feat(notifications): Make panel to render notification type based icon
1 parent 13ead0a commit 19e62df

3 files changed

Lines changed: 21 additions & 6 deletions

File tree

src/notifications/NotificationsPanel.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export const NotificationsPanel = ({ handleClose, notifications }: Props) => {
2424
<NPC.Body>
2525
{notifications.map(n => (
2626
<NPC.Item key={n.created_at} onClick={handleClose}>
27-
{getNotificationIcon("foo")}
27+
{getNotificationIcon(n.notification_type)}
2828
<div aria-label="NotificationItem">
2929
<Typography variant="body2">{n.data.topic_title}</Typography>
3030
<Typography variant="caption">
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// @flow
2+
3+
import { getNotificationTypeName } from "../helpers";
4+
5+
describe("helpers", () => {
6+
describe("getNotificationTypeName", () => {
7+
it("returns mapped notification name after number", () => {
8+
expect(getNotificationTypeName(1)).toEqual("replied");
9+
});
10+
});
11+
});

src/notifications/helpers.js

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,15 +62,19 @@ const iconsMapping = {
6262
[notificationTypes[16]]: AddComment,
6363
};
6464

65+
export const getNotificationTypeName = (
66+
notificationType: string | number
67+
): string => {
68+
return typeof notificationType === "number"
69+
? notificationTypes[notificationType]
70+
: notificationType;
71+
};
72+
6573
export const getNotificationIcon = (
6674
notificationType: string | number,
6775
color: string = "disabled"
6876
) => {
69-
const notificationIndex =
70-
typeof notificationType === "number"
71-
? notificationType
72-
: notificationTypes.indexOf(notificationType);
73-
const Icon = iconsMapping[notificationIndex];
77+
const Icon = iconsMapping[getNotificationTypeName(notificationType)];
7478

7579
return Icon ? <Icon color={color} /> : <Announcement color={color} />;
7680
};

0 commit comments

Comments
 (0)