aboutsummaryrefslogtreecommitdiffstats
path: root/src/components/settings/services/ServiceItem.tsx
blob: 7df59f1d25818c2de115e1301abab33b3f6ae474 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
import { mdiBellOff, mdiMessageBulletedOff, mdiPower } from '@mdi/js';
import classnames from 'classnames';
import { observer } from 'mobx-react';
import { Component, type ReactElement } from 'react';
import {
  type WrappedComponentProps,
  defineMessages,
  injectIntl,
} from 'react-intl';
import { Tooltip as ReactTooltip } from 'react-tooltip';
import type ServiceModel from '../../../models/Service';
import Icon from '../../ui/icon';

const messages = defineMessages({
  tooltipIsDisabled: {
    id: 'settings.services.tooltip.isDisabled',
    defaultMessage: 'Service is disabled',
  },
  tooltipNotificationsDisabled: {
    id: 'settings.services.tooltip.notificationsDisabled',
    defaultMessage: 'Notifications are disabled',
  },
  tooltipIsMuted: {
    id: 'settings.services.tooltip.isMuted',
    defaultMessage: 'All sounds are muted',
  },
});

interface IProps extends WrappedComponentProps {
  service: ServiceModel;
  goToServiceForm: () => void;
}

@observer
class ServiceItem extends Component<IProps> {
  render(): ReactElement {
    const {
      service,
      // toggleAction, // TODO: [TECH DEBT][PROP NOT USED IN COMPONENT] check it later
      goToServiceForm,
    } = this.props;
    const { intl } = this.props;

    return (
      <tr
        className={classnames({
          'service-table__row': true,
          'service-table__row--disabled': !service.isEnabled,
        })}
      >
        <td className="service-table__column-icon" onClick={goToServiceForm}>
          <img
            src={service.icon}
            className={classnames({
              'service-table__icon': true,
              'has-custom-icon': service.hasCustomIcon,
            })}
            alt=""
          />
        </td>
        <td className="service-table__column-name" onClick={goToServiceForm}>
          {service.name === '' ? service.recipe.name : service.name}
        </td>
        <td className="service-table__column-info" onClick={goToServiceForm}>
          {service.isMuted && (
            <Icon
              icon={mdiBellOff}
              data-tooltip-id="tooltip-service-item"
              data-tooltip-content={intl.formatMessage(messages.tooltipIsMuted)}
            />
          )}
        </td>
        <td className="service-table__column-info" onClick={goToServiceForm}>
          {!service.isEnabled && (
            <Icon
              icon={mdiPower}
              data-tooltip-id="tooltip-service-item"
              data-tooltip-content={intl.formatMessage(
                messages.tooltipIsDisabled,
              )}
            />
          )}
        </td>
        <td className="service-table__column-info" onClick={goToServiceForm}>
          {!service.isNotificationEnabled && (
            <Icon
              icon={mdiMessageBulletedOff}
              data-tooltip-id="tooltip-service-item"
              data-tooltip-content={intl.formatMessage(
                messages.tooltipNotificationsDisabled,
              )}
            />
          )}
          <ReactTooltip
            id="tooltip-service-item"
            place="right"
            variant="dark"
            style={{ height: 'auto' }}
          />
        </td>
      </tr>
    );
  }
}

export default injectIntl(ServiceItem);