From 58f51697b0f4aa1930dd301b85fc02ac77b4e74b Mon Sep 17 00:00:00 2001 From: Igor Loskutov Date: Wed, 18 Jun 2025 15:55:16 -0400 Subject: [PATCH] consent dialog api cleanup --- www/app/(app)/rooms/audioConsentDialog.tsx | 48 --------- www/app/[roomName]/page.tsx | 111 +++++++++++---------- 2 files changed, 59 insertions(+), 100 deletions(-) delete mode 100644 www/app/(app)/rooms/audioConsentDialog.tsx diff --git a/www/app/(app)/rooms/audioConsentDialog.tsx b/www/app/(app)/rooms/audioConsentDialog.tsx deleted file mode 100644 index e3d568f3..00000000 --- a/www/app/(app)/rooms/audioConsentDialog.tsx +++ /dev/null @@ -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 ( - - - - Audio Storage Consent - - - Can we have your permission to store this meeting's audio recording on our servers? - - - - - - - - - ); -}; - -export default AudioConsentDialog; \ No newline at end of file diff --git a/www/app/[roomName]/page.tsx b/www/app/[roomName]/page.tsx index 30b4138c..6e182d10 100644 --- a/www/app/[roomName]/page.tsx +++ b/www/app/[roomName]/page.tsx @@ -7,10 +7,7 @@ import useRoomMeeting from "./useRoomMeeting"; import { useRouter } from "next/navigation"; import { notFound } from "next/navigation"; import useSessionStatus from "../lib/useSessionStatus"; -import { DomainContext } from "../domainContext"; import { useRecordingConsent } from "../recordingConsentContext"; -import useSessionAccessToken from "../lib/useSessionAccessToken"; -import useSessionUser from "../lib/useSessionUser"; import useApi from "../lib/useApi"; export type RoomDetails = { @@ -19,35 +16,14 @@ export type RoomDetails = { }; }; -export default function Room(details: RoomDetails) { - const wherebyRef = useRef(null); - const roomName = details.params.roomName; - const meeting = useRoomMeeting(roomName); - const router = useRouter(); - const { isLoading, isAuthenticated } = useSessionStatus(); - const [consentLoading, setConsentLoading] = useState(false); +const useConsentDialog = (meetingId: string) => { const { state: consentState, touch, hasConsent } = useRecordingConsent(); - const { api_url } = useContext(DomainContext); - const { accessToken } = useSessionAccessToken(); - const { id: userId } = useSessionUser(); + const [consentLoading, setConsentLoading] = useState(false); const api = useApi(); const toast = useToast(); - - - 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) => { + const handleConsent = useCallback(async (meetingId: string, given: boolean) => { if (!api) return; - if (onClose) onClose(); setConsentLoading(true); try { @@ -55,7 +31,7 @@ export default function Room(details: RoomDetails) { meetingId, requestBody: { consent_given: given } }); - + touch(meetingId); } catch (error) { console.error('Error submitting consent:', error); @@ -64,18 +40,6 @@ export default function Room(details: RoomDetails) { } }, [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 useEffect(() => { 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? - - @@ -119,6 +89,40 @@ export default function Room(details: RoomDetails) { }; } }, [consentState.ready, meetingId, hasConsent, consentLoading, toast, handleConsent]); +} + +function ConsentDialog({ meetingId }: { meetingId: string }) { + useConsentDialog(meetingId); + return <> +} + +export default function Room(details: RoomDetails) { + const wherebyRef = useRef(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(() => { if (isLoading || !isAuthenticated || !roomUrl) return; @@ -154,12 +158,15 @@ export default function Room(details: RoomDetails) { return ( <> - {roomUrl && ( - + {roomUrl && meetingId && ( + <> + + + )} );