From 910463103bb1fe15851f4e8561a2e6146d425ec3 Mon Sep 17 00:00:00 2001 From: Anthony Le Courric Date: Wed, 20 Dec 2023 15:03:22 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B(lib-video)=20intl=20not=20accessib?= =?UTF-8?q?le=20from=20toast.custom?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When we load a component from a toast.custom, we can't access the intl object, the ancestor tree is lost. We need to pass it down explicitly. --- .../OnStageRequestToast/index.spec.tsx | 7 ++++- .../Wrapper/OnStageRequestToast/index.tsx | 26 ++++++------------- .../components/live/Teacher/Wrapper/index.tsx | 19 +++++++++++++- 3 files changed, 32 insertions(+), 20 deletions(-) diff --git a/src/frontend/packages/lib_video/src/components/live/Teacher/Wrapper/OnStageRequestToast/index.spec.tsx b/src/frontend/packages/lib_video/src/components/live/Teacher/Wrapper/OnStageRequestToast/index.spec.tsx index 0908435785..1c9325db14 100644 --- a/src/frontend/packages/lib_video/src/components/live/Teacher/Wrapper/OnStageRequestToast/index.spec.tsx +++ b/src/frontend/packages/lib_video/src/components/live/Teacher/Wrapper/OnStageRequestToast/index.spec.tsx @@ -23,7 +23,12 @@ describe('', () => { setPanelVisibility: mockSetPanelVisibility, }); - render(); + render( + , + ); screen.getByText( `${participants[1].name} and ${participants[0].name} want to go on stage.`, diff --git a/src/frontend/packages/lib_video/src/components/live/Teacher/Wrapper/OnStageRequestToast/index.tsx b/src/frontend/packages/lib_video/src/components/live/Teacher/Wrapper/OnStageRequestToast/index.tsx index 94e8b87bd1..02972d6360 100644 --- a/src/frontend/packages/lib_video/src/components/live/Teacher/Wrapper/OnStageRequestToast/index.tsx +++ b/src/frontend/packages/lib_video/src/components/live/Teacher/Wrapper/OnStageRequestToast/index.tsx @@ -1,51 +1,41 @@ import { colorsTokens } from '@lib-common/cunningham'; import { Button } from '@openfun/cunningham-react'; -import { Box, Participant, Text } from 'lib-components'; +import { Box, Text } from 'lib-components'; import React from 'react'; import toast from 'react-hot-toast'; -import { defineMessages, useIntl } from 'react-intl'; import { LivePanelItem, useLivePanelState, } from '@lib-video/hooks/useLivePanelState'; -import { onStageRequestMessage } from '@lib-video/utils/onStageRequestMessage'; - -const messages = defineMessages({ - manageRequestBtnLabel: { - defaultMessage: 'Manage requests', - description: - 'Label of the button used for opening the manage on-stage request tab.', - id: 'component.DashboardLive.manageRequestBtnLabel', - }, -}); interface OnStageRequestToastProps { - participantsList: Participant[]; + buttonLabel: string; + message: string; } export const ON_STAGE_REQUEST_TOAST_ID = 'onStageRequestToastId'; export const OnStageRequestToast = ({ - participantsList, + buttonLabel, + message, }: OnStageRequestToastProps) => { - const intl = useIntl(); const { setPanelVisibility } = useLivePanelState((state) => ({ setPanelVisibility: state.setPanelVisibility, })); return ( - {onStageRequestMessage(participantsList, intl)} + {message} ); diff --git a/src/frontend/packages/lib_video/src/components/live/Teacher/Wrapper/index.tsx b/src/frontend/packages/lib_video/src/components/live/Teacher/Wrapper/index.tsx index f3d746ec7d..6134a98952 100644 --- a/src/frontend/packages/lib_video/src/components/live/Teacher/Wrapper/index.tsx +++ b/src/frontend/packages/lib_video/src/components/live/Teacher/Wrapper/index.tsx @@ -7,6 +7,7 @@ import { } from 'lib-components'; import React, { Fragment, useEffect, useRef, useState } from 'react'; import { toast } from 'react-hot-toast'; +import { defineMessages, useIntl } from 'react-intl'; import { TeacherVideoInfoBar } from '@lib-video/components/common/TeacherVideoInfoBar'; import { VideoLayout } from '@lib-video/components/common/VideoLayout'; @@ -19,6 +20,7 @@ import { useLivePanelState, } from '@lib-video/hooks/useLivePanelState'; import { usePictureInPicture } from '@lib-video/hooks/usePictureInPicture'; +import { onStageRequestMessage } from '@lib-video/utils/onStageRequestMessage'; import { converse } from '@lib-video/utils/window'; import { DashboardControlPane } from '../../../common/DashboardControlPane'; @@ -31,7 +33,17 @@ import { } from './OnStageRequestToast'; import { TeacherLiveTypeSwitch } from './TeacherLiveTypeSwitch'; +const messages = defineMessages({ + manageRequestBtnLabel: { + defaultMessage: 'Manage requests', + description: + 'Label of the button used for opening the manage on-stage request tab.', + id: 'component.DashboardLive.manageRequestBtnLabel', + }, +}); + export const TeacherLiveWrapper = () => { + const intl = useIntl(); const live = useCurrentLive(); const appData = useAppConfig(); const [showPanelTrigger, setShowPanelTrigger] = useState(true); @@ -139,7 +151,11 @@ export const TeacherLiveWrapper = () => { if (shouldDisplayToast) { toast.custom( , { id: ON_STAGE_REQUEST_TOAST_ID, @@ -153,6 +169,7 @@ export const TeacherLiveWrapper = () => { live.join_mode, isPanelVisible, currentItem, + intl, ]); return (