consent context vibe

This commit is contained in:
Igor Loskutov
2025-06-17 17:47:04 -04:00
parent 91c7c8b83a
commit 2ac92b2d67
6 changed files with 52 additions and 23 deletions

View File

@@ -1,2 +1,4 @@
- non-auth user consent - store on frontend per session? per meeting? (get meeting from the iframe) - consent popup itself - make much less invasive, somewhere in the corner
- consent field userIdentity itself - optional - non-auth user consent AND AUTH user consent - store on frontend per session - per meeting? (get meeting from the iframe)
- actually delete aws
- add externalId to the iframe with the logged in user

View File

@@ -13,7 +13,7 @@ import useMp3 from "../../useMp3";
import WaveformLoading from "../../waveformLoading"; import WaveformLoading from "../../waveformLoading";
import { Box, Text, Grid, Heading, VStack, Flex } from "@chakra-ui/react"; import { Box, Text, Grid, Heading, VStack, Flex } from "@chakra-ui/react";
import LiveTrancription from "../../liveTranscription"; import LiveTrancription from "../../liveTranscription";
import AudioConsentDialog from "../../components/AudioConsentDialog"; import AudioConsentDialog from "../../../rooms/audioConsentDialog";
import useApi from "../../../../lib/useApi"; import useApi from "../../../../lib/useApi";
type TranscriptDetails = { type TranscriptDetails = {

View File

@@ -133,6 +133,8 @@ const ShareModal = (props: ShareModalProps) => {
setStream(val.toString()); setStream(val.toString());
}} }}
placeholder="Pick a stream" placeholder="Pick a stream"
onBlur={() => {}}
onFocus={() => {}}
/> />
</div> </div>
@@ -145,6 +147,8 @@ const ShareModal = (props: ShareModalProps) => {
value={topic} value={topic}
onChange={(val) => setTopic(val.toString())} onChange={(val) => setTopic(val.toString())}
placeholder="Pick a topic" placeholder="Pick a topic"
onBlur={() => {}}
onFocus={() => {}}
/> />
</div> </div>
)} )}

View File

