• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

atlp-rwanda / trojans-ec-fe / deb4f0a9-072d-4634-aae5-cf86f706e873

pending completion
deb4f0a9-072d-4634-aae5-cf86f706e873

Pull #47

circleci

Ntare cedrick
Merge branch 'ft-sales-status-000003' of github.com:atlp-rwanda/trojans-ec-fe into ft-sales-status-000003
Pull Request #47: #000003 update sales status

553 of 843 branches covered (65.6%)

Branch coverage included in aggregate %.

120 of 120 new or added lines in 8 files covered. (100.0%)

1302 of 1731 relevant lines covered (75.22%)

23.03 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

90.48
/src/components/hooks/useNotification.js
1
import React, { useEffect, useState } from 'react'
2
import { getNotifThunk } from '../../redux/features/actions/notification'
3
import { useDispatch, useSelector } from 'react-redux'
4
import { getNotifStates } from '../../redux/features/slices/notification'
5
import { socket } from '../../config/socket'
6
import { setMarkOneAsRead, setMarkAllAsRead, setTotalNotif } from '../../redux/features/slices/notification';
7
import { DeleteNotification, MarkAllNotification , MarkOneNotification } from '../../redux/features/actions/notification';
8
import { toast } from 'react-toastify';
9
import { socketHandle } from '../../helpers/notifications/socketHandle'
10
import { MarkNotifAsRead, handleDelNotification } from '../../helpers/notifications/notificationHandler'
11
import { handleCheckbox } from '../../helpers/notifications/SelectCheckbox';
12

13
const notificationLogic = () => {
26✔
14
    const {notifications, loading, error, message} = useSelector(getNotifStates)
160✔
15
    const dispatch = useDispatch()
152✔
16
    const [isOpen, setIsOpen] = useState(false);
152✔
17
    const [viewMore, setViewMore] = useState(false);
152✔
18
    const [totalNotification, setTotalNotification] = useState(0)
152✔
19

20
    const [checkedItem, setCheckedItem] = useState([]);
152✔
21
    const isSelectAllSelected = checkedItem.length === notifications.length ;
152✔
22
    let visibleNotifications;
23

24
    !viewMore ? visibleNotifications = notifications?.slice(-4).reverse() : visibleNotifications = notifications?.slice().reverse();
152!
25

26
    useEffect(()=>{
152✔
27
        dispatch(getNotifThunk())
34✔
28
    },[])
29
    //handling click outside notification box
30
    useEffect(() => {
152✔
31
      const handleClickOutside = (event) => {
34✔
32
        if(!event.target.closest('.notifications') && !event.target.closest('.drop-content')  && !event.target.closest('.viewMore')){
20✔
33
          setIsOpen(false)
8✔
34
        }
35
      };
36
      window.addEventListener('click', handleClickOutside);
34✔
37
    }, []);
38

39
    //handling notification when some notification added
40
    useEffect(()=>{
152✔
41
      socketHandle(socket, dispatch, setTotalNotif)
34✔
42
    }, [])   
43

44
    //Generating new total notification
45
    useEffect(()=>{
152✔
46
      if(notifications){
38!
47
        const newNotifValue = notifications.filter((notif)=> !notif.read)
38✔
48
        setTotalNotification(newNotifValue.length)
38✔
49
      }
50
    },[notifications]);
51

52
    const handleOpen = ()=>{
152✔
53
      setIsOpen(prevState => !prevState) 
×
54
    }
55
      
56
      //Mark one and all notification as read
57
      const handleMarkAsRead = async(notificationId)=>{
152✔
58
        await MarkNotifAsRead( {notificationId, dispatch, toast, MarkOneNotification,  MarkAllNotification, setMarkOneAsRead, setMarkAllAsRead} )
2✔
59
      }
60

61
      //delete Notification
62
      const handleDelete = async(notificationId)=>{
152✔
63
        await handleDelNotification(
2✔
64
          {notificationId, dispatch, toast, setMarkOneAsRead, DeleteNotification}
65
        )
66
      }
67
    
68
    //handling select Chechbox
69
    const handleBoxChange = (notificationId)=>{
152✔
70
        handleCheckbox(
4✔
71
          notificationId, 
72
          isSelectAllSelected, 
73
          setCheckedItem, 
74
          notifications,
75
          checkedItem
76
        )
77
    }
78
    //handle view more notification button
79
    const handleViewMore = ()=>{
152✔
80
      setViewMore(!viewMore)
×
81
    }
82

83
    return {
152✔
84
      checkedItem, 
85
      handleBoxChange, 
86
      isSelectAllSelected, 
87
      setCheckedItem, 
88
      notifications,
89
      loading,
90
      error,
91
      message,
92
      handleOpen,
93
      totalNotification,
94
      isOpen,
95
      handleMarkAsRead,
96
      handleDelete,
97
      visibleNotifications,
98
      viewMore,
99
      setViewMore,
100
      handleViewMore
101
    }
102
}
103

104
export default notificationLogic
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc