Skip to content

Commit 0af3aab

Browse files
authored
refactor: Update prop and function names, and modify the logic for real-time fetch
1 parent 5e855f4 commit 0af3aab

21 files changed

+593
-692
lines changed

README.md

Lines changed: 21 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -58,16 +58,17 @@ Below are optional props available for the inbox component:
5858
Prop | Description | Type | Default value |
5959
--- | --- | --- | --- |
6060
theme | Object for custom themes | Theme | {} |
61+
customStyles | Object for custom styling | CustomStyle | {} |
6162
loadMoreLabel | Text shown on the load more component | string | "Load More" |
6263
hideBadge | Toggle to hide or show the badge | boolean | false |
6364
darkMode | Toggle to enable dark mode | boolean | false |
6465
itemsPerFetch | Number of notifications fetch per api request (have a max cap of 50) | number | 20 |
6566
windowViewOnly | Toggle to enable fit-to-screen window or modal view | boolean | false |
6667
notificationIcon | Option to use custom notification Icon | JSX Element | null |
67-
inboxHeaderProps | Props for customizing the header.<br> title - Title of the notification inbox<br> hideHeader - Toggle to hide or show the header section.<br> hideClearAll - Toggle to hide or show the clear all button.<br> customHeader - Custom header component. | InboxHeaderProps| { title: 'Notifications', <br>hideHeader: false,<br> hideClearAll: false, <br>customHeader: null } |
68-
cardProps | Props for customizing the notification cards. <br>hideDelete - Toggle to hide or show delete icon<br> hideAvatar - Toggle to hide or show the avatar.<br> disableAutoMarkAsRead - Toggle to disable or enable the markAsRead functionality on card click.<br> deleteIcon - Custom delete icon <br> onAvatarClick - Custom click handler for avatar | CardProps | { hideDelete: false,<br> hideAvatar: false,<br> disableAutoMarkAsRead: false, <br> onAvatarClick: ()=>null } |
69-
customNotificationCard | Function for rendering custom notification cards | (notification)=> JSX Element | null |
70-
onNotificationCardClick | Custom click handler for notification cards | (notification)=> void | ()=>null |
68+
headerProps | Props for customizing the header.<br> title - Title of the notification inbox<br> hideHeader - Toggle to hide or show the header section.<br> hideClearAll - Toggle to hide or show the clear all button.<br> customHeader - Custom header component. | HeaderProps| { title: 'Notifications', <br>hideHeader: false,<br> hideClearAll: false, <br>customHeader: null } |
69+
cardProps | Props for customizing the notification cards. <br>hideDelete - Toggle to hide or show delete icon<br> hideAvatar - Toggle to hide or show the avatar.<br> disableAutoMarkAsRead - Toggle to disable or enable the markAsReadById functionality on card click.<br> deleteIcon - Custom delete icon <br> onAvatarClick - Custom click handler for avatar | CardProps | { hideDelete: false,<br> hideAvatar: false,<br> disableAutoMarkAsRead: false, <br> deleteIcon: null, <br> onAvatarClick: ()=>null } |
70+
customCard | Function for rendering custom notification cards | (notification)=> JSX Element | null |
71+
onCardClick | Custom click handler for notification cards | (notification)=> void | ()=>null |
7172
listEmptyComponent | Custom component for empty notification list | JSX Element | null |
7273
customFooter | Custom footer component | JSX Element | null |
7374
customLoader | Custom loader component | JSX Element | null |
@@ -108,9 +109,6 @@ type ThemeProps = {
108109
color?: string,
109110
textColor?: string,
110111
},
111-
window?: {
112-
borderColor?: string,
113-
},
114112
windowHeader?: {
115113
background?: string,
116114
titleColor?: string,
@@ -120,11 +118,11 @@ type ThemeProps = {
120118
windowContainer?: {
121119
background?: string,
122120
},
123-
notificationCard?: {
121+
customCard?: {
124122
borderColor?: string,
125123
background?: string,
126124
titleColor?: string,
127-
subTitleColor?: string,
125+
subtitleColor?: string,
128126
descriptionColor?: string,
129127
},
130128
loadMoreButton?: {
@@ -160,15 +158,15 @@ Please note that the badgeStyle, window shadow and border props are only applica
160158
padding?: number,
161159
contentHeight?: DimensionValue,
162160
},
163-
notificationCard?: {
161+
customCard?: {
164162
padding?: number,
165163
borderWidth?: number,
166164
avatarSize?: number,
167165
titleFontWeight?: TextStyle["fontWeight"],
168166
titleSize?: number,
169-
subTitleFontWeight?: TextStyle['fontWeight'];
170-
subTitleSize?: number
171-
descriptionFontWeight?: TextStyle['fontWeight'];
167+
subtitleFontWeight?: TextStyle['fontWeight'],
168+
subtitleSize?: number,
169+
descriptionFontWeight?: TextStyle['fontWeight'],
172170
descriptionSize?: number,
173171
dateSize?: number,
174172
},
@@ -226,31 +224,11 @@ import { useSiren } from "@sirenapp/react-inbox";
226224

227225
function MyComponent() {
228226
const {
229-
markAsRead,
230-
deleteNotification,
231-
markAllNotificationsAsReadByDate,
232-
clearAllNotificationByDate,
233-
markNotificationsAsViewed,
227+
markAsReadById,
234228
} = useSiren();
235229

236230
function handleMarkAsRead(id) {
237-
markAsRead(id);
238-
}
239-
240-
function handleDeleteNotification(id) {
241-
deleteNotification(id);
242-
}
243-
244-
function handleMarkAllNotificationsAsReadByDate(untilDate) {
245-
markNotificationsAsReadByDate(untilDate);
246-
}
247-
248-
function handleClearAllNotificationByDate(untilDate) {
249-
deleteNotificationsByDate(untilDate);
250-
}
251-
252-
function handleMarkNotificationsAsViewed(untilDate) {
253-
markNotificationsAsViewed(untilDate);
231+
markAsReadById(id);
254232
}
255233

256234
return {
@@ -263,24 +241,12 @@ function MyComponent() {
263241

264242
Functions | Parameters | Type | Description |
265243
----------|------------|-------|------------|
266-
markNotificationsAsReadByDate | startDate | ISO date string | Sets the read status of notifications to true until the given date |
267-
markAsRead | id | string | Set read status of a notification to true |
268-
deleteNotification | id | string | Delete a notification by id |
269-
deleteNotificationsByDate | startDate | ISO date string | Delete all notifications until given date |
270-
markNotificationsAsViewed | startDate | ISO date string |Sets the viewed status of notifications to true until the given date |
271-
272-
## 5. Error codes
273-
274-
Given below are all possible error codes thrown by sdk.
244+
markAsReadByDate | startDate | ISO date string | Sets the read status of notifications to true until the given date |
245+
markAsReadById | id | string | Set read status of a notification to true |
246+
deleteById | id | string | Delete a notification by id |
247+
deleteByDate | startDate | ISO date string | Delete all notifications until given date |
248+
markAllAsViewed | startDate | ISO date string |Sets the viewed status of notifications to true until the given date |
275249

276-
Error code | Description |
277-
------------------------- | ------------------------------------------------------------------|
278-
INVALID_TOKEN | The token passed in the provider is invalid |
279-
INVALID_RECIPIENT_ID | The recipient id passed in the provider is invalid |
280-
TOKEN_VERIFICATION_FAILED | Verification of the given tokens has failed |
281-
GENERIC_API_ERROR | Occurrence of an unexpected api error |
282-
OUTSIDE_SIREN_CONTEXT | Attempting to invoke the functions outside the siren inbox context|
283-
MISSING_PARAMETER | The required parameter is missing |
284250

285251
## Example
286252

@@ -309,7 +275,7 @@ export function MyContainer(): React.JSX.Element {
309275
return (
310276
<div>
311277
<SirenInbox
312-
inboxHeaderProps={
278+
headerProps={
313279
title: "Notifications",
314280
hideHeader: false
315281
}
@@ -318,6 +284,8 @@ export function MyContainer(): React.JSX.Element {
318284
hideDelete: false,
319285
hideAvatar: false,
320286
disableAutoMarkAsRead: false,
287+
deleteIcon: null,
288+
onAvatarClick: () => null,
321289
}}
322290
/>
323291
</div>

example/src/App.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ const App: React.FC = () => {
3737
const [showCustomNotificationCard, setShowCustomNotificationCard] =
3838
useState(false);
3939

40-
const { markNotificationsAsReadByDate } = useSiren();
40+
const { markAsReadByDate } = useSiren();
4141

4242
const renderListEmpty = () => {
4343
return (
@@ -84,7 +84,7 @@ const App: React.FC = () => {
8484
<div style={{ color: "#fff", fontWeight: "600" }}>Siren</div>
8585
</div>
8686
<div>
87-
<div style={{ color: "#fff", fontWeight: "600" }} onClick={() => markNotificationsAsReadByDate(String(new Date().getTime()))}>Mark allAsRead</div>
87+
<div style={{ color: "#fff", fontWeight: "600" }} onClick={() => markAsReadByDate(String(new Date().getTime()))}>Mark allAsRead</div>
8888
</div>
8989
</div>
9090
);
@@ -249,7 +249,7 @@ const App: React.FC = () => {
249249
return (
250250
<div>
251251
<SirenInbox
252-
inboxHeaderProps={{
252+
headerProps={{
253253
title:"Siren Notifications",
254254
hideHeader: hideHeader,
255255
customHeader: showCustomHeader ? renderCustomHeader() : undefined
@@ -261,12 +261,12 @@ const App: React.FC = () => {
261261
listEmptyComponent={
262262
showCustomEmptyComponent ? renderListEmpty() : undefined
263263
}
264-
customNotificationCard={
264+
customCard={
265265
showCustomNotificationCard
266266
? (notification: any) => renderCustomNotificationCard(notification)
267267
: undefined
268268
}
269-
onNotificationCardClick={() => {
269+
onCardClick={() => {
270270
console.log("click on notification");
271271
}}
272272
onError={(error: any) => {

0 commit comments

Comments
 (0)