Skip to content

Commit bc72380

Browse files
refactor: Updated props names
* refactor: Updated props name to meaningful names * refactor: update style props * refactor: updated error codes in readme
1 parent 970af7b commit bc72380

22 files changed

+124
-104
lines changed

README.md

Lines changed: 27 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ Below are optional props available for the icon component:
5151
Prop | Description | Type | Default value |
5252
--- | --- | --- | --- |
5353
theme | Object for custom themes | Theme | {} |
54-
customStyles | Object for custom styling | StyleProps | {} |
54+
customStyles | Object for custom styling | CustomStyleProps | {} |
5555
notificationIcon | Option to use custom notification icon | JSX Element | null |
5656
darkMode | Toggle to enable dark mode | boolean | false |
5757
onError | Callback for handling errors | (error: SirenErrorType)=> void | null |
@@ -80,7 +80,7 @@ Here are the available theme options:
8080
Here are the custom style options for the notification icon:
8181
```js
8282

83-
type StyleProps = {
83+
type CustomStyleProps = {
8484
notificationIcon?: {
8585
size?: number,
8686
};
@@ -109,14 +109,14 @@ Below are optional props available for the inbox component:
109109
Prop | Description | Type | Default value |
110110
--- | --- | --- | --- |
111111
theme | Object for custom themes | Theme | {} |
112-
customStyles | Object for custom styling | StyleProps | {} |
112+
customStyles | Object for custom styling | CustomStyleProps | {} |
113113
darkMode | Toggle to enable dark mode| boolean | false |
114114
itemsPerFetch | Number of notifications fetch per api request (have a max cap of 50) | number | 20 |
115115
cardProps | Props for customizing the notification cards | CardProps | { hideAvatar: false, disableAutoMarkAsRead: false, hideDelete: false } |
116-
customNotificationCard | Function for rendering custom notification cards | (notification)=> JSX Element | null |
117-
onNotificationCardClick | Custom click handler for notification cards | (notification)=> void | ()=>null |
116+
customCard | Function for rendering custom notification cards | (notification)=> JSX Element | null |
117+
onCardClick | Custom click handler for notification cards | (notification)=> void | ()=>null |
118118
listEmptyComponent | Custom component for empty notification list | JSX Element | null |
119-
inboxHeaderProps | Props for customizing the header | InboxHeaderProps | { title: "Notifications", hideHeader: false, hideClearAll: false, customHeader: null, showBackButton:false, backButton: null, onBackPress: ()=> null } |
119+
headerProps | Props for customizing the header | HeaderProps | { title: "Notifications", hideHeader: false, hideClearAll: false, customHeader: null, showBackButton:false, backButton: null, onBackPress: ()=> null } |
120120
customFooter | Custom footer component | JSX Element | null |
121121
customLoader | Custom component to display the initial loading state| JSX Element | null |
122122
customErrorWindow | Custom error window | JSX Element | null |
@@ -170,7 +170,7 @@ Here are the available theme options:
170170
Here are the custom style options for the notification inbox:
171171

172172
```js
173-
type StyleProps = {
173+
type CustomStyleProps = {
174174
notificationIcon?: {
175175
size?: number;
176176
};
@@ -228,9 +228,9 @@ Here are the custom style options for the notification inbox:
228228
};
229229
```
230230

231-
#### InboxHeaderProps
231+
#### HeaderProps
232232
```js
233-
type InboxHeaderProps = {
233+
type HeaderProps = {
234234
title?: string;
235235
hideHeader?: boolean;
236236
hideClearAll?: boolean;
@@ -249,14 +249,14 @@ Here are the custom style options for the notification inbox:
249249
import { useSiren } from '@sirenapp/react-native-inbox';
250250

251251
function MyComponent() {
252-
const { markAsRead, deleteNotification } = useSiren();
252+
const { markAsRead, deleteById } = useSiren();
253253

254254
function handleMarkAsRead(id) {
255255
markAsRead(id);
256256
}
257257

258258
function handleDeleteNotification(id) {
259-
deleteNotification(id);
259+
deleteById(id);
260260
}
261261

262262
return (
@@ -268,23 +268,32 @@ function MyComponent() {
268268

269269
Functions | Parameters | Type | Description |
270270
----------|------------|-------|------------|
271-
markNotificationsAsReadByDate | startDate | ISO date string | Sets the read status of notifications to true until the given date |
271+
markAsReadByDate | startDate | ISO date string | Sets the read status of notifications to true until the given date |
272272
markAsRead | id | string | Set read status of a notification to true |
273-
deleteNotification | id | string | Delete a notification by id |
274-
deleteNotificationsByDate | startDate | ISO date string | Delete all notifications until given date |
275-
markNotificationsAsViewed | startDate | ISO date string |Sets the viewed status of notifications to true until the given date |
273+
deleteById | id | string | Delete a notification by id |
274+
deleteByDate | startDate | ISO date string | Delete all notifications until given date |
275+
markAllAsViewed | startDate | ISO date string |Sets the viewed status of notifications to true until the given date |
276276

277277
## 4. Error codes
278278
Given below are all possible error codes thrown by sdk:
279279

280280
Error code | Description |
281281
--- | --- |
282-
INVALID_TOKEN | The token passed in the provider is invalid |
283-
INVALID_RECIPIENT_ID | The recipient id passed in the provider is invalid |
282+
AUTHENTICATION_FAILED | Failed to authenticate given credentials |
284283
TOKEN_VERIFICATION_FAILED | Verification of the given tokens has failed |
285-
GENERIC_API_ERROR | Occurrence of an unexpected api error |
284+
TOKEN_VERIFICATION_PENDING | Authentication in progress |
285+
API_ERROR | Occurrence of an unexpected api error |
286+
UNVIEWED_COUNT_FETCH_FAILED | Failed to fetch unviewed notifications count |
287+
NOTIFICATION_FETCH_FAILED | Failed to fetch notifications |
288+
DELETE_FAILED | Failed to delete notification |
289+
MARK_AS_READ_FAILED | Failed to mark notification as read |
290+
BULK_DELETE_FAILED | Bulk deletion of notifications failed |
291+
MARK_ALL_AS_READ_FAILED | Failed to mark all notifications as read |
292+
MARK_ALL_AS_VIEWED_FAILED | Failed to mark notification as viewed |
286293
OUTSIDE_SIREN_CONTEXT | Attempting to invoke the functions outside the siren inbox context |
287294
MISSING_PARAMETER | The required parameter is missing |
295+
UNAUTHORIZED_OPERATION | This operation require valid credentials |
296+
INVALID_ERROR_FUNCTION | The error function passed to sdk is invalid |
288297

289298
## Example
290299
Here's a basic example to help you get started

example/screens/notifications.tsx

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ function Notifications(): React.JSX.Element {
5252
backgroundColor: isDarkMode ? '#000' : '#FFF'
5353
};
5454

55-
const { markNotificationsAsReadByDate } = useSiren();
55+
const { markAsReadByDate } = useSiren();
5656

5757
const renderListEmpty = () => {
5858
return (
@@ -76,7 +76,9 @@ function Notifications(): React.JSX.Element {
7676
<TouchableOpacity onPress={() => navigation.goBack()}>
7777
<Text style={styles.whiteLabel}>Back</Text>
7878
</TouchableOpacity>
79-
<TouchableOpacity onPress={() => markNotificationsAsReadByDate(String(new Date().getTime()))}>
79+
<TouchableOpacity
80+
onPress={() => markAsReadByDate(String(new Date().getTime()))}
81+
>
8082
<Text style={styles.whiteLabel}>Mark allAsRead</Text>
8183
</TouchableOpacity>
8284
</View>
@@ -108,12 +110,9 @@ function Notifications(): React.JSX.Element {
108110
</View>
109111
{showTestingWindow && (
110112
<View style={styles.testingWindowInnerContainer}>
111-
{renderButton(
112-
`${showNetwork ? 'Hide' : 'Show'} network`,
113-
() => {
114-
setShowNetwork((showNetwork) => !showNetwork);
115-
}
116-
)}
113+
{renderButton(`${showNetwork ? 'Hide' : 'Show'} network`, () => {
114+
setShowNetwork((showNetwork) => !showNetwork);
115+
})}
117116
{renderButton('Theme-Mode', () =>
118117
setSdkDarkModeEnabled((sdkDarkModeEnabled) => !sdkDarkModeEnabled)
119118
)}
@@ -163,29 +162,34 @@ function Notifications(): React.JSX.Element {
163162
/>
164163
<View style={styles.contentContainer}>
165164
<SirenInbox
166-
inboxHeaderProps={{
165+
headerProps={{
167166
hideHeader: hideHeader,
168167
customHeader: showCustomHeader ? renderCustomHeader() : undefined,
169168
showBackButton: true,
170169
onBackPress: () => navigation.goBack(),
171-
title: 'Siren Inbox',
170+
title: 'Siren Inbox'
172171
}}
173172
darkMode={sdkDarkModeEnabled}
174-
cardProps={{ hideAvatar: hideAvatar, disableAutoMarkAsRead: false, onAvatarClick: (notification: NotificationDataType) => console.log('avatar click', notification) }}
173+
cardProps={{
174+
hideAvatar: hideAvatar,
175+
disableAutoMarkAsRead: false,
176+
onAvatarClick: (notification: NotificationDataType) =>
177+
console.log('avatar click', notification)
178+
}}
175179
theme={windowThemes[windowThemeIndex]}
176180
customFooter={showCustomFooter ? renderCustomFooter() : undefined}
177181
listEmptyComponent={showCustomEmptyComponent ? renderListEmpty() : undefined}
178182
customStyles={{
179183
notificationCard: {
180-
avatarSize: 30,
184+
avatarSize: 30
181185
}
182186
}}
183-
customNotificationCard={
187+
customCard={
184188
showCustomNotificationCard
185189
? (notification: NotificationDataType) => renderCustomNotificationCard(notification)
186190
: undefined
187191
}
188-
onNotificationCardClick={(notification: NotificationDataType) => {
192+
onCardClick={(notification: NotificationDataType) => {
189193
console.log('click on notification');
190194
}}
191195
onError={(error: SirenErrorType) => {

src/components/backIcon.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import React, { type ReactElement } from 'react';
22
import { StyleSheet, View } from 'react-native';
33

4-
import type { SirenStyleProps } from '../types';
4+
import type { StyleProps } from '../types';
55

6-
const BackIcon = ({ styles }: { styles: Partial<SirenStyleProps> }): ReactElement => {
6+
const BackIcon = ({ styles }: { styles: Partial<StyleProps> }): ReactElement => {
77
return (
88
<View style={style.backIconContainer}>
99
<View style={[style.backIconLine1, styles.backIcon]} />

src/components/clearIcon.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import React, { type ReactElement } from 'react';
22
import { StyleSheet, View } from 'react-native';
33

4-
import type { SirenStyleProps } from '../types';
4+
import type { StyleProps } from '../types';
55

6-
const ClearIcon = ({ styles }: { styles: Partial<SirenStyleProps> }): ReactElement => {
6+
const ClearIcon = ({ styles }: { styles: Partial<StyleProps> }): ReactElement => {
77
const icon: JSX.Element[] = [];
88

99
for (let i = 0; i < 3; i++)

src/components/closeIcon.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@ import { StyleSheet, TouchableOpacity, View } from 'react-native';
33

44
import type { NotificationDataType } from '@sirenapp/js-sdk/dist/esm/types';
55

6-
import type { SirenStyleProps } from '../types';
6+
import type { StyleProps } from '../types';
77

88
const CloseIcon = ({
99
notification,
1010
styles,
1111
onDelete
1212
}: {
1313
notification: NotificationDataType;
14-
styles: Partial<SirenStyleProps>;
14+
styles: Partial<StyleProps>;
1515
onDelete: (id: string) => void;
1616
}): ReactElement => {
1717
const icon: JSX.Element[] = [];

src/components/emptyWindow.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React, { type ReactElement } from 'react';
22
import { StyleSheet, Text, View, Image } from 'react-native';
33

4-
import type { SirenStyleProps } from '../types';
4+
import type { StyleProps } from '../types';
55
import { Constants } from '../utils';
66

77
const { LIST_EMPTY_TEXT, LIST_EMPTY_DESCRIPTION } = Constants;
@@ -18,7 +18,7 @@ const { LIST_EMPTY_TEXT, LIST_EMPTY_DESCRIPTION } = Constants;
1818
* @param {Object} props.styles - Custom styles applied to the empty window.
1919
*/
2020
const EmptyWindow = (props: {
21-
styles: Partial<SirenStyleProps>;
21+
styles: Partial<StyleProps>;
2222
darkMode: boolean;
2323
}): ReactElement => {
2424
const { styles, darkMode } = props;

src/components/errorWindow.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React, { type ReactElement } from 'react';
22
import { StyleSheet, Text, Image, View } from 'react-native';
33

4-
import type { SirenStyleProps } from '../types';
4+
import type { StyleProps } from '../types';
55
import { Constants } from '../utils';
66
import { ERROR_DESCRIPTION } from '../utils/constants';
77

@@ -21,7 +21,7 @@ const { ERROR_TEXT } = Constants;
2121
* @param {Function} props.onRetry - A callback function that is invoked when the user presses the refresh button.
2222
*/
2323
const ErrorWindow = (props: {
24-
styles: Partial<SirenStyleProps>;
24+
styles: Partial<StyleProps>;
2525
darkMode: boolean;
2626
customErrorWindow?: JSX.Element | null;
2727
}): ReactElement => {

src/components/header.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React, { type ReactElement } from 'react';
22
import { StyleSheet, Text, TouchableOpacity, View } from 'react-native';
33

4-
import type { SirenStyleProps } from '../types';
4+
import type { StyleProps } from '../types';
55
import { Constants } from '../utils';
66
import ClearIcon from './clearIcon';
77
import BackIcon from './backIcon';
@@ -30,7 +30,7 @@ import BackIcon from './backIcon';
3030

3131
type HeaderProps = {
3232
title: string;
33-
styles: Partial<SirenStyleProps>;
33+
styles: Partial<StyleProps>;
3434
onPressClearAll: () => void;
3535
clearAllDisabled: boolean;
3636
hideClearAll?: boolean;

src/components/loadingWindow.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import React, { useEffect, type ReactElement, useRef } from 'react';
22
import { Animated, Easing, FlatList, StyleSheet, View } from 'react-native';
33

4-
import type { SirenStyleProps } from '../types';
4+
import type { StyleProps } from '../types';
55

66
type LoadingWindowProps = {
7-
styles: Partial<SirenStyleProps>;
7+
styles: Partial<StyleProps>;
88
customLoader?: JSX.Element | null;
99
hideAvatar?: boolean;
1010
hideDelete?: boolean;

src/components/sirenInbox.tsx

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -59,12 +59,12 @@ type NotificationFetchParams = {
5959
* @param {boolean} [props.darkMode=false] - Flag to enable dark mode.
6060
* @param {Object} [props.cardProps={ hideAvatar: false, showMedia: true }] - Props for customizing the notification cards.
6161
* @param {JSX.Element} [props.listEmptyComponent=null] - Custom component to display when the notification list is empty.
62-
* @param {CardProps} [props.inboxHeaderProps] - Object containing props related to the inbox header
62+
* @param {CardProps} [props.headerProps] - Object containing props related to the inbox header
6363
* @param {JSX.Element} [props.customFooter=null] - Custom footer component.
6464
* @param {JSX.Element} [props.customLoader=null] - Custom loader component.
6565
* @param {JSX.Element} [props.customErrorWindow=null] - Custom error component.
66-
* @param {Function} [props.customNotificationCard=null] - Custom function for rendering notification cards.
67-
* @param {Function} [props.onNotificationCardClick=() => null] - Callback for handling notification card clicks.
66+
* @param {Function} [props.customCard=null] - Custom function for rendering notification cards.
67+
* @param {Function} [props.onCardClick=() => null] - Callback for handling notification card clicks.
6868
* @param {Function} [props.onError] - Callback for handling errors.
6969
*/
7070
const SirenInbox = (props: SirenInboxProps): ReactElement => {
@@ -78,12 +78,12 @@ const SirenInbox = (props: SirenInboxProps): ReactElement => {
7878
hideDelete: false
7979
},
8080
listEmptyComponent = null,
81-
inboxHeaderProps = {},
81+
headerProps = {},
8282
customFooter = null,
8383
customLoader = null,
8484
customErrorWindow = null,
85-
customNotificationCard = null,
86-
onNotificationCardClick = () => null,
85+
customCard = null,
86+
onCardClick = () => null,
8787
onError = () => {},
8888
itemsPerFetch = 20
8989
} = props;
@@ -96,15 +96,15 @@ const SirenInbox = (props: SirenInboxProps): ReactElement => {
9696
showBackButton,
9797
backButton,
9898
onBackPress
99-
} = inboxHeaderProps;
99+
} = headerProps;
100100
const notificationsPerPage = Math.max(
101101
0,
102102
itemsPerFetch > MAXIMUM_ITEMS_PER_FETCH ? MAXIMUM_ITEMS_PER_FETCH : itemsPerFetch
103103
);
104104

105105
const { siren, verificationStatus } = useSirenContext();
106106

107-
const { deleteNotification, deleteNotificationsByDate, markNotificationsAsViewed } = useSiren();
107+
const { deleteById, deleteByDate, markAllAsViewed } = useSiren();
108108

109109
const [notifications, setNotifications] = useState<NotificationDataType[]>([]);
110110
const [isLoading, setIsLoading] = useState<boolean>(true);
@@ -145,7 +145,7 @@ const SirenInbox = (props: SirenInboxProps): ReactElement => {
145145
const handleMarkNotificationsAsViewed = async (newNotifications = notifications) => {
146146
const currentTimestamp = new Date().getTime();
147147
const isoString = new Date(currentTimestamp).toISOString();
148-
const response = await markNotificationsAsViewed(
148+
const response = await markAllAsViewed(
149149
isNonEmptyArray(newNotifications) ? newNotifications[0].createdAt : isoString
150150
);
151151

@@ -319,7 +319,7 @@ const SirenInbox = (props: SirenInboxProps): ReactElement => {
319319
if (!disableCardDelete.current) {
320320
disableCardDelete.current = true;
321321

322-
const response = await deleteNotification(id, shouldUpdateList);
322+
const response = await deleteById(id, shouldUpdateList);
323323

324324
if (response?.data) isSuccess = true;
325325
processError(response?.error);
@@ -331,7 +331,7 @@ const SirenInbox = (props: SirenInboxProps): ReactElement => {
331331

332332
const onPressClearAll = async (): Promise<void> => {
333333
if (isNonEmptyArray(notifications)) {
334-
const response = await deleteNotificationsByDate(notifications[0].createdAt);
334+
const response = await deleteByDate(notifications[0].createdAt);
335335

336336
if (response?.error) {
337337
processError(response?.error);
@@ -346,7 +346,7 @@ const SirenInbox = (props: SirenInboxProps): ReactElement => {
346346
const renderDefaultNotificationCard = (item: NotificationDataType) => {
347347
return (
348348
<Card
349-
onCardClick={onNotificationCardClick}
349+
onCardClick={onCardClick}
350350
notification={item}
351351
cardProps={cardProps}
352352
styles={styles}
@@ -358,7 +358,7 @@ const SirenInbox = (props: SirenInboxProps): ReactElement => {
358358

359359
// Render notification card
360360
const renderCard = ({ item }: { item: NotificationDataType }): JSX.Element => {
361-
if (customNotificationCard) return customNotificationCard(item);
361+
if (customCard) return customCard(item);
362362

363363
return renderDefaultNotificationCard(item);
364364
};

0 commit comments

Comments
 (0)