aboutsummaryrefslogtreecommitdiffstats
path: root/packages/renderer/src/components/banner/InsecureConnectionBanner.tsx
diff options
context:
space:
mode:
Diffstat (limited to 'packages/renderer/src/components/banner/InsecureConnectionBanner.tsx')
-rw-r--r--packages/renderer/src/components/banner/InsecureConnectionBanner.tsx92
1 files changed, 92 insertions, 0 deletions
diff --git a/packages/renderer/src/components/banner/InsecureConnectionBanner.tsx b/packages/renderer/src/components/banner/InsecureConnectionBanner.tsx
new file mode 100644
index 0000000..7a03fce
--- /dev/null
+++ b/packages/renderer/src/components/banner/InsecureConnectionBanner.tsx
@@ -0,0 +1,92 @@
1/*
2 * Copyright (C) 2022 Kristóf Marussy <kristof@marussy.com>
3 *
4 * This file is part of Sophie.
5 *
6 * Sophie is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU Affero General Public License as
8 * published by the Free Software Foundation, version 3.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU Affero General Public License for more details.
14 *
15 * You should have received a copy of the GNU Affero General Public License
16 * along with this program. If not, see <https://www.gnu.org/licenses/>.
17 *
18 * SPDX-License-Identifier: AGPL-3.0-only
19 */
20
21import CableIcon from '@mui/icons-material/Cable';
22import ErrorOutlineIcon from '@mui/icons-material/ErrorOutline';
23import HomeIcon from '@mui/icons-material/HomeOutlined';
24import Button from '@mui/material/Button';
25import { SecurityLabelKind } from '@sophie/shared';
26import { observer } from 'mobx-react-lite';
27import React from 'react';
28import { useTranslation } from 'react-i18next';
29
30import type Service from '../../stores/Service';
31
32import NotificationBanner from './NotificationBanner';
33
34function InsecureConnectionBanner({
35 service,
36}: {
37 service: Service | undefined;
38}): JSX.Element | null {
39 const { t } = useTranslation(undefined, {
40 keyPrefix: 'banner.insecureConnection',
41 });
42
43 if (service === undefined) {
44 // eslint-disable-next-line unicorn/no-null -- React requires `null` to skip rendering.
45 return null;
46 }
47
48 const {
49 canReconnectSecurely,
50 hasError,
51 securityLabel,
52 settings: { name: serviceName },
53 } = service;
54
55 if (securityLabel !== SecurityLabelKind.NotSecureConnection || hasError) {
56 // eslint-disable-next-line unicorn/no-null -- React requires `null` to skip rendering.
57 return null;
58 }
59
60 return (
61 <NotificationBanner
62 severity="error"
63 icon={<ErrorOutlineIcon fontSize="inherit" />}
64 buttons={
65 <>
66 <Button
67 onClick={() => service.goHome()}
68 color="inherit"
69 size="small"
70 startIcon={<HomeIcon />}
71 >
72 {t('home', { serviceName })}
73 </Button>
74 {canReconnectSecurely && (
75 <Button
76 onClick={() => service.reconnectSecurely()}
77 color="inherit"
78 size="small"
79 startIcon={<CableIcon />}
80 >
81 {t('reconnectSecurely')}
82 </Button>
83 )}
84 </>
85 }
86 >
87 {t('message')}
88 </NotificationBanner>
89 );
90}
91
92export default observer(InsecureConnectionBanner);