ente/src/components/RecoveryKeyModal.tsx

84 lines
2.5 KiB
TypeScript
Raw Normal View History

2021-04-05 07:41:31 +00:00
import React, { useEffect, useState } from 'react';
import { Spinner } from 'react-bootstrap';
2021-04-05 07:41:31 +00:00
import { downloadAsFile } from 'utils/common';
import { getRecoveryKey } from 'utils/crypto';
import constants from 'utils/strings/constants';
import { MessageDialog } from './MessageDailog';
2021-04-05 07:41:31 +00:00
interface Props {
2021-04-05 07:41:31 +00:00
show: boolean;
onHide: () => void;
somethingWentWrong: any;
2021-04-05 07:41:31 +00:00
}
function RecoveryKeyModal(props: Props) {
const [recoveryKey, setRecoveryKey] = useState(null);
useEffect(() => {
2021-04-05 09:11:06 +00:00
if (!props.show) {
return;
}
2021-04-05 07:41:31 +00:00
const main = async () => {
2021-04-05 12:18:29 +00:00
const recoveryKey = await getRecoveryKey();
if (!recoveryKey) {
props.somethingWentWrong();
props.onHide();
}
2021-04-05 07:41:31 +00:00
setRecoveryKey(recoveryKey);
};
main();
}, [props.show]);
return (
<MessageDialog
{...props}
attributes={{
title: constants.DOWNLOAD_RECOVERY_KEY,
2021-04-05 12:17:33 +00:00
cancel: { text: constants.SAVE_LATER },
proceed: {
text: constants.SAVE,
action: () => {
2021-04-05 08:28:22 +00:00
downloadAsFile(
constants.RECOVERY_KEY_FILENAME,
recoveryKey
2021-04-05 10:39:58 +00:00
);
props.onHide();
},
},
}}
>
2021-04-05 13:48:47 +00:00
<p>
{constants.RECOVERY_KEY_DESCRIPTION}
</p>
<div
style={{
display: 'flex',
alignItems: 'center',
justifyContent: 'center',
background: '#1a1919',
height: '150px',
padding: '40px',
color: 'white',
margin: '20px 0',
}}
>
{recoveryKey ? (
<div
style={{
wordWrap: 'break-word',
overflowWrap: 'break-word',
2021-04-05 13:48:47 +00:00
minWidth: '30%',
}}
>
{recoveryKey}
</div>
) : (
<Spinner animation="border" />
)}
</div>
2021-04-05 13:48:47 +00:00
<p>
{constants.KEY_NOT_STORED_DISCLAIMER}
</p>
</MessageDialog>
2021-04-05 07:41:31 +00:00
);
}
export default RecoveryKeyModal;