|
| 1 | +/** |
| 2 | + * Copyright 2018 Shift Devices AG |
| 3 | + * Copyright 2024 Shift Crypto AG |
| 4 | + * |
| 5 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | + * you may not use this file except in compliance with the License. |
| 7 | + * You may obtain a copy of the License at |
| 8 | + * |
| 9 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | + * |
| 11 | + * Unless required by applicable law or agreed to in writing, software |
| 12 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | + * See the License for the specific language governing permissions and |
| 15 | + * limitations under the License. |
| 16 | + */ |
| 17 | + |
| 18 | +import { useTranslation } from 'react-i18next'; |
| 19 | +import { useNavigate } from 'react-router-dom'; |
| 20 | +import { TDevices } from '../../../api/devices'; |
| 21 | +import { ButtonLink } from '../../../components/forms'; |
| 22 | +import { Guide } from '../../../components/guide/guide'; |
| 23 | +import { Entry } from '../../../components/guide/entry'; |
| 24 | +import { Header } from '../../../components/layout'; |
| 25 | +import { Backups } from '../bitbox01/backups'; |
| 26 | +import { BackupsV2 } from '../bitbox02/backups'; |
| 27 | +import { SDCardCheck } from '../bitbox02/sdcardcheck'; |
| 28 | + |
| 29 | +type TProps = { |
| 30 | + deviceID: string | null; |
| 31 | + devices: TDevices |
| 32 | +} |
| 33 | + |
| 34 | +export const ManageBackups = ({ |
| 35 | + deviceID, |
| 36 | + devices, |
| 37 | +}: TProps) => { |
| 38 | + const { t } = useTranslation(); |
| 39 | + const navigate = useNavigate(); |
| 40 | + |
| 41 | + if (!deviceID || !devices[deviceID]) { |
| 42 | + navigate('/'); |
| 43 | + return null; |
| 44 | + } |
| 45 | + |
| 46 | + return ( |
| 47 | + <div className="contentWithGuide"> |
| 48 | + <div className="container"> |
| 49 | + <div className="innerContainer scrollableContainer"> |
| 50 | + <Header |
| 51 | + title={<h2>{t('backup.title')}</h2>} |
| 52 | + /> |
| 53 | + <div className="content padded"> |
| 54 | + <h3 className="subTitle">{t('backup.list')}</h3> |
| 55 | + <BackupsList |
| 56 | + deviceID={deviceID} |
| 57 | + devices={devices} |
| 58 | + /> |
| 59 | + </div> |
| 60 | + </div> |
| 61 | + </div> |
| 62 | + <ManageBackupGuide |
| 63 | + deviceID={deviceID} |
| 64 | + devices={devices} |
| 65 | + /> |
| 66 | + </div> |
| 67 | + ); |
| 68 | +}; |
| 69 | + |
| 70 | +const BackupsList = ({ |
| 71 | + deviceID, |
| 72 | + devices, |
| 73 | +}: TProps) => { |
| 74 | + if (!deviceID) { |
| 75 | + return null; |
| 76 | + } |
| 77 | + switch (devices[deviceID]) { |
| 78 | + case 'bitbox': |
| 79 | + return ( |
| 80 | + <Backups |
| 81 | + deviceID={deviceID} |
| 82 | + showCreate={true} |
| 83 | + showRestore={false}> |
| 84 | + <BackButton deviceID={deviceID} /> |
| 85 | + </Backups> |
| 86 | + ); |
| 87 | + case 'bitbox02': |
| 88 | + return ( |
| 89 | + <SDCardCheck deviceID={deviceID}> |
| 90 | + <BackupsV2 |
| 91 | + deviceID={deviceID} |
| 92 | + showCreate={true} |
| 93 | + showRestore={false} |
| 94 | + showRadio={false}> |
| 95 | + <BackButton deviceID={deviceID} /> |
| 96 | + </BackupsV2> |
| 97 | + </SDCardCheck> |
| 98 | + ); |
| 99 | + default: |
| 100 | + return null; |
| 101 | + } |
| 102 | +}; |
| 103 | + |
| 104 | +const BackButton = ({ deviceID }: { deviceID: string }) => { |
| 105 | + const { t } = useTranslation(); |
| 106 | + return ( |
| 107 | + <ButtonLink |
| 108 | + secondary |
| 109 | + to={`/settings/device-settings/${deviceID}`}> |
| 110 | + {t('button.back')} |
| 111 | + </ButtonLink> |
| 112 | + ); |
| 113 | +}; |
| 114 | + |
| 115 | +const ManageBackupGuide = ({ |
| 116 | + deviceID, |
| 117 | + devices, |
| 118 | +}: TProps) => { |
| 119 | + const { t } = useTranslation(); |
| 120 | + |
| 121 | + if (!deviceID) { |
| 122 | + return null; |
| 123 | + } |
| 124 | + |
| 125 | + switch (devices[deviceID]) { |
| 126 | + case 'bitbox': |
| 127 | + return ( |
| 128 | + <Guide> |
| 129 | + <Entry key="guide.backups.whatIsABackup" entry={t('guide.backups.whatIsABackup')} /> |
| 130 | + <Entry key="guide.backups.encrypt" entry={t('guide.backups.encrypt')} /> |
| 131 | + <Entry key="guide.backups.check" entry={t('guide.backups.check')} /> |
| 132 | + <Entry key="guide.backups.howOften" entry={t('guide.backups.howOften')} /> |
| 133 | + </Guide> |
| 134 | + ); |
| 135 | + case 'bitbox02': |
| 136 | + return ( |
| 137 | + <Guide> |
| 138 | + <Entry key="guide.backupsBB02.whatIsABackup" entry={t('guide.backupsBB02.whatIsABackup')} /> |
| 139 | + <Entry key="guide.backupsBB02.encrypt" entry={t('guide.backupsBB02.encrypt')} shown={true} /> |
| 140 | + <Entry key="guide.backupsBB02.check" entry={t('guide.backupsBB02.check')} /> |
| 141 | + <Entry key="guide.backups.howOften" entry={t('guide.backups.howOften')} /> |
| 142 | + </Guide> |
| 143 | + ); |
| 144 | + default: |
| 145 | + return null; |
| 146 | + } |
| 147 | +}; |
0 commit comments