diff --git a/custom/shared/components/WaitingRoom/WaitingRoomNotification.js b/custom/shared/components/WaitingRoom/WaitingRoomNotification.js index 3dee756..5ccbc38 100644 --- a/custom/shared/components/WaitingRoom/WaitingRoomNotification.js +++ b/custom/shared/components/WaitingRoom/WaitingRoomNotification.js @@ -1,5 +1,4 @@ -import React, { useEffect, useState } from 'react'; - +import React, { useCallback, useEffect, useMemo, useState } from 'react'; import { useCallState } from '../../contexts/CallProvider'; import { useWaitingRoom } from '../../contexts/WaitingRoomProvider'; import { ReactComponent as IconWaiting } from '../../icons/add-person-lg.svg'; @@ -14,9 +13,70 @@ export const WaitingRoomNotification = () => { showModal, setShowModal, waitingParticipants, + multipleWaiting, } = useWaitingRoom(); const [showNotification, setShowNotification] = useState(false); + /** + * Click handlers passed to render functions + */ + const handleViewAllClick = useCallback(() => { + setShowModal(true); + setShowNotification(false); + }, [setShowModal]); + + const handleAllowClick = useCallback(() => { + grantAccess(waitingParticipants[0].id); + }, [grantAccess, waitingParticipants]); + + const handleDenyClick = useCallback(() => { + denyAccess(multipleWaiting ? 'all' : waitingParticipants[0].id); + }, [denyAccess, waitingParticipants, multipleWaiting]); + + /** + * Render the full participant waiting list + */ + const showMultipleParticipants = useMemo(() => { + return ( + +

+ {waitingParticipants.length} people would like to + join the call +

+ + + + +
+ ); + }, [waitingParticipants, handleDenyClick, handleViewAllClick]); + + /** + * Render the single waiting participant + */ + const showSingleParticipant = useMemo(() => { + return ( + +

+ {waitingParticipants[0]?.name} would like to join the + call +

+ + + + +
+ ); + }, [waitingParticipants, handleAllowClick, handleDenyClick]); + /** * Show notification when waiting participants change. */ @@ -47,48 +107,12 @@ export const WaitingRoomNotification = () => { 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 ? ( - - ) : ( - - )} - - - + {multipleWaiting ? showMultipleParticipants : showSingleParticipant}