diff --git a/www/app/[roomName]/page.tsx b/www/app/[roomName]/page.tsx index 821c7a52..ac033d6a 100644 --- a/www/app/[roomName]/page.tsx +++ b/www/app/[roomName]/page.tsx @@ -50,8 +50,11 @@ const useConsentWherebyFocusManagement = (acceptButtonRef: RefObject/*accessibility*/) => { const { state: consentState, touch, hasConsent } = useRecordingConsent(); const [consentLoading, setConsentLoading] = useState(false); + // toast would open duplicates, even with using "id=" prop + const [modalOpen, setModalOpen] = useState(false); const api = useApi(); const toast = useToast(); + const handleConsent = useCallback(async (meetingId: string, given: boolean) => { if (!api) return; @@ -71,81 +74,102 @@ const useConsentDialog = (meetingId: string, wherebyRef: RefObject/ } }, [api, touch]); - useEffect(() => { - if ( - consentState.ready && - meetingId && - !hasConsent(meetingId) && - !consentLoading - ) { + const showConsentModal = useCallback(() => { + if (modalOpen) return; - const toastId = toast({ - position: "top", - duration: null, - render: ({ onClose }) => { - const AcceptButton = () => { - const buttonRef = useRef(null); - useConsentWherebyFocusManagement(buttonRef, wherebyRef); - return ( - - ); - }; + setModalOpen(true); + const TOAST_NEVER_DISMISS_VALUE = null; + const toastId = toast({ + position: "top", + duration: TOAST_NEVER_DISMISS_VALUE, + render: ({ onClose }) => { + const AcceptButton = () => { + const buttonRef = useRef(null); + useConsentWherebyFocusManagement(buttonRef, wherebyRef); return ( - - - - Can we have your permission to store this meeting's audio recording on our servers? - - - - - - - + ); - }, - }); + }; - // Handle escape key to close the toast - const handleKeyDown = (event: KeyboardEvent) => { - if (event.key === 'Escape') { - toast.close(toastId); - } - }; + return ( + + + + Can we have your permission to store this meeting's audio recording on our servers? + + + + + + + + ); + }, + onCloseComplete: () => { + setModalOpen(false); + } + }); - document.addEventListener('keydown', handleKeyDown); - - return () => { + // Handle escape key to close the toast + const handleKeyDown = (event: KeyboardEvent) => { + if (event.key === 'Escape') { toast.close(toastId); - document.removeEventListener('keydown', handleKeyDown); - }; - } - }, [consentState.ready, meetingId, hasConsent, consentLoading, toast, handleConsent]); + } + }; + + document.addEventListener('keydown', handleKeyDown); + + const cleanup = () => { + toast.close(toastId); + document.removeEventListener('keydown', handleKeyDown); + }; + + return cleanup; + }, [meetingId, toast, handleConsent, wherebyRef, modalOpen]); + + return { showConsentModal, consentState, hasConsent, consentLoading }; } -function ConsentDialog({ meetingId, wherebyRef }: { meetingId: string; wherebyRef: React.RefObject }) { - useConsentDialog(meetingId, wherebyRef); - return <> +function ConsentDialogButton({ meetingId, wherebyRef }: { meetingId: string; wherebyRef: React.RefObject }) { + const { showConsentModal, consentState, hasConsent, consentLoading } = useConsentDialog(meetingId, wherebyRef); + + if (!consentState.ready || hasConsent(meetingId) || consentLoading) { + return null; + } + + return ( + + ); } const recordingTypeRequiresConsent = (recordingType: NonNullable) => { @@ -237,7 +261,7 @@ export default function Room(details: RoomDetails) { room={roomUrl} style={{ width: "100vw", height: "100vh" }} /> - {recordingType && recordingTypeRequiresConsent(recordingType) && } + {recordingType && recordingTypeRequiresConsent(recordingType) && } )}