aboutsummaryrefslogtreecommitdiffstats
path: root/src/components/services/content/ConnectionLostBanner.tsx
blob: 7040337f020110904e5beaa09eb78219fe11580e (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
import { Component, ReactElement } from 'react';
import { observer } from 'mobx-react';
import withStyles, { WithStylesProps } from 'react-jss';
import { defineMessages, injectIntl, WrappedComponentProps } from 'react-intl';
import { mdiAlert } from '@mdi/js';
import { LIVE_API_FERDIUM_WEBSITE } from '../../../config';
import Icon from '../../ui/icon';

const messages = defineMessages({
  text: {
    id: 'connectionLostBanner.message',
    defaultMessage: 'Oh no! Ferdium lost the connection to {name}.',
  },
  moreInformation: {
    id: 'connectionLostBanner.informationLink',
    defaultMessage: 'What happened?',
  },
  cta: {
    id: 'connectionLostBanner.cta',
    defaultMessage: 'Reload Service',
  },
});

const buttonTransition = window?.matchMedia(
  '(prefers-reduced-motion: no-preference)',
)
  ? 'opacity 0.25s'
  : 'none';

const styles = theme => ({
  root: {
    background: theme.colorBackground,
    borderRadius: theme.borderRadius,
    position: 'absolute',
    zIndex: 300,
    height: 50,
    display: 'flex',
    flexDirection: 'row',
    alignItems: 'center',
    bottom: 10,
    right: 10,
    justifyContent: 'center',
    padding: 10,
    fontSize: 12,
  },
  link: {
    display: 'inline-flex',
    opacity: 0.7,
  },
  button: {
    transition: buttonTransition,
    color: theme.colorText,
    border: [1, 'solid', theme.colorText],
    borderRadius: theme.borderRadiusSmall,
    padding: 4,
    fontSize: 12,
    marginLeft: 15,

    '&:hover': {
      opacity: 0.8,
    },
  },
  icon: {
    marginRight: 10,
    fill: theme.styleTypes.danger.accent,
  },
});

interface IProps extends WithStylesProps<typeof styles>, WrappedComponentProps {
  name: string;
  reload: () => void;
}

@observer
class ConnectionLostBanner extends Component<IProps> {
  render(): ReactElement {
    const { classes, name, reload, intl } = this.props;

    return (
      <div className={classes.root}>
        <Icon icon={mdiAlert} className={classes.icon} />
        <p>
          {intl.formatMessage(messages.text, { name })}
          <br />
          <a
            href={`${LIVE_API_FERDIUM_WEBSITE}/support#what-does-franz-lost-the-connection-to-service-mean`}
            className={classes.link}
          >
            {intl.formatMessage(messages.moreInformation)}
          </a>
        </p>
        <button type="button" className={classes.button} onClick={reload}>
          {intl.formatMessage(messages.cta)}
        </button>
      </div>
    );
  }
}

export default injectIntl(withStyles(styles)(ConnectionLostBanner));