2020-04-16 13:47:10 +03:00
|
|
|
import React from 'react';
|
2024-11-06 15:47:19 -06:00
|
|
|
import { useTranslation } from 'react-i18next';
|
|
|
|
|
import { useSelector } from 'react-redux';
|
2022-09-13 10:36:00 +03:00
|
|
|
import { makeStyles } from 'tss-react/mui';
|
2020-05-20 12:57:03 +02:00
|
|
|
|
2024-11-06 15:47:19 -06:00
|
|
|
import { ColorPalette } from '../../../../base/styles/components/styles/ColorPalette';
|
2023-01-30 13:34:56 +02:00
|
|
|
import { withPixelLineHeight } from '../../../../base/styles/functions.web';
|
2020-04-16 13:47:10 +03:00
|
|
|
import {
|
2022-09-27 10:10:28 +03:00
|
|
|
getDeviceStatusText,
|
|
|
|
|
getDeviceStatusType
|
2022-10-28 12:07:58 +02:00
|
|
|
} from '../../../functions';
|
2020-04-16 13:47:10 +03:00
|
|
|
|
2024-11-06 15:47:19 -06:00
|
|
|
const useStyles = makeStyles<{ deviceStatusType?: string; }>()((theme, { deviceStatusType = 'pending' }) => {
|
2022-03-15 14:18:05 +03:30
|
|
|
return {
|
|
|
|
|
deviceStatus: {
|
2023-01-30 13:34:56 +02:00
|
|
|
display: 'flex',
|
2022-03-15 14:18:05 +03:30
|
|
|
alignItems: 'center',
|
2023-01-30 13:34:56 +02:00
|
|
|
justifyContent: 'center',
|
|
|
|
|
...withPixelLineHeight(theme.typography.bodyShortRegular),
|
2022-03-15 14:18:05 +03:30
|
|
|
color: '#fff',
|
2023-01-30 13:34:56 +02:00
|
|
|
marginTop: theme.spacing(4),
|
2022-03-15 14:18:05 +03:30
|
|
|
|
|
|
|
|
'& 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 13:34:56 +02:00
|
|
|
textAlign: 'left',
|
|
|
|
|
marginTop: theme.spacing(2)
|
2022-03-15 14:18:05 +03:30
|
|
|
},
|
2023-01-30 13:34:56 +02:00
|
|
|
|
|
|
|
|
'@media (max-width: 720px)': {
|
|
|
|
|
marginTop: 0
|
2022-03-15 14:18:05 +03:30
|
|
|
}
|
2023-01-30 13:34:56 +02:00
|
|
|
},
|
|
|
|
|
indicator: {
|
|
|
|
|
width: '16px',
|
|
|
|
|
height: '16px',
|
|
|
|
|
borderRadius: '100%',
|
2024-11-06 15:47:19 -06:00
|
|
|
backgroundColor: deviceStatusType === 'ok' ? theme.palette.success01 : ColorPalette.darkGrey
|
2022-03-15 14:18:05 +03:30
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
});
|
|
|
|
|
|
2020-04-16 13:47:10 +03:00
|
|
|
/**
|
|
|
|
|
* Strip showing the current status of the devices.
|
|
|
|
|
* User is informed if there are missing or malfunctioning devices.
|
|
|
|
|
*
|
|
|
|
|
* @returns {ReactElement}
|
|
|
|
|
*/
|
2024-11-06 15:47:19 -06:00
|
|
|
function DeviceStatus() {
|
|
|
|
|
const { t } = useTranslation();
|
|
|
|
|
const deviceStatusType = useSelector(getDeviceStatusType);
|
|
|
|
|
const deviceStatusText = useSelector(getDeviceStatusText);
|
|
|
|
|
const { classes, cx } = useStyles({ deviceStatusType });
|
2021-09-17 13:12:34 +03:00
|
|
|
const hasError = deviceStatusType === 'warning';
|
2022-09-13 10:36:00 +03:00
|
|
|
const containerClassName = cx(classes.deviceStatus, { 'device-status-error': hasError });
|
2020-04-16 13:47:10 +03:00
|
|
|
|
|
|
|
|
return (
|
2021-06-10 14:48:44 +02:00
|
|
|
<div
|
2021-09-17 13:12:34 +03:00
|
|
|
className = { containerClassName }
|
2021-06-10 14:48:44 +02:00
|
|
|
role = 'alert'
|
|
|
|
|
tabIndex = { -1 }>
|
2023-01-30 13:34:56 +02:00
|
|
|
{!hasError && <div className = { classes.indicator } />}
|
2021-09-17 13:12:34 +03:00
|
|
|
<span role = 'heading'>
|
2022-10-17 12:28:04 +03:00
|
|
|
{hasError ? t('prejoin.errorNoPermissions') : t(deviceStatusText ?? '')}
|
2021-06-10 14:48:44 +02:00
|
|
|
</span>
|
2020-04-16 13:47:10 +03:00
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2024-11-06 15:47:19 -06:00
|
|
|
export default DeviceStatus;
|