You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

DeviceStatus.tsx 2.5KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. import React from 'react';
  2. import { useTranslation } from 'react-i18next';
  3. import { useSelector } from 'react-redux';
  4. import { makeStyles } from 'tss-react/mui';
  5. import { ColorPalette } from '../../../../base/styles/components/styles/ColorPalette';
  6. import { withPixelLineHeight } from '../../../../base/styles/functions.web';
  7. import {
  8. getDeviceStatusText,
  9. getDeviceStatusType
  10. } from '../../../functions';
  11. const useStyles = makeStyles<{ deviceStatusType?: string; }>()((theme, { deviceStatusType = 'pending' }) => {
  12. return {
  13. deviceStatus: {
  14. display: 'flex',
  15. alignItems: 'center',
  16. justifyContent: 'center',
  17. ...withPixelLineHeight(theme.typography.bodyShortRegular),
  18. color: '#fff',
  19. marginTop: theme.spacing(4),
  20. '& span': {
  21. marginLeft: theme.spacing(3)
  22. },
  23. '&.device-status-error': {
  24. alignItems: 'flex-start',
  25. backgroundColor: theme.palette.warning01,
  26. borderRadius: '6px',
  27. color: theme.palette.uiBackground,
  28. padding: '12px 16px',
  29. textAlign: 'left',
  30. marginTop: theme.spacing(2)
  31. },
  32. '@media (max-width: 720px)': {
  33. marginTop: 0
  34. }
  35. },
  36. indicator: {
  37. width: '16px',
  38. height: '16px',
  39. borderRadius: '100%',
  40. backgroundColor: deviceStatusType === 'ok' ? theme.palette.success01 : ColorPalette.darkGrey
  41. }
  42. };
  43. });
  44. /**
  45. * Strip showing the current status of the devices.
  46. * User is informed if there are missing or malfunctioning devices.
  47. *
  48. * @returns {ReactElement}
  49. */
  50. function DeviceStatus() {
  51. const { t } = useTranslation();
  52. const deviceStatusType = useSelector(getDeviceStatusType);
  53. const deviceStatusText = useSelector(getDeviceStatusText);
  54. const { classes, cx } = useStyles({ deviceStatusType });
  55. const hasError = deviceStatusType === 'warning';
  56. const containerClassName = cx(classes.deviceStatus, { 'device-status-error': hasError });
  57. return (
  58. <div
  59. className = { containerClassName }
  60. role = 'alert'
  61. tabIndex = { -1 }>
  62. {!hasError && <div className = { classes.indicator } />}
  63. <span role = 'heading'>
  64. {hasError ? t('prejoin.errorNoPermissions') : t(deviceStatusText ?? '')}
  65. </span>
  66. </div>
  67. );
  68. }
  69. export default DeviceStatus;