@@ -6,7 +6,7 @@ import type {
66 NotificationDataType ,
77 NotificationsApiResponse ,
88 SirenErrorType ,
9- } from "@sirenapp/js-sdk /dist/esm/types" ;
9+ } from "test_notification /dist/esm/types" ;
1010
1111import "../styles/sirenPanel.css" ;
1212import NotificationCard from "./Card" ;
@@ -16,6 +16,7 @@ import Header from "./Header";
1616import AnimatedLoader from "./Loader" ;
1717import ShowMoreButton from "./ShowMore" ;
1818import { useSirenContext } from "./SirenProvider" ;
19+ import Tab from "./Tab" ;
1920import type { EventListenerDataType , SirenPanelProps } from "../types" ;
2021import {
2122 filterDataProperty ,
@@ -27,7 +28,7 @@ import {
2728 mergeStyles ,
2829 updateNotifications ,
2930} from "../utils/commonUtils" ;
30- import { DEFAULT_WINDOW_TITLE , ERROR_TEXT , errorMap , events , EventType , eventTypes , VerificationStatus } from "../utils/constants" ;
31+ import { DEFAULT_WINDOW_TITLE , ERROR_TEXT , errorMap , events , EventType , eventTypes , LIST_EMPTY_TEXT , Tabs , UNREAD_LIST_EMPTY_TEXT , VerificationStatus } from "../utils/constants" ;
3132import useSiren from "../utils/sirenHook" ;
3233
3334/**
@@ -87,6 +88,14 @@ const SirenPanel: FC<SirenPanelProps> = ({
8788 onCardClick,
8889 onError,
8990 modalWidth,
91+ hideTab = false ,
92+ tabProps = {
93+ tabs : [
94+ { key : Tabs . ALL , title : 'All' } ,
95+ { key : Tabs . UNREAD , title : 'Unread' }
96+ ] ,
97+ activeTab : 0
98+ }
9099} ) => {
91100 const {
92101 markAllAsViewed,
@@ -98,7 +107,8 @@ const SirenPanel: FC<SirenPanelProps> = ({
98107 const [ notifications , setNotifications ] = useState < NotificationDataType [ ] > (
99108 [ ]
100109 ) ;
101-
110+ const [ activeTabIndex , setActiveTabIndex ] = useState ( 0 ) ;
111+ const [ filterType , setFilterType ] = useState < string > ( tabProps . tabs [ tabProps . activeTab ] . key ) ;
102112 const [ error , setError ] = useState < string > ( "" ) ;
103113 const [ isLoading , setIsLoading ] = useState ( true ) ;
104114 const [ endReached , setEndReached ] = useState ( false ) ;
@@ -154,7 +164,7 @@ const SirenPanel: FC<SirenPanelProps> = ({
154164 else if ( verificationStatus === VerificationStatus . FAILED ) {
155165 handleVerificationFailure ( ) ;
156166 }
157- } , [ siren , verificationStatus , hideBadge ] ) ;
167+ } , [ siren , verificationStatus , hideBadge , activeTabIndex ] ) ;
158168
159169 const restartNotificationCountFetch = ( ) => {
160170 try {
@@ -183,17 +193,27 @@ const SirenPanel: FC<SirenPanelProps> = ({
183193 setError ( "" ) ;
184194 } ;
185195
186- const handleClearAllNotification = async ( ) : Promise < void > => {
196+ const handleClearAllNotification = async ( ) : Promise < void > => {
187197 try {
188198 if ( ! isEmptyArray ( notifications ) ) {
199+ let params ;
200+ const startDate = notifications [ 0 ] . createdAt ;
201+
202+ if ( filterType === Tabs . UNREAD )
203+ params = { startDate, isRead : false } ;
204+ else
205+ params = { startDate } ;
206+
207+
189208 const response = await deleteByDate (
190- notifications [ 0 ] . createdAt
209+ params
191210 ) ;
192211
193212 response && triggerOnError ( response ) ;
194213
195214 if ( response && isValidResponse ( response ) ) {
196215 resetValues ( ) ;
216+ setEndReached ( true ) ;
197217 setIsLoading ( false ) ;
198218 }
199219 }
@@ -227,7 +247,8 @@ const SirenPanel: FC<SirenPanelProps> = ({
227247 generateFilterParams (
228248 isRefresh ? [ ] : notifications ,
229249 false ,
230- noOfNotificationsPerFetch
250+ noOfNotificationsPerFetch ,
251+ filterType
231252 )
232253 ) ;
233254
@@ -270,7 +291,7 @@ const SirenPanel: FC<SirenPanelProps> = ({
270291
271292 try {
272293 siren ?. startRealTimeFetch (
273- { eventType : EventType . NOTIFICATION , params : generateFilterParams ( newList ?? [ ] , true , noOfNotificationsPerFetch ) }
294+ { eventType : EventType . NOTIFICATION , params : generateFilterParams ( newList ?? [ ] , true , noOfNotificationsPerFetch , filterType ) }
274295 ) ;
275296 } catch ( er ) {
276297 // handle error if needed
@@ -326,6 +347,14 @@ const SirenPanel: FC<SirenPanelProps> = ({
326347 onEndReached ( ) ;
327348 } ;
328349
350+
351+ const handleTabChange = ( index : number ) => {
352+ resetValues ( ) ;
353+ cleanUp ( ) ;
354+ setActiveTabIndex ( index ) ;
355+ setFilterType ( tabProps . tabs [ index ] . key ) ;
356+ } ;
357+
329358 const renderFooter = ( ) => {
330359 if ( isEmptyArray ( notifications ) && isLoading ) return < div /> ;
331360
@@ -350,7 +379,7 @@ const SirenPanel: FC<SirenPanelProps> = ({
350379 />
351380 ) ) ;
352381 } , [ notifications , cardProps , onCardClick , deleteNotificationById , styles , darkMode ] ) ;
353-
382+
354383
355384 const renderList = ( ) => {
356385 if ( isLoading && isEmptyArray ( notifications ) ) {
@@ -387,14 +416,15 @@ const SirenPanel: FC<SirenPanelProps> = ({
387416 data-testid = "empty-list"
388417 styles = { styles }
389418 darkMode = { darkMode }
419+ emptyText = { filterType === Tabs . UNREAD ? UNREAD_LIST_EMPTY_TEXT : LIST_EMPTY_TEXT }
390420 /> )
391421 }
392422 </ div >
393423 ) ;
394424
395- if ( customCard )
396- return notifications . map ( ( item ) => customCard ( item ) ) ;
397-
425+ if ( customCard )
426+ return notifications . map ( ( item ) => customCard ( item ) ) ;
427+
398428 return renderedListItems ;
399429 } ;
400430
@@ -457,6 +487,13 @@ const SirenPanel: FC<SirenPanelProps> = ({
457487 return getModalContentHeightInFullScreen ( styles ?. headerContainer ?. height ) ;
458488 } , [ styles ?. headerContainer ?. height ] ) ;
459489
490+ const defaultTabProps = {
491+ tabs : tabProps . tabs ,
492+ activeTab : tabProps . activeTab ,
493+ onTabChange : handleTabChange ,
494+ styles : styles ,
495+ } ;
496+
460497 return (
461498 < div
462499 className = {
@@ -484,6 +521,7 @@ const SirenPanel: FC<SirenPanelProps> = ({
484521 ...styles . contentContainer ,
485522 } }
486523 >
524+ { ! hideTab && ( < Tab { ...defaultTabProps } /> ) }
487525 < div
488526 id = "contentContainer"
489527 style = { {
0 commit comments