consent dialog button

This commit is contained in:
Igor Loskutov
2025-06-20 10:57:38 -04:00
parent 8f0bd31c75
commit 1c60c809eb

View File

@@ -50,8 +50,11 @@ const useConsentWherebyFocusManagement = (acceptButtonRef: RefObject<HTMLButtonE
const useConsentDialog = (meetingId: string, wherebyRef: RefObject<HTMLElement>/*accessibility*/) => { const useConsentDialog = (meetingId: string, wherebyRef: RefObject<HTMLElement>/*accessibility*/) => {
const { state: consentState, touch, hasConsent } = useRecordingConsent(); const { state: consentState, touch, hasConsent } = useRecordingConsent();
const [consentLoading, setConsentLoading] = useState(false); const [consentLoading, setConsentLoading] = useState(false);
// toast would open duplicates, even with using "id=" prop
const [modalOpen, setModalOpen] = useState(false);
const api = useApi(); const api = useApi();
const toast = useToast(); const toast = useToast();
const handleConsent = useCallback(async (meetingId: string, given: boolean) => { const handleConsent = useCallback(async (meetingId: string, given: boolean) => {
if (!api) return; if (!api) return;
@@ -71,81 +74,102 @@ const useConsentDialog = (meetingId: string, wherebyRef: RefObject<HTMLElement>/
} }
}, [api, touch]); }, [api, touch]);
useEffect(() => { const showConsentModal = useCallback(() => {
if ( if (modalOpen) return;
consentState.ready &&
meetingId &&
!hasConsent(meetingId) &&
!consentLoading
) {
const toastId = toast({ setModalOpen(true);
position: "top",
duration: null,
render: ({ onClose }) => {
const AcceptButton = () => {
const buttonRef = useRef<HTMLButtonElement>(null);
useConsentWherebyFocusManagement(buttonRef, wherebyRef);
return (
<Button
ref={buttonRef}
colorScheme="blue"
size="sm"
onClick={() => {
handleConsent(meetingId, true).then(() => {/*signifies it's ok to now wait here.*/})
onClose()
}}
>
Yes, store the audio
</Button>
);
};
const TOAST_NEVER_DISMISS_VALUE = null;
const toastId = toast({
position: "top",
duration: TOAST_NEVER_DISMISS_VALUE,
render: ({ onClose }) => {
const AcceptButton = () => {
const buttonRef = useRef<HTMLButtonElement>(null);
useConsentWherebyFocusManagement(buttonRef, wherebyRef);
return ( return (
<Box p={6} bg="rgba(255, 255, 255, 0.7)" borderRadius="lg" boxShadow="lg" maxW="md" mx="auto"> <Button
<VStack spacing={4} align="center"> ref={buttonRef}
<Text fontSize="md" textAlign="center" fontWeight="medium"> colorScheme="blue"
Can we have your permission to store this meeting's audio recording on our servers? size="sm"
</Text> onClick={() => {
<HStack spacing={4} justify="center"> handleConsent(meetingId, true).then(() => {/*signifies it's ok to now wait here.*/})
<AcceptButton /> onClose()
<Button }}
colorScheme="gray" >
size="sm" Yes, store the audio
onClick={() => { </Button>
handleConsent(meetingId, false).then(() => {/*signifies it's ok to now wait here.*/})
onClose()
}}
>
No, delete after transcription
</Button>
</HStack>
</VStack>
</Box>
); );
}, };
});
// Handle escape key to close the toast return (
const handleKeyDown = (event: KeyboardEvent) => { <Box p={6} bg="rgba(255, 255, 255, 0.7)" borderRadius="lg" boxShadow="lg" maxW="md" mx="auto">
if (event.key === 'Escape') { <VStack spacing={4} align="center">
toast.close(toastId); <Text fontSize="md" textAlign="center" fontWeight="medium">
} Can we have your permission to store this meeting's audio recording on our servers?
}; </Text>
<HStack spacing={4} justify="center">
<AcceptButton />
<Button
colorScheme="gray"
size="sm"
onClick={() => {
handleConsent(meetingId, false).then(() => {/*signifies it's ok to now wait here.*/})
onClose()
}}
>
No, delete after transcription
</Button>
</HStack>
</VStack>
</Box>
);
},
onCloseComplete: () => {
setModalOpen(false);
}
});
document.addEventListener('keydown', handleKeyDown); // Handle escape key to close the toast
const handleKeyDown = (event: KeyboardEvent) => {
return () => { if (event.key === 'Escape') {
toast.close(toastId); 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<HTMLElement> }) { function ConsentDialogButton({ meetingId, wherebyRef }: { meetingId: string; wherebyRef: React.RefObject<HTMLElement> }) {
useConsentDialog(meetingId, wherebyRef); const { showConsentModal, consentState, hasConsent, consentLoading } = useConsentDialog(meetingId, wherebyRef);
return <></>
if (!consentState.ready || hasConsent(meetingId) || consentLoading) {
return null;
}
return (
<Button
position="absolute"
top="56px"
left="8px"
zIndex={1000}
colorScheme="blue"
size="sm"
onClick={showConsentModal}
>
Meeting is recording
</Button>
);
} }
const recordingTypeRequiresConsent = (recordingType: NonNullable<Meeting['recording_type']>) => { const recordingTypeRequiresConsent = (recordingType: NonNullable<Meeting['recording_type']>) => {
@@ -237,7 +261,7 @@ export default function Room(details: RoomDetails) {
room={roomUrl} room={roomUrl}
style={{ width: "100vw", height: "100vh" }} style={{ width: "100vw", height: "100vh" }}
/> />
{recordingType && recordingTypeRequiresConsent(recordingType) && <ConsentDialog meetingId={meetingId} wherebyRef={wherebyRef} />} {recordingType && recordingTypeRequiresConsent(recordingType) && <ConsentDialogButton meetingId={meetingId} wherebyRef={wherebyRef} />}
</> </>
)} )}
</> </>