Skip to content

Commit 708fe7a

Browse files
authored
fix: Default outline shown for the avatar container if the url is invalid
1 parent 2f56429 commit 708fe7a

File tree

10 files changed

+29
-16
lines changed

10 files changed

+29
-16
lines changed

jest.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ export default {
77
transform: {
88
"^.+\\.[t|j]sx?$": "ts-jest",
99
"^.+\\.svg?$": "<rootDir>/transform.js",
10+
"^.+\\.png?$": "<rootDir>/transform.js",
1011
"^.+\\.scss?$": "<rootDir>/transform.js"
1112
},
1213
};
11.7 KB
Loading

src/assets/defaultAvatar.svg

Lines changed: 0 additions & 5 deletions
This file was deleted.
11.4 KB
Loading

src/components/Card.tsx

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ import React, { type FC } from "react";
33

44
import CloseIcon from "./CloseIcon";
55
import TimerIcon from "./TimerIcon";
6-
import DefaultAvatar from "../assets/defaultAvatar.svg";
6+
import defaultAvatarDark from "../assets/dark/defaultAvatarDark.png";
7+
import defaultAvatarLight from "../assets/light/defaultAvatarLight.png";
78
import type { NotificationCardProps } from "../types";
89
import { generateElapsedTimeText } from "../utils/commonUtils";
910
import "../styles/card.css";
@@ -44,6 +45,7 @@ const Card: FC<NotificationCardProps> = ({
4445
notification,
4546
cardProps,
4647
styles,
48+
darkMode,
4749
onNotificationCardClick,
4850
deleteNotificationById,
4951
}) => {
@@ -55,7 +57,8 @@ const Card: FC<NotificationCardProps> = ({
5557
event.stopPropagation();
5658
};
5759

58-
const cardConatinerStyle: CSSProperties = isRead
60+
const defaultAvatar = darkMode ? defaultAvatarDark : defaultAvatarLight;
61+
const cardContainerStyle: CSSProperties = isRead
5962
? {
6063
...styles.defaultCardContainer,
6164
borderLeft: "4px transparent solid",
@@ -68,7 +71,7 @@ const Card: FC<NotificationCardProps> = ({
6871

6972
return (
7073
<div
71-
style={cardConatinerStyle}
74+
style={cardContainerStyle}
7275
className={`${
7376
cardProps?.hideAvatar
7477
? "siren-sdk-hide-avatar-card-container"
@@ -80,10 +83,13 @@ const Card: FC<NotificationCardProps> = ({
8083
data-testid={`card-${notification.id}`}
8184
>
8285
{!cardProps?.hideAvatar && (
83-
<img
84-
src={avatar?.imageUrl || DefaultAvatar}
85-
alt=""
86-
style={styles.cardIconRound}
86+
<div
87+
style={{
88+
...styles.cardIconRound,
89+
backgroundImage: `url(${avatar?.imageUrl || defaultAvatar})`,
90+
backgroundSize: 'cover',
91+
backgroundPosition: 'center',
92+
}}
8793
/>
8894
)}
8995
<div className="siren-sdk-card-content-wrapper">

src/components/SirenPanel.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,7 @@ const SirenPanel: FC<SirenPanelProps> = ({
356356
deleteNotificationById={deleteNotificationById}
357357
styles={styles}
358358
key={item.id}
359+
darkMode={darkMode}
359360
data-testid="notification-card"
360361
/>
361362
));

src/global.d.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,8 @@ declare module '*.svg' {
22
const content: string;
33
export default content;
44
}
5+
6+
declare module '*.png' {
7+
const value: string;
8+
export = value;
9+
}

src/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ export type NotificationCardProps = {
5555
onNotificationCardClick: SirenInboxProps["onNotificationCardClick"];
5656
styles: SirenStyleProps;
5757
deleteNotificationById: (id: string) => void;
58+
darkMode: boolean;
5859
};
5960

6061
export type SirenNotificationButtonProps = {

tests/components/__snapshots__/card.spec.tsx.snap

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,8 @@ exports[`matches snapshot 1`] = `
77
data-testid="card-1"
88
style="background-color: rgb(46, 45, 48); padding: 10px; border-bottom: 0.5px solid; border-color: #344054; border-left: 4px solid #F56630;"
99
>
10-
<img
11-
alt=""
12-
src="[object Object]"
13-
style="width: 40px; height: 40px; border-radius: 20px; overflow: hidden; background-color: rgb(52, 64, 84);"
10+
<div
11+
style="width: 40px; height: 40px; border-radius: 20px; overflow: hidden; background-color: rgb(52, 64, 84); background-size: cover; background-position: center;"
1412
/>
1513
<div
1614
class="siren-sdk-card-content-wrapper"

tests/components/card.spec.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ test("matches snapshot", () => {
4040
onNotificationCardClick={mockOnNotificationCardClick}
4141
cardProps={{}}
4242
styles={style}
43+
darkMode={false}
4344
/>
4445
);
4546

@@ -53,6 +54,7 @@ test("renders notification card with basic content", () => {
5354
onNotificationCardClick={mockOnNotificationCardClick}
5455
cardProps={{}}
5556
styles={style}
57+
darkMode={false}
5658
/>
5759
);
5860

@@ -67,6 +69,7 @@ test("triggers delete notification callback on delete button click", () => {
6769
onNotificationCardClick={mockOnNotificationCardClick}
6870
cardProps={{}}
6971
styles={style}
72+
darkMode={false}
7073
/>
7174
);
7275
const deleteButton = screen.getByTestId("delete-1");
@@ -83,6 +86,7 @@ test("triggers notification card click callback on card click", () => {
8386
onNotificationCardClick={mockOnNotificationCardClick}
8487
cardProps={{ hideAvatar: true }}
8588
styles={style}
89+
darkMode={false}
8690
/>
8791
);
8892

@@ -100,6 +104,7 @@ test("renders header, subheader, and body", () => {
100104
onNotificationCardClick={mockOnNotificationCardClick}
101105
cardProps={{}}
102106
styles={style}
107+
darkMode={false}
103108
/>
104109
);
105110

@@ -120,6 +125,7 @@ test("does not render avatar if hideAvatar is true", () => {
120125
onNotificationCardClick={mockOnNotificationCardClick}
121126
cardProps={{ hideAvatar: true }}
122127
styles={style}
128+
darkMode={false}
123129
/>
124130
);
125131

0 commit comments

Comments
 (0)