mirror of
https://github.com/Monadical-SAS/reflector.git
synced 2025-12-21 04:39:06 +00:00
consent dialog button
This commit is contained in:
@@ -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,17 +74,15 @@ 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
|
|
||||||
) {
|
|
||||||
|
|
||||||
|
setModalOpen(true);
|
||||||
|
|
||||||
|
const TOAST_NEVER_DISMISS_VALUE = null;
|
||||||
const toastId = toast({
|
const toastId = toast({
|
||||||
position: "top",
|
position: "top",
|
||||||
duration: null,
|
duration: TOAST_NEVER_DISMISS_VALUE,
|
||||||
render: ({ onClose }) => {
|
render: ({ onClose }) => {
|
||||||
const AcceptButton = () => {
|
const AcceptButton = () => {
|
||||||
const buttonRef = useRef<HTMLButtonElement>(null);
|
const buttonRef = useRef<HTMLButtonElement>(null);
|
||||||
@@ -124,6 +125,9 @@ const useConsentDialog = (meetingId: string, wherebyRef: RefObject<HTMLElement>/
|
|||||||
</Box>
|
</Box>
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
onCloseComplete: () => {
|
||||||
|
setModalOpen(false);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// Handle escape key to close the toast
|
// Handle escape key to close the toast
|
||||||
@@ -135,17 +139,37 @@ const useConsentDialog = (meetingId: string, wherebyRef: RefObject<HTMLElement>/
|
|||||||
|
|
||||||
document.addEventListener('keydown', handleKeyDown);
|
document.addEventListener('keydown', handleKeyDown);
|
||||||
|
|
||||||
return () => {
|
const cleanup = () => {
|
||||||
toast.close(toastId);
|
toast.close(toastId);
|
||||||
document.removeEventListener('keydown', handleKeyDown);
|
document.removeEventListener('keydown', handleKeyDown);
|
||||||
};
|
};
|
||||||
}
|
|
||||||
}, [consentState.ready, meetingId, hasConsent, consentLoading, toast, handleConsent]);
|
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} />}
|
||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
</>
|
</>
|
||||||
|
|||||||
Reference in New Issue
Block a user