1.0.0 • Published 2 months ago

test_notification-react v1.0.0

Weekly downloads
-
License
MIT
Repository
github
Last release
2 months ago

Siren React Inbox

Table of Contents

Overview

The @siren/react-inbox sdk is a comprehensive and customizable React UI kit for displaying and managing notifications. This documentation provides comprehensive information on how to install, configure, and use the sdk effectively.

Quick Start Guide

1. Install SDK

To install the @siren/react-inbox sdk, you can use npm or yarn.

Prerequisites

  • React v16.8+

Steps

  1. Under your app's root directory, install @siren/react-inbox.
npm install @siren/react-inbox
  1. Under your application's folder, run
pod install

2. Siren Provider

The SirenProvider initializes the Siren sdk with the specified configuration, which contains important parameters like the user token and recipient ID. Wrap the SirenProvider around your App's root.

import { SirenProvider } from '@siren/react-inbox';

const config = {
  userToken: 'your_user_token',
  recipientId: 'your_recipient_id',
};

<SirenProvider config={config}>
  {/* Your app components */}
</SirenProvider>

The config is a prop for the SirenProvider component is authenticate and initialize sdk.

type config = {
  userToken: string,
  recipientId:  string,
};

3. Siren Window

SirenWindow is a paginated list view with notification Icon for displaying notifications.

import { SirenWindow } from '@siren/react-inbox';

<SirenWindow
    theme={customTheme}
    title="Notifications"
    windowViewOnly={false}
    hideHeader={false}
    darkMode={true}
    notificationsPerPage={10}
    realTimeNotificationEnabled={true}
    realTimeUnViewedCountEnabled={true}
    onError={(error) => console.log(error)}
/>

Siren Window Props

Given below are all props of window component.

PropDescriptionTypeDefault value
themeTheme object for custom stylingTheme{}
titleTitle of the notification windowstring"Notifications"
hideHeaderFlag to hide or show the headerbooleanfalse
darkModeFlag to enable dark modebooleanfalse
windowViewOnlyFlag to enable window viewbooleanfalse
notificationIconOption to use custom notification IconJSX Elementnull
realTimeNotificationEnabledSwitch for on and of notification listenerbooleanfalse
realTimeUnViewedCountEnabledFlag to enable real-time un-viewed notification countbooleanfalse
notificationsPerPageNumber of notifications to fetch per pagenumber10
cardPropsProps for customizing the notification cardsCardPropsnull
customNotificationCardCustom function for rendering notification cards(notification)=> JSX Elementnull
onNotificationCardClickProps for customizing the notification cards(notification)=> void()=>null
listEmptyComponentCustom component to display when the notification list is emptyJSX Elementnull
customHeaderCustom header componentJSX Elementnull
customFooterCustom footer componentJSX Elementnull
onErrorCallback for handling errors(error: SirenErrorType)=> voidnull

Theming options

Customizable UI option for notification window, with dark and light theme options.

    type Theme = {
        dark: ThemeProps;
        light: ThemeProps;
    };

    type ThemeProps = {
        unreadBadgeCount?: {
            background?: string;
            color?: string;
            borderRadius?: number;
            fontSize?: number;
            inset?: number;
            size?: number;
        };
        badgeStyle?: {
            size?: number;
            color?: string;
            textColor?: string;
            textSize?: number;
        };
        colors?: {
            primaryColor?: string;
            secondaryColor?: string;
            textColor?: string;
            neutralColor?: string;
            borderColor?: string;
            primaryTextColor?: string;
            activeCardColor?: string;
        };
        window?: {
            width?: DimensionValue;
            height?: DimensionValue;
            borderColor?: string;
            borderRadius?: number;
            shadowDepth?: number;
            shadowColor?: string;
        };
        windowHeader?: {
            background?: string;
            height?: DimensionValue;
            titleColor?: string;
            titleFontWeight?: TextStyle['fontWeight'];
            titleSize?: number;
            closeIconColor?: string;
            closeIconSize?: number;
        };
        windowContainer?: {
            background?: string;
            padding?: number;
        };
        notificationCard?: {
            height?: DimensionValue;
            padding?: number;
            borderWidth?: number;
            borderColor?: string;
            background?: string;
            hoverBackground?: string;
            avatarSize?: number;
            titleColor?: string;
            titleFontWeight?: TextStyle['fontWeight'];
            titleSize?: number;
            titlePadding?: number;
            descriptionColor?: string;
            descriptionSize?: number;
            descriptionPadding?: number;
            mediaWidth?: DimensionValue;
            mediaHeight?: DimensionValue;
            mediaObjectFit?: string;
            mediaRadius?: number;
            mediaPlaceholder?: string;
            dateColor?: string;
            dateSize?: number;
        };
    }

4. useSiren

This is a hook that provides utility functions for modifying notifications.

import { useSiren } from '@siren/react-inbox';

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

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

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

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

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

  function handleMarkNotificationsAsViewed(untilDate){
    markNotificationsAsViewed(untilDate)
  }
  
  return (
    {/* Your component logic */}
  );
}

useSiren functions

Function nameParameters typeDescription
markAllNotificationsAsReadByDatestartDate: stringSet all notification read status to true until given date
markAsReadid: stringSet read status of a specific notification to true
deleteNotificationid: stringDelete a specific notification by id
clearAllNotificationByDatestartDate: stringDelete all notifications until given date
markNotificationsAsViewedstartDate: stringSet all notification viewed status to true until given date

5. Error codes

Given below are all possible error codes thrown by sdk.

Error codeMessageDescription
INVALID_TOKENInvalid tokenToken passed in provider is invalid
INVALID_RECIPIENT_IDInvalid recipient idRecipient id in provider is invalid
TOKEN_VERIFICATION_FAILEDThis operation requires a valid tokenFailed to verify token and initialize sdk
INVALID_ERROR_FUNCTIONInvalid error functionError function is invalid
GENERIC_API_ERRORApi errorFailed to call a internal api
SIREN_OBJECT_NOT_FOUNDSiren Object Not foundWas failed to initialize sdk, Siren object not created
MISSING_PARAMETERMissing ParameterA parameter is missing in function call

Complete Code Example

Here's a runnable code example that covers everything in this quick start guide.

import React from 'react';
import {SafeAreaView} from 'react';
import {SirenWindow,SirenProvider} from '@siren/react-inbox';

function App(): React.JSX.Element {

  const config = {
    userToken: 'your_user_token',
    recipientId: 'your_recipient_id',
  };

  return (
    <SirenProvider config={config}>
      <MyContainer />
    </SirenProvider>
  );
}

export default App;

function MyContainer(): React.JSX.Element {

  return (
    <SafeAreaView style={{flex: 1}}>
      <SirenWindow
        title="Notifications"
        hideHeader={false}
        darkMode={false}
        cardProps={{hideAvatar: false, showMedia: true}}
      />
    </SafeAreaView>
  );
}

export default MyContainer;

I want to know more!

No worries, here are some links that you will find useful:

1.0.0

2 months ago