From a22d052f4664a19a6f34d42b2d9cef5d01b8ba84 Mon Sep 17 00:00:00 2001 From: lebaudantoine Date: Mon, 7 Apr 2025 11:57:49 +0200 Subject: [PATCH] =?UTF-8?q?=E2=99=BB=EF=B8=8F(frontend)=20generalize=20rec?= =?UTF-8?q?ording=20availability=20hook=20for=20all=20types?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Extend recording availability and access hook to work with all recording types instead of being transcript-specific. Create flexible implementation that determines availability and permissions for screen recordings and future recording formats. --- .../features/rooms/livekit/components/Tools.tsx | 7 +++++-- .../rooms/livekit/components/Transcript.tsx | 7 +++++-- ...iptAccess.ts => useHasScreenRecordingAccess.ts} | 14 +++++++++----- ...riptEnabled.ts => useIsRecordingModeEnabled.ts} | 4 ++-- 4 files changed, 21 insertions(+), 11 deletions(-) rename src/frontend/src/features/rooms/livekit/hooks/{useHasTranscriptAccess.ts => useHasScreenRecordingAccess.ts} (50%) rename src/frontend/src/features/rooms/livekit/hooks/{useIsTranscriptEnabled.ts => useIsRecordingModeEnabled.ts} (61%) diff --git a/src/frontend/src/features/rooms/livekit/components/Tools.tsx b/src/frontend/src/features/rooms/livekit/components/Tools.tsx index ec58f6d7..8320d7b0 100644 --- a/src/frontend/src/features/rooms/livekit/components/Tools.tsx +++ b/src/frontend/src/features/rooms/livekit/components/Tools.tsx @@ -6,8 +6,9 @@ import { CRISP_HELP_ARTICLE_MORE_TOOLS } from '@/utils/constants' import { ReactNode } from 'react' import { Transcript } from './Transcript' import { RiFileTextFill } from '@remixicon/react' -import { useIsTranscriptEnabled } from '../hooks/useIsTranscriptEnabled' import { useSidePanel } from '../hooks/useSidePanel' +import { useIsRecordingModeEnabled } from '../hooks/useIsRecordingModeEnabled' +import { RecordingMode } from '@/features/rooms/api/startRecording' export interface ToolsButtonProps { icon: ReactNode @@ -70,7 +71,9 @@ const ToolButton = ({ export const Tools = () => { const { openTranscript, isTranscriptOpen } = useSidePanel() const { t } = useTranslation('rooms', { keyPrefix: 'moreTools' }) - const isTranscriptEnabled = useIsTranscriptEnabled() + const isTranscriptEnabled = useIsRecordingModeEnabled( + RecordingMode.Transcript + ) if (isTranscriptOpen && isTranscriptEnabled) { return diff --git a/src/frontend/src/features/rooms/livekit/components/Transcript.tsx b/src/frontend/src/features/rooms/livekit/components/Transcript.tsx index 31576309..c23c9b3d 100644 --- a/src/frontend/src/features/rooms/livekit/components/Transcript.tsx +++ b/src/frontend/src/features/rooms/livekit/components/Transcript.tsx @@ -16,7 +16,7 @@ import { NotificationPayload } from '@/features/notifications/NotificationPayloa import { NotificationType } from '@/features/notifications/NotificationType' import { useSnapshot } from 'valtio/index' import { RecordingStatus, recordingStore } from '@/stores/recording' -import { useHasTranscriptAccess } from '../hooks/useHasTranscriptAccess' +import { useHasRecordingAccess } from '../hooks/useHasScreenRecordingAccess' import { BETA_USERS_FORM_URL, CRISP_HELP_ARTICLE_TRANSCRIPT, @@ -26,7 +26,10 @@ export const Transcript = () => { const [isLoading, setIsLoading] = useState(false) const { t } = useTranslation('rooms', { keyPrefix: 'transcript' }) - const hasTranscriptAccess = useHasTranscriptAccess() + const hasTranscriptAccess = useHasRecordingAccess( + RecordingMode.Transcript, + 'transcription-summary' + ) const roomId = useRoomId() const { mutateAsync: startRecordingRoom } = useStartRecording() diff --git a/src/frontend/src/features/rooms/livekit/hooks/useHasTranscriptAccess.ts b/src/frontend/src/features/rooms/livekit/hooks/useHasScreenRecordingAccess.ts similarity index 50% rename from src/frontend/src/features/rooms/livekit/hooks/useHasTranscriptAccess.ts rename to src/frontend/src/features/rooms/livekit/hooks/useHasScreenRecordingAccess.ts index 731ba0ba..0f578b2e 100644 --- a/src/frontend/src/features/rooms/livekit/hooks/useHasTranscriptAccess.ts +++ b/src/frontend/src/features/rooms/livekit/hooks/useHasScreenRecordingAccess.ts @@ -1,17 +1,21 @@ import { useFeatureFlagEnabled } from 'posthog-js/react' import { useIsAnalyticsEnabled } from '@/features/analytics/hooks/useIsAnalyticsEnabled' -import { useIsTranscriptEnabled } from './useIsTranscriptEnabled' +import { RecordingMode } from '@/features/rooms/api/startRecording' +import { useIsRecordingModeEnabled } from './useIsRecordingModeEnabled' import { useIsAdminOrOwner } from './useIsAdminOrOwner' -export const useHasTranscriptAccess = () => { - const featureEnabled = useFeatureFlagEnabled('transcription-summary') +export const useHasRecordingAccess = ( + mode: RecordingMode, + featureFlag: string +) => { + const featureEnabled = useFeatureFlagEnabled(featureFlag) const isAnalyticsEnabled = useIsAnalyticsEnabled() - const isTranscriptEnabled = useIsTranscriptEnabled() + const isRecordingModeEnabled = useIsRecordingModeEnabled(mode) const isAdminOrOwner = useIsAdminOrOwner() return ( (featureEnabled || !isAnalyticsEnabled) && isAdminOrOwner && - isTranscriptEnabled + isRecordingModeEnabled ) } diff --git a/src/frontend/src/features/rooms/livekit/hooks/useIsTranscriptEnabled.ts b/src/frontend/src/features/rooms/livekit/hooks/useIsRecordingModeEnabled.ts similarity index 61% rename from src/frontend/src/features/rooms/livekit/hooks/useIsTranscriptEnabled.ts rename to src/frontend/src/features/rooms/livekit/hooks/useIsRecordingModeEnabled.ts index 085538e4..d94772c0 100644 --- a/src/frontend/src/features/rooms/livekit/hooks/useIsTranscriptEnabled.ts +++ b/src/frontend/src/features/rooms/livekit/hooks/useIsRecordingModeEnabled.ts @@ -1,11 +1,11 @@ import { RecordingMode } from '@/features/rooms/api/startRecording' import { useConfig } from '@/api/useConfig' -export const useIsTranscriptEnabled = () => { +export const useIsRecordingModeEnabled = (mode: RecordingMode) => { const { data } = useConfig() return ( data?.recording?.is_enabled && - data?.recording?.available_modes?.includes(RecordingMode.Transcript) + data?.recording?.available_modes?.includes(mode) ) }