import React, { useState } from 'react'; import PropTypes from 'prop-types'; import { defineMessages, injectIntl } from 'react-intl'; import { LAYOUT_TYPE, CAMERADOCK_POSITION, HIDDEN_LAYOUTS } from '/imports/ui/components/layout/enums'; import SettingsService from '/imports/ui/components/settings/service'; import deviceInfo from '/imports/utils/deviceInfo'; import Button from '/imports/ui/components/common/button/component'; import Styled from './styles'; const LayoutModalComponent = (props) => { const { intl, setIsOpen, isModerator, isPresenter, application, updateSettings, onRequestClose, isOpen, setLocalSettings, } = props; const [selectedLayout, setSelectedLayout] = useState(application.selectedLayout); const [updateAllUsed, setUpdateAllUsed] = useState(false); const BASE_NAME = window.meetingClientSettings.public.app.basename; const LAYOUTS_PATH = `${BASE_NAME}/resources/images/layouts/`; const isKeepPushingLayoutEnabled = SettingsService.isKeepPushingLayoutEnabled(); const intlMessages = defineMessages({ title: { id: 'app.layout.modal.title', description: 'Modal title', }, update: { id: 'app.layout.modal.update', description: 'Modal confirm button', }, updateAll: { id: 'app.layout.modal.updateAll', description: 'Modal updateAll button', }, layoutLabel: { id: 'app.layout.modal.layoutLabel', description: 'Layout label', }, layoutToastLabelAuto: { id: 'app.layout.modal.layoutToastLabelAuto', description: 'Layout toast label', }, layoutToastLabelAutoOff: { id: 'app.layout.modal.layoutToastLabelAutoOff', description: 'Layout toast label', }, layoutToastLabel: { id: 'app.layout.modal.layoutToastLabel', description: 'Layout toast label', }, customLayout: { id: 'app.layout.style.custom', description: 'label for custom layout style', }, smartLayout: { id: 'app.layout.style.smart', description: 'label for smart layout style', }, presentationFocusLayout: { id: 'app.layout.style.presentationFocus', description: 'label for presentationFocus layout style', }, videoFocusLayout: { id: 'app.layout.style.videoFocus', description: 'label for videoFocus layout style', }, layoutSingular: { id: 'app.layout.modal.layoutSingular', description: 'label for singular layout', }, layoutBtnDesc: { id: 'app.layout.modal.layoutBtnDesc', description: 'label for singular layout', }, }); const handleSwitchLayout = (e) => { setSelectedLayout(e); }; const handleUpdateLayout = (updateAll) => { const obj = { application: { ...application, selectedLayout, pushLayout: updateAll }, }; if ((isModerator || isPresenter) && updateAll) { updateSettings(obj, intlMessages.layoutToastLabelAuto); setUpdateAllUsed(true); } else if ((isModerator || isPresenter) && !updateAll && !updateAllUsed) { updateSettings(obj, intlMessages.layoutToastLabelAutoOff); setUpdateAllUsed(false); } else { updateSettings(obj, intlMessages.layoutToastLabel); } updateSettings(obj, intlMessages.layoutToastLabel, setLocalSettings); setIsOpen(false); }; const renderPushLayoutsOptions = () => { if (!isModerator && !isPresenter) { return null; } if (isKeepPushingLayoutEnabled) { return ( handleUpdateLayout(true)} color="secondary" data-test="updateEveryoneLayoutBtn" /> ); } return null; }; const renderLayoutButtons = () => ( {Object.values(LAYOUT_TYPE) .filter((layout) => !HIDDEN_LAYOUTS.includes(layout)) .map((layout) => ( )} onClick={() => { handleSwitchLayout(layout); if (layout === LAYOUT_TYPE.CUSTOM_LAYOUT && application.selectedLayout !== layout) { document.getElementById('layout')?.setAttribute('data-cam-position', CAMERADOCK_POSITION.CONTENT_TOP); } }} active={(layout === selectedLayout).toString()} aria-describedby="layout-btn-desc" data-test={`${layout}Layout`} /> {intl.formatMessage(intlMessages[`${layout}Layout`])} ))} ); return ( setIsOpen(false)} title={intl.formatMessage(intlMessages.title)} {...{ isOpen, onRequestClose, }} > {renderLayoutButtons()} {renderPushLayoutsOptions()}