jiti-meet/react/features/prejoin/components/web/preview/DeviceStatus.tsx

103 lines
3.0 KiB
TypeScript
Raw Normal View History

2020-04-16 10:47:10 +00:00
import React from 'react';
import { WithTranslation } from 'react-i18next';
2022-09-13 07:36:00 +00:00
import { makeStyles } from 'tss-react/mui';
2020-05-20 10:57:03 +00:00
import { IReduxState } from '../../../../app/types';
import { translate } from '../../../../base/i18n/functions';
import { connect } from '../../../../base/redux/functions';
2023-01-30 11:34:56 +00:00
import { withPixelLineHeight } from '../../../../base/styles/functions.web';
2020-04-16 10:47:10 +00:00
import {
getDeviceStatusText,
getDeviceStatusType
} from '../../../functions';
2020-04-16 10:47:10 +00:00
export interface IProps extends WithTranslation {
2020-04-16 10:47:10 +00:00
/**
* The text to be displayed in relation to the status of the audio/video devices.
*/
deviceStatusText?: string;
2020-04-16 10:47:10 +00:00
/**
* The type of status for current devices, controlling the background color of the text.
* Can be `ok` or `warning`.
*/
deviceStatusType?: string;
}
2020-04-16 10:47:10 +00:00
const useStyles = makeStyles()(theme => {
return {
deviceStatus: {
2023-01-30 11:34:56 +00:00
display: 'flex',
alignItems: 'center',
2023-01-30 11:34:56 +00:00
justifyContent: 'center',
...withPixelLineHeight(theme.typography.bodyShortRegular),
color: '#fff',
2023-01-30 11:34:56 +00:00
marginTop: theme.spacing(4),
'& span': {
marginLeft: theme.spacing(3)
},
'&.device-status-error': {
alignItems: 'flex-start',
backgroundColor: theme.palette.warning01,
borderRadius: '6px',
color: theme.palette.uiBackground,
padding: '12px 16px',
2023-01-30 11:34:56 +00:00
textAlign: 'left',
marginTop: theme.spacing(2)
},
2023-01-30 11:34:56 +00:00
'@media (max-width: 720px)': {
marginTop: 0
}
2023-01-30 11:34:56 +00:00
},
indicator: {
width: '16px',
height: '16px',
borderRadius: '100%',
backgroundColor: theme.palette.success01
}
};
});
2020-04-16 10:47:10 +00:00
/**
* Strip showing the current status of the devices.
* User is informed if there are missing or malfunctioning devices.
*
* @returns {ReactElement}
*/
function DeviceStatus({ deviceStatusType, deviceStatusText, t }: IProps) {
2022-09-13 07:36:00 +00:00
const { classes, cx } = useStyles();
const hasError = deviceStatusType === 'warning';
2022-09-13 07:36:00 +00:00
const containerClassName = cx(classes.deviceStatus, { 'device-status-error': hasError });
2020-04-16 10:47:10 +00:00
return (
<div
className = { containerClassName }
role = 'alert'
tabIndex = { -1 }>
2023-01-30 11:34:56 +00:00
{!hasError && <div className = { classes.indicator } />}
<span role = 'heading'>
{hasError ? t('prejoin.errorNoPermissions') : t(deviceStatusText ?? '')}
</span>
2020-04-16 10:47:10 +00:00
</div>
);
}
/**
* Maps (parts of) the redux state to the React {@code Component} props.
*
* @param {Object} state - The redux state.
* @returns {{ deviceStatusText: string, deviceStatusText: string }}
*/
function mapStateToProps(state: IReduxState) {
2020-04-16 10:47:10 +00:00
return {
deviceStatusText: getDeviceStatusText(state),
deviceStatusType: getDeviceStatusType(state)
2020-04-16 10:47:10 +00:00
};
}
export default translate(connect(mapStateToProps)(DeviceStatus));