diff options
Diffstat (limited to 'packages/renderer/src/components/banner/InsecureConnectionBanner.tsx')
-rw-r--r-- | packages/renderer/src/components/banner/InsecureConnectionBanner.tsx | 87 |
1 files changed, 87 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..6165153 --- /dev/null +++ b/packages/renderer/src/components/banner/InsecureConnectionBanner.tsx | |||
@@ -0,0 +1,87 @@ | |||
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 | |||
21 | import CableIcon from '@mui/icons-material/Cable'; | ||
22 | import ErrorOutlineIcon from '@mui/icons-material/ErrorOutline'; | ||
23 | import HomeIcon from '@mui/icons-material/HomeOutlined'; | ||
24 | import Button from '@mui/material/Button'; | ||
25 | import { SecurityLabelKind } from '@sophie/shared'; | ||
26 | import { observer } from 'mobx-react-lite'; | ||
27 | import React from 'react'; | ||
28 | import { useTranslation } from 'react-i18next'; | ||
29 | |||
30 | import type Service from '../../stores/Service.js'; | ||
31 | |||
32 | import NotificationBanner from './NotificationBanner.js'; | ||
33 | |||
34 | function InsecureConnectionBanner({ | ||
35 | service, | ||
36 | }: { | ||
37 | service: Service; | ||
38 | }): JSX.Element | null { | ||
39 | const { t } = useTranslation(undefined, { | ||
40 | keyPrefix: 'banner.insecureConnection', | ||
41 | }); | ||
42 | |||
43 | const { | ||
44 | canReconnectSecurely, | ||
45 | hasError, | ||
46 | securityLabel, | ||
47 | settings: { name: serviceName }, | ||
48 | } = service; | ||
49 | |||
50 | if (securityLabel !== SecurityLabelKind.NotSecureConnection || hasError) { | ||
51 | // eslint-disable-next-line unicorn/no-null -- React requires `null` to skip rendering. | ||
52 | return null; | ||
53 | } | ||
54 | |||
55 | return ( | ||
56 | <NotificationBanner | ||
57 | severity="error" | ||
58 | icon={<ErrorOutlineIcon fontSize="inherit" />} | ||
59 | buttons={ | ||
60 | <> | ||
61 | <Button | ||
62 | onClick={() => service.goHome()} | ||
63 | color="inherit" | ||
64 | size="small" | ||
65 | startIcon={<HomeIcon />} | ||
66 | > | ||
67 | {t('home', { serviceName })} | ||
68 | </Button> | ||
69 | {canReconnectSecurely && ( | ||
70 | <Button | ||
71 | onClick={() => service.reconnectSecurely()} | ||
72 | color="inherit" | ||
73 | size="small" | ||
74 | startIcon={<CableIcon />} | ||
75 | > | ||
76 | {t('reconnectSecurely')} | ||
77 | </Button> | ||
78 | )} | ||
79 | </> | ||
80 | } | ||
81 | > | ||
82 | {t('message')} | ||
83 | </NotificationBanner> | ||
84 | ); | ||
85 | } | ||
86 | |||
87 | export default observer(InsecureConnectionBanner); | ||