Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
7bf1fa4
feat: Add animation on notification delete
reshmarevi17 Apr 11, 2024
ef032e7
feat: Add avatar click functionality
reshmarevi17 Apr 11, 2024
cd2458a
fix: Circular dependency warning
reshmarevi17 Apr 22, 2024
f2ddc0e
refactor: performance optimizations
reshmarevi17 Apr 22, 2024
1036cf9
fix: Update customStyle props
reshmarevi17 Apr 22, 2024
3ed521f
feat: Add custom delete icon in card props
reshmarevi17 Apr 22, 2024
c2b9b8d
feat: Add stories for components
reshmarevi17 Apr 22, 2024
2d73cbd
fix: Update modal position calculation by changing from window.outer…
reshmarevi17 Apr 22, 2024
adb9294
feat: Add aria-label property to enhance accessibility for interacti…
reshmarevi17 Apr 22, 2024
d44be17
refactor: Update custom style prop
reshmarevi17 Apr 22, 2024
5e855f4
fix: Style fixes
reshmarevi17 May 2, 2024
0af3aab
refactor: Update prop and function names, and modify the logic for r…
reshmarevi17 May 7, 2024
487152f
fix: Terminate retry verification api trigger if config changes while…
reshmarevi17 May 9, 2024
75650ce
fix: Trigger delete animation after delete API success
reshmarevi17 May 9, 2024
95a7ca0
feat: Add media support in notification card
reshmarevi17 May 9, 2024
edb2340
fix: Adjust modal height in window view to occupy entire screen height
reshmarevi17 May 10, 2024
eba465f
fix: Add unique identifier for PubSub events in SirenProvider
reshmarevi17 May 14, 2024
5d5f585
refactor: Code refactor and optimisation
reshmarevi17 May 15, 2024
56af9b6
feat: Update changelog and SDK version in the example app
reshmarevi17 May 15, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module.exports = {
browser: true,
es2021: true
},
extends: ['eslint:recommended', 'plugin:@typescript-eslint/recommended'],
extends: ['eslint:recommended', 'plugin:@typescript-eslint/recommended', 'plugin:storybook/recommended'],
overrides: [
{
env: {
Expand Down
23 changes: 23 additions & 0 deletions .storybook/main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import type { StorybookConfig } from "@storybook/react-webpack5";

const config: StorybookConfig = {
stories: ["../stories/**/*.mdx", "../stories/**/*.stories.@(js|jsx|mjs|ts|tsx)"],
addons: [
"@storybook/addon-links",
"@storybook/addon-essentials",
"@storybook/addon-onboarding",
"@storybook/addon-interactions",
],
framework: {
name: "@storybook/react-webpack5",
options: {
builder: {
useSWC: true,
},
},
},
docs: {
autodocs: "tag",
},
};
export default config;
15 changes: 15 additions & 0 deletions .storybook/preview.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import type { Preview } from "@storybook/react";

const preview: Preview = {
parameters: {
actions: { argTypesRegex: "^on[A-Z].*" },
controls: {
matchers: {
color: /(background|color)$/i,
date: /Date$/i,
},
},
},
};

export default preview;
10 changes: 7 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,12 @@

All notable changes to this project will be documented in this file.

## [0.0.1] - 2024-03-26
## 1.1.0
This is an update to the package.

### Added

- React UI kit for managing and displaying in-app notification
- Added support for custom delete icon and a flag to toggle the visibility of the delete icon.
- Added functionality to display thumbnail URL previews for media content
- Exposed Avatar click property.
- Implemented specific error code mapping.
- Enhanced style and theme customizations.
97 changes: 35 additions & 62 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,16 +58,17 @@ Below are optional props available for the inbox component:
Prop | Description | Type | Default value |
--- | --- | --- | --- |
theme | Object for custom themes | Theme | {} |
customStyles | Object for custom styling | CustomStyle | {} |
loadMoreLabel | Text shown on the load more component | string | "Load More" |
hideBadge | Toggle to hide or show the badge | boolean | false |
darkMode | Toggle to enable dark mode | boolean | false |
itemsPerFetch | Number of notifications fetch per api request (have a max cap of 50) | number | 20 |
windowViewOnly | Toggle to enable fit-to-screen window or modal view | boolean | false |
notificationIcon | Option to use custom notification Icon | JSX Element | null |
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 } |
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 | CardProps | { hideDelete: false,<br> hideAvatar: false,<br> disableAutoMarkAsRead: false } |
customNotificationCard | Function for rendering custom notification cards | (notification)=> JSX Element | null |
onNotificationCardClick | Custom click handler for notification cards | (notification)=> void | ()=>null |
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 } |
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> hideMediaThumbnail - Toggle to hide or show thumbnail image<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 <br> onMediaThumbnailClick - Custom click handler for media thumbnail | CardProps | { hideDelete: false,<br> hideAvatar: false,<br> disableAutoMarkAsRead: false, <br> hideMediaThumbnail: false, <br>deleteIcon: null, <br> onAvatarClick: ()=>null,<br> onMediaThumbnailClick: () => null } |
customCard | Function for rendering custom notification cards | (notification)=> JSX Element | null |
onCardClick | Custom click handler for notification cards | (notification)=> void | ()=>null |
listEmptyComponent | Custom component for empty notification list | JSX Element | null |
customFooter | Custom footer component | JSX Element | null |
customLoader | Custom loader component | JSX Element | null |
Expand All @@ -88,9 +89,6 @@ type Theme = {
};

type ThemeProps = {
notificationIcon?: {
size?: number,
},
colors?: {
primaryColor?: string,
textColor?: string,
Expand All @@ -108,25 +106,22 @@ type ThemeProps = {
color?: string,
textColor?: string,
},
window?: {
borderColor?: string,
},
windowHeader?: {
background?: string,
titleColor?: string,
headerActionColor?: string,
borderColor?: string,
},
windowContainer?: {
background?: string,
},
notificationCard?: {
customCard?: {
borderColor?: string,
background?: string,
titleColor?: string,
subtitleColor?: string,
descriptionColor?: string,
},
loadMoreButton: {
loadMoreButton?: {
color?: string,
background?: string,
},
Expand All @@ -153,17 +148,21 @@ Please note that the badgeStyle, window shadow and border props are only applica
titleFontWeight?:TextStyle["fontWeight"],
titleSize?: number,
titlePadding?: number,
borderWidth?: string,
},
windowContainer?: {
padding?: number,
contentHeight?: DimensionValue,
},
notificationCard?: {
customCard?: {
padding?: number,
borderWidth?: number,
avatarSize?: number,
titleFontWeight?: TextStyle["fontWeight"],
titleSize?: number,
subtitleFontWeight?: TextStyle['fontWeight'],
subtitleSize?: number,
descriptionFontWeight?: TextStyle['fontWeight'],
descriptionSize?: number,
dateSize?: number,
},
Expand All @@ -174,36 +173,40 @@ Please note that the badgeStyle, window shadow and border props are only applica
badgeStyle?: {
size?: number,
textSize?: number,
top?: number;
left?: number
top?: number,
right?: number
},
deleteIcon?:{
size?: number
}
dateIcon?:{
},
timerIcon?:{
size?: number
}
},
clearAllIcon?:{
size?: number
}
},
}
```

#### CardProps

```js
type CardProps = {
hideDelete?: boolean;
hideDelete?: boolean,
hideAvatar?: boolean,
hideMediaThumbnail?: boolean,
disableAutoMarkAsRead?: boolean,
deleteIcon?: JSX.Element,
onAvatarClick?: () => void,
onMediaThumbnailClick?: () => void,
};
```

#### InboxHeaderProps

```js
type InboxHeaderProps = {
title?: string;
title?: string,
hideHeader?: boolean,
hideClearAll?: boolean,
customHeader?: JSX.Element | null,
Expand All @@ -219,31 +222,11 @@ import { useSiren } from "@sirenapp/react-inbox";

function MyComponent() {
const {
markAsRead,
deleteNotification,
markAllNotificationsAsReadByDate,
clearAllNotificationByDate,
markNotificationsAsViewed,
markAsReadById,
} = useSiren();

function handleMarkAsRead(id) {
markAsRead(id);
}

function handleDeleteNotification(id) {
deleteNotification(id);
}

function handleMarkAllNotificationsAsReadByDate(untilDate) {
markNotificationsAsReadByDate(untilDate);
}

function handleClearAllNotificationByDate(untilDate) {
deleteNotificationsByDate(untilDate);
}

function handleMarkNotificationsAsViewed(untilDate) {
markNotificationsAsViewed(untilDate);
markAsReadById(id);
}

return {
Expand All @@ -256,24 +239,12 @@ function MyComponent() {

Functions | Parameters | Type | Description |
----------|------------|-------|------------|
markNotificationsAsReadByDate | startDate | ISO date string | Sets the read status of notifications to true until the given date |
markAsRead | id | string | Set read status of a notification to true |
deleteNotification | id | string | Delete a notification by id |
deleteNotificationsByDate | startDate | ISO date string | Delete all notifications until given date |
markNotificationsAsViewed | startDate | ISO date string |Sets the viewed status of notifications to true until the given date |

## 5. Error codes

Given below are all possible error codes thrown by sdk.
markAsReadByDate | startDate | ISO date string | Sets the read status of notifications to true until the given date |
markAsReadById | id | string | Set read status of a notification to true |
deleteById | id | string | Delete a notification by id |
deleteByDate | startDate | ISO date string | Delete all notifications until given date |
markAllAsViewed | startDate | ISO date string |Sets the viewed status of notifications to true until the given date |

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

## Example

Expand Down Expand Up @@ -302,7 +273,7 @@ export function MyContainer(): React.JSX.Element {
return (
<div>
<SirenInbox
inboxHeaderProps={
headerProps={
title: "Notifications",
hideHeader: false
}
Expand All @@ -311,6 +282,8 @@ export function MyContainer(): React.JSX.Element {
hideDelete: false,
hideAvatar: false,
disableAutoMarkAsRead: false,
deleteIcon: null,
onAvatarClick: () => null,
}}
/>
</div>
Expand Down
2 changes: 1 addition & 1 deletion example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-scripts": "^5.0.1",
"@sirenapp/react-inbox": "^1.0.0"
"@sirenapp/react-inbox": "^1.1.0"
},
"scripts": {
"dev": "PORT=9902 react-scripts start",
Expand Down
12 changes: 6 additions & 6 deletions example/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ const App: React.FC = () => {
const [showCustomNotificationCard, setShowCustomNotificationCard] =
useState(false);

const { markNotificationsAsReadByDate } = useSiren();
const { markAsReadByDate } = useSiren();

const renderListEmpty = () => {
return (
Expand Down Expand Up @@ -84,7 +84,7 @@ const App: React.FC = () => {
<div style={{ color: "#fff", fontWeight: "600" }}>Siren</div>
</div>
<div>
<div style={{ color: "#fff", fontWeight: "600" }} onClick={() => markNotificationsAsReadByDate(String(new Date().getTime()))}>Mark allAsRead</div>
<div style={{ color: "#fff", fontWeight: "600" }} onClick={() => markAsReadByDate(String(new Date().getTime()))}>Mark allAsRead</div>
</div>
</div>
);
Expand Down Expand Up @@ -249,24 +249,24 @@ const App: React.FC = () => {
return (
<div>
<SirenInbox
inboxHeaderProps={{
headerProps={{
title:"Siren Notifications",
hideHeader: hideHeader,
customHeader: showCustomHeader ? renderCustomHeader() : undefined
}}
darkMode={sdkDarkModeEnabled}
cardProps={{ hideAvatar: hideAvatar, showMedia: true }}
cardProps={{ hideAvatar: hideAvatar, onAvatarClick: () => console.log('avatar click') }}
theme={windowThemes[windowThemeIndex]}
customFooter={showCustomFooter ? renderCustomFooter() : undefined}
listEmptyComponent={
showCustomEmptyComponent ? renderListEmpty() : undefined
}
customNotificationCard={
customCard={
showCustomNotificationCard
? (notification: any) => renderCustomNotificationCard(notification)
: undefined
}
onNotificationCardClick={() => {
onCardClick={() => {
console.log("click on notification");
}}
onError={(error: any) => {
Expand Down
Loading