mirror of
https://github.com/Monadical-SAS/reflector.git
synced 2025-12-20 20:29:06 +00:00
consent dialog api cleanup
This commit is contained in:
@@ -1,48 +0,0 @@
|
|||||||
import React from "react";
|
|
||||||
import {
|
|
||||||
Modal,
|
|
||||||
ModalOverlay,
|
|
||||||
ModalContent,
|
|
||||||
ModalHeader,
|
|
||||||
ModalBody,
|
|
||||||
Button,
|
|
||||||
Text,
|
|
||||||
HStack,
|
|
||||||
} from "@chakra-ui/react";
|
|
||||||
|
|
||||||
interface AudioConsentDialogProps {
|
|
||||||
isOpen: boolean;
|
|
||||||
onClose: () => void;
|
|
||||||
onConsent: (given: boolean) => void;
|
|
||||||
}
|
|
||||||
|
|
||||||
const AudioConsentDialog = ({ isOpen, onClose, onConsent }: AudioConsentDialogProps) => {
|
|
||||||
const handleConsent = (given: boolean) => {
|
|
||||||
onConsent(given);
|
|
||||||
onClose();
|
|
||||||
};
|
|
||||||
|
|
||||||
return (
|
|
||||||
<Modal isOpen={isOpen} onClose={onClose} closeOnOverlayClick={false} closeOnEsc={false}>
|
|
||||||
<ModalOverlay />
|
|
||||||
<ModalContent>
|
|
||||||
<ModalHeader>Audio Storage Consent</ModalHeader>
|
|
||||||
<ModalBody pb={6}>
|
|
||||||
<Text mb={4}>
|
|
||||||
Can we have your permission to store this meeting's audio recording on our servers?
|
|
||||||
</Text>
|
|
||||||
<HStack spacing={4}>
|
|
||||||
<Button colorScheme="green" onClick={() => handleConsent(true)}>
|
|
||||||
Yes, store the audio
|
|
||||||
</Button>
|
|
||||||
<Button colorScheme="red" onClick={() => handleConsent(false)}>
|
|
||||||
No, delete after transcription
|
|
||||||
</Button>
|
|
||||||
</HStack>
|
|
||||||
</ModalBody>
|
|
||||||
</ModalContent>
|
|
||||||
</Modal>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
export default AudioConsentDialog;
|
|
||||||
@@ -7,10 +7,7 @@ import useRoomMeeting from "./useRoomMeeting";
|
|||||||
import { useRouter } from "next/navigation";
|
import { useRouter } from "next/navigation";
|
||||||
import { notFound } from "next/navigation";
|
import { notFound } from "next/navigation";
|
||||||
import useSessionStatus from "../lib/useSessionStatus";
|
import useSessionStatus from "../lib/useSessionStatus";
|
||||||
import { DomainContext } from "../domainContext";
|
|
||||||
import { useRecordingConsent } from "../recordingConsentContext";
|
import { useRecordingConsent } from "../recordingConsentContext";
|
||||||
import useSessionAccessToken from "../lib/useSessionAccessToken";
|
|
||||||
import useSessionUser from "../lib/useSessionUser";
|
|
||||||
import useApi from "../lib/useApi";
|
import useApi from "../lib/useApi";
|
||||||
|
|
||||||
export type RoomDetails = {
|
export type RoomDetails = {
|
||||||
@@ -19,35 +16,14 @@ export type RoomDetails = {
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
export default function Room(details: RoomDetails) {
|
const useConsentDialog = (meetingId: string) => {
|
||||||
const wherebyRef = useRef<HTMLElement>(null);
|
|
||||||
const roomName = details.params.roomName;
|
|
||||||
const meeting = useRoomMeeting(roomName);
|
|
||||||
const router = useRouter();
|
|
||||||
const { isLoading, isAuthenticated } = useSessionStatus();
|
|
||||||
const [consentLoading, setConsentLoading] = useState(false);
|
|
||||||
const { state: consentState, touch, hasConsent } = useRecordingConsent();
|
const { state: consentState, touch, hasConsent } = useRecordingConsent();
|
||||||
const { api_url } = useContext(DomainContext);
|
const [consentLoading, setConsentLoading] = useState(false);
|
||||||
const { accessToken } = useSessionAccessToken();
|
|
||||||
const { id: userId } = useSessionUser();
|
|
||||||
const api = useApi();
|
const api = useApi();
|
||||||
const toast = useToast();
|
const toast = useToast();
|
||||||
|
const handleConsent = useCallback(async (meetingId: string, given: boolean) => {
|
||||||
|
|
||||||
const roomUrl = meeting?.response?.host_room_url
|
|
||||||
? meeting?.response?.host_room_url
|
|
||||||
: meeting?.response?.room_url;
|
|
||||||
|
|
||||||
const meetingId = meeting?.response?.id;
|
|
||||||
|
|
||||||
const handleLeave = useCallback(() => {
|
|
||||||
router.push("/browse");
|
|
||||||
}, [router]);
|
|
||||||
|
|
||||||
const handleConsent = useCallback(async (meetingId: string, given: boolean, onClose?: () => void) => {
|
|
||||||
if (!api) return;
|
if (!api) return;
|
||||||
|
|
||||||
if (onClose) onClose();
|
|
||||||
setConsentLoading(true);
|
setConsentLoading(true);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@@ -55,7 +31,7 @@ export default function Room(details: RoomDetails) {
|
|||||||
meetingId,
|
meetingId,
|
||||||
requestBody: { consent_given: given }
|
requestBody: { consent_given: given }
|
||||||
});
|
});
|
||||||
|
|
||||||
touch(meetingId);
|
touch(meetingId);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Error submitting consent:', error);
|
console.error('Error submitting consent:', error);
|
||||||
@@ -64,18 +40,6 @@ export default function Room(details: RoomDetails) {
|
|||||||
}
|
}
|
||||||
}, [api, touch]);
|
}, [api, touch]);
|
||||||
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
if (
|
|
||||||
!isLoading &&
|
|
||||||
meeting?.error &&
|
|
||||||
"status" in meeting.error &&
|
|
||||||
meeting.error.status === 404
|
|
||||||
) {
|
|
||||||
notFound();
|
|
||||||
}
|
|
||||||
}, [isLoading, meeting?.error]);
|
|
||||||
|
|
||||||
// Show consent toast when meeting is loaded and consent hasn't been answered yet
|
// Show consent toast when meeting is loaded and consent hasn't been answered yet
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (
|
if (
|
||||||
@@ -94,17 +58,23 @@ export default function Room(details: RoomDetails) {
|
|||||||
Can we have your permission to store this meeting's audio recording on our servers?
|
Can we have your permission to store this meeting's audio recording on our servers?
|
||||||
</Text>
|
</Text>
|
||||||
<HStack spacing={4} justify="center">
|
<HStack spacing={4} justify="center">
|
||||||
<Button
|
<Button
|
||||||
colorScheme="green"
|
colorScheme="green"
|
||||||
size="sm"
|
size="sm"
|
||||||
onClick={() => handleConsent(meetingId, true, onClose)}
|
onClick={() => {
|
||||||
|
handleConsent(meetingId, true).then(() => {/*signifies it's ok to now wait here.*/})
|
||||||
|
onClose()
|
||||||
|
}}
|
||||||
>
|
>
|
||||||
Yes, store the audio
|
Yes, store the audio
|
||||||
</Button>
|
</Button>
|
||||||
<Button
|
<Button
|
||||||
colorScheme="red"
|
colorScheme="red"
|
||||||
size="sm"
|
size="sm"
|
||||||
onClick={() => handleConsent(meetingId, false, onClose)}
|
onClick={() => {
|
||||||
|
handleConsent(meetingId, false).then(() => {/*signifies it's ok to now wait here.*/})
|
||||||
|
onClose()
|
||||||
|
}}
|
||||||
>
|
>
|
||||||
No, delete after transcription
|
No, delete after transcription
|
||||||
</Button>
|
</Button>
|
||||||
@@ -119,6 +89,40 @@ export default function Room(details: RoomDetails) {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
}, [consentState.ready, meetingId, hasConsent, consentLoading, toast, handleConsent]);
|
}, [consentState.ready, meetingId, hasConsent, consentLoading, toast, handleConsent]);
|
||||||
|
}
|
||||||
|
|
||||||
|
function ConsentDialog({ meetingId }: { meetingId: string }) {
|
||||||
|
useConsentDialog(meetingId);
|
||||||
|
return <></>
|
||||||
|
}
|
||||||
|
|
||||||
|
export default function Room(details: RoomDetails) {
|
||||||
|
const wherebyRef = useRef<HTMLElement>(null);
|
||||||
|
const roomName = details.params.roomName;
|
||||||
|
const meeting = useRoomMeeting(roomName);
|
||||||
|
const router = useRouter();
|
||||||
|
const { isLoading, isAuthenticated } = useSessionStatus();
|
||||||
|
|
||||||
|
const roomUrl = meeting?.response?.host_room_url
|
||||||
|
? meeting?.response?.host_room_url
|
||||||
|
: meeting?.response?.room_url;
|
||||||
|
|
||||||
|
const meetingId = meeting?.response?.id;
|
||||||
|
|
||||||
|
const handleLeave = useCallback(() => {
|
||||||
|
router.push("/browse");
|
||||||
|
}, [router]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (
|
||||||
|
!isLoading &&
|
||||||
|
meeting?.error &&
|
||||||
|
"status" in meeting.error &&
|
||||||
|
meeting.error.status === 404
|
||||||
|
) {
|
||||||
|
notFound();
|
||||||
|
}
|
||||||
|
}, [isLoading, meeting?.error]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (isLoading || !isAuthenticated || !roomUrl) return;
|
if (isLoading || !isAuthenticated || !roomUrl) return;
|
||||||
@@ -154,12 +158,15 @@ export default function Room(details: RoomDetails) {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
{roomUrl && (
|
{roomUrl && meetingId && (
|
||||||
<whereby-embed
|
<>
|
||||||
ref={wherebyRef}
|
<whereby-embed
|
||||||
room={roomUrl}
|
ref={wherebyRef}
|
||||||
style={{ width: "100vw", height: "100vh" }}
|
room={roomUrl}
|
||||||
/>
|
style={{ width: "100vw", height: "100vh" }}
|
||||||
|
/>
|
||||||
|
<ConsentDialog meetingId={meetingId} />
|
||||||
|
</>
|
||||||
)}
|
)}
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user