import React, { useEffect, useState } from 'react'; import { useCallState } from '../../contexts/CallProvider'; import { useWaitingRoom } from '../../contexts/WaitingRoomProvider'; import { ReactComponent as IconWaiting } from '../../icons/add-person-lg.svg'; import Button from '../Button'; import { Card, CardBody, CardFooter } from '../Card'; export const WaitingRoomNotification = () => { const { callObject } = useCallState(); const { denyAccess, grantAccess, showModal, setShowModal, waitingParticipants, } = useWaitingRoom(); const [showNotification, setShowNotification] = useState(false); /** * Show notification when waiting participants change. */ useEffect(() => { if (showModal) return false; const handleWaitingParticipantAdded = () => { setShowNotification( Object.keys(callObject.waitingParticipants()).length > 0 ); }; callObject.on('waiting-participant-added', handleWaitingParticipantAdded); return () => { callObject.off( 'waiting-participant-added', handleWaitingParticipantAdded ); }; }, [callObject, showModal]); /** * Hide notification when people panel is opened. */ useEffect(() => { if (showModal) setShowNotification(false); }, [showModal]); if (!showNotification || waitingParticipants.length === 0) return null; const hasMultiplePeopleWaiting = waitingParticipants.length > 1; const handleViewAllClick = () => { setShowModal(true); setShowNotification(false); }; const handleAllowClick = () => { grantAccess(waitingParticipants[0].id); }; const handleDenyClick = () => { denyAccess(hasMultiplePeopleWaiting ? 'all' : waitingParticipants[0].id); }; return ( {hasMultiplePeopleWaiting ? waitingParticipants.length : waitingParticipants[0].name} {hasMultiplePeopleWaiting ? ` people would like to join the call` : ` would like to join the call`} {hasMultiplePeopleWaiting ? ( ) : ( )} ); }; export default WaitingRoomNotification;