11import type { CSSProperties } from "react" ;
2- import React , { type FC } from "react" ;
2+ import React , { type FC , useState } from "react" ;
33
44import CloseIcon from "./CloseIcon" ;
55import TimerIcon from "./TimerIcon" ;
@@ -8,6 +8,7 @@ import defaultAvatarLight from "../assets/light/defaultAvatarLight.png";
88import type { NotificationCardProps } from "../types" ;
99import { generateElapsedTimeText } from "../utils/commonUtils" ;
1010import "../styles/card.css" ;
11+ import { events , eventTypes } from "../utils/constants" ;
1112import useSiren from "../utils/sirenHook" ;
1213
1314/**
@@ -48,28 +49,37 @@ const Card: FC<NotificationCardProps> = ({
4849 styles,
4950 darkMode,
5051 onCardClick,
51- deleteById ,
52+ deleteNotificationById ,
5253} ) => {
53- const { id , createdAt, message, isRead } = notification ;
54+ const { createdAt, message, isRead } = notification ;
5455 const { avatar, header, subHeader, body } = message ;
5556 const { hideAvatar, hideDelete, disableAutoMarkAsRead, deleteIcon = null , onAvatarClick } = cardProps ?? { } ;
5657 const {
5758 markAsReadById
5859 } = useSiren ( ) ;
5960
60- const onDelete = ( event : React . MouseEvent ) => {
61- const cardElement = event . currentTarget . closest (
62- ".siren-sdk-card-common-container"
63- ) ;
61+ const [ deleteAnimationStyle , setDeleteAnimationStyle ] = useState ( '' ) ;
6462
65- cardElement ?. classList . add ( "siren-sdk-delete-animation" ) ;
66- setTimeout ( ( ) => {
67- deleteById ( id ) ;
68- } , 200 ) ;
63+ const onDelete = async ( event : React . MouseEvent ) : Promise < void > => {
6964
7065 event . stopPropagation ( ) ;
66+
67+ const isSuccess = await deleteNotificationById ( notification . id , false ) ;
68+
69+ if ( isSuccess ) {
70+
71+ setDeleteAnimationStyle ( "siren-sdk-delete-animation" ) ;
72+
73+ const payload = { id : notification . id , action : eventTypes . DELETE_ITEM } ;
74+
75+ setTimeout ( ( ) => {
76+ PubSub . publish ( events . NOTIFICATION_LIST_EVENT , JSON . stringify ( payload ) ) ;
77+ } , 200 )
78+
79+ }
7180 } ;
7281
82+
7383 const defaultAvatar = darkMode ? defaultAvatarDark : defaultAvatarLight ;
7484 const cardContainerStyle : CSSProperties = isRead
7585 ? {
@@ -99,7 +109,7 @@ const Card: FC<NotificationCardProps> = ({
99109 hideAvatar
100110 ? "siren-sdk-hide-avatar-card-container"
101111 : "siren-sdk-card-container"
102- } siren-sdk-card-common-container`}
112+ } siren-sdk-card-common-container ${ deleteAnimationStyle } `}
103113 onClick = { handleNotificationCardClick }
104114 aria-label = { `siren-notification-card-${ notification . id } ` }
105115 data-testid = { `card-${ notification . id } ` }
0 commit comments