@@ -177,6 +177,8 @@ const TranscriptCreate = () => {
value={targetLanguage} value={targetLanguage}
onChange={onLanguageChange} onChange={onLanguageChange}
placeholder="Choose your language" placeholder="Choose your language"
onBlur={() => {}}
onFocus={() => {}}
/> />
</Box> </Box>
{isClient && !loading ? ( {isClient && !loading ? (

View File

@@ -9,6 +9,7 @@ import { notFound } from "next/navigation";
import useSessionStatus from "../lib/useSessionStatus"; import useSessionStatus from "../lib/useSessionStatus";
import AudioConsentDialog from "../(app)/rooms/audioConsentDialog"; import AudioConsentDialog from "../(app)/rooms/audioConsentDialog";
import { DomainContext } from "../domainContext"; import { DomainContext } from "../domainContext";
import { useRecordingConsent } from "../recordingConsentContext";
import useSessionAccessToken from "../lib/useSessionAccessToken"; import useSessionAccessToken from "../lib/useSessionAccessToken";
import useSessionUser from "../lib/useSessionUser"; import useSessionUser from "../lib/useSessionUser";
@@ -25,7 +26,8 @@ export default function Room(details: RoomDetails) {
const router = useRouter(); const router = useRouter();
const { isLoading, isAuthenticated } = useSessionStatus(); const { isLoading, isAuthenticated } = useSessionStatus();
const [showConsentDialog, setShowConsentDialog] = useState(false); const [showConsentDialog, setShowConsentDialog] = useState(false);
const [consentGiven, setConsentGiven] = useState<boolean | null>(null); const [consentLoading, setConsentLoading] = useState(false);
const { state: consentState, touch, hasConsent } = useRecordingConsent();
const { api_url } = useContext(DomainContext); const { api_url } = useContext(DomainContext);
const { accessToken } = useSessionAccessToken(); const { accessToken } = useSessionAccessToken();
const { id: userId } = useSessionUser(); const { id: userId } = useSessionUser();
@@ -35,6 +37,8 @@ export default function Room(details: RoomDetails) {
? meeting?.response?.host_room_url ? meeting?.response?.host_room_url
: meeting?.response?.room_url; : meeting?.response?.room_url;
const meetingId = meeting?.response?.id;
const handleLeave = useCallback(() => { const handleLeave = useCallback(() => {
router.push("/browse"); router.push("/browse");
}, [router]); }, [router]);
@@ -48,9 +52,9 @@ export default function Room(details: RoomDetails) {
return null; return null;
}, [isAuthenticated, userId]); }, [isAuthenticated, userId]);
const handleConsent = useCallback(async (given: boolean) => { const handleConsent = useCallback(async (meetingId: string, given: boolean) => {
setConsentGiven(given); setConsentLoading(true);
setShowConsentDialog(false); // Close dialog after consent is given setShowConsentDialog(false); // Close dialog immediately
if (meeting?.response?.id && api_url) { if (meeting?.response?.id && api_url) {
try { try {
@@ -73,14 +77,20 @@ export default function Room(details: RoomDetails) {
body: JSON.stringify(requestBody), body: JSON.stringify(requestBody),
}); });
if (!response.ok) { if (response.ok) {
touch(meetingId);
} else {
console.error('Failed to submit consent'); console.error('Failed to submit consent');
} }
} catch (error) { } catch (error) {
console.error('Error submitting consent:', error); console.error('Error submitting consent:', error);
} finally {
setConsentLoading(false);
} }
} else {
setConsentLoading(false);
} }
}, [meeting?.response?.id, api_url, accessToken]); }, [meeting?.response?.id, api_url, accessToken, touch, getUserIdentifier]);
useEffect(() => { useEffect(() => {
@@ -94,12 +104,18 @@ export default function Room(details: RoomDetails) {
} }
}, [isLoading, meeting?.error]); }, [isLoading, meeting?.error]);
// Show consent dialog when meeting is loaded and consent hasn't been given yet // Show consent dialog when meeting is loaded and consent hasn't been answered yet
useEffect(() => { useEffect(() => {
if (meeting?.response?.id && consentGiven === null && !showConsentDialog) { if (
consentState.ready &&
meetingId &&
!hasConsent(meetingId) &&
!showConsentDialog &&
!consentLoading
) {
setShowConsentDialog(true); setShowConsentDialog(true);
} }
}, [meeting?.response?.id, consentGiven, showConsentDialog]); }, [consentState.ready, meetingId, hasConsent, showConsentDialog, consentLoading]);
useEffect(() => { useEffect(() => {
if (isLoading || !isAuthenticated || !roomUrl) return; if (isLoading || !isAuthenticated || !roomUrl) return;
@@ -142,11 +158,13 @@ export default function Room(details: RoomDetails) {
style={{ width: "100vw", height: "100vh" }} style={{ width: "100vw", height: "100vh" }}
/> />
)} )}
<AudioConsentDialog {meetingId && consentState.ready && !hasConsent(meetingId) && !consentLoading && (
isOpen={showConsentDialog} <AudioConsentDialog
onClose={() => {}} // No-op: ESC should not close without consent isOpen={showConsentDialog}
onConsent={handleConsent} onClose={() => {}} // No-op: ESC should not close without consent
/> onConsent={b => handleConsent(meetingId, b)}
/>
)}
</> </>
); );
} }

View File

@@ -4,6 +4,7 @@ import SessionProvider from "./lib/SessionProvider";
import { ErrorProvider } from "./(errors)/errorContext"; import { ErrorProvider } from "./(errors)/errorContext";
import ErrorMessage from "./(errors)/errorMessage"; import ErrorMessage from "./(errors)/errorMessage";
import { DomainContextProvider } from "./domainContext"; import { DomainContextProvider } from "./domainContext";
import { RecordingConsentProvider } from "./recordingConsentContext";
import { getConfig } from "./lib/edgeConfig"; import { getConfig } from "./lib/edgeConfig";
import { ErrorBoundary } from "@sentry/nextjs"; import { ErrorBoundary } from "@sentry/nextjs";
import { Providers } from "./providers"; import { Providers } from "./providers";
@@ -68,12 +69,14 @@ export default async function RootLayout({
<body className={"h-[100svh] w-[100svw] overflow-x-hidden relative"}> <body className={"h-[100svh] w-[100svw] overflow-x-hidden relative"}>
<SessionProvider> <SessionProvider>
<DomainContextProvider config={config}> <DomainContextProvider config={config}>
<ErrorBoundary fallback={<p>"something went really wrong"</p>}> <RecordingConsentProvider>
<ErrorProvider> <ErrorBoundary fallback={<p>"something went really wrong"</p>}>
<ErrorMessage /> <ErrorProvider>
<Providers>{children}</Providers> <ErrorMessage />
</ErrorProvider> <Providers>{children}</Providers>
</ErrorBoundary> </ErrorProvider>
</ErrorBoundary>
</RecordingConsentProvider>
</DomainContextProvider> </DomainContextProvider>
</SessionProvider> </SessionProvider>
</body> </body>