diff --git a/matrixgw_frontend/src/dialogs/SetRecoveryKeyDialog.tsx b/matrixgw_frontend/src/dialogs/SetRecoveryKeyDialog.tsx
new file mode 100644
index 0000000..22c0aa6
--- /dev/null
+++ b/matrixgw_frontend/src/dialogs/SetRecoveryKeyDialog.tsx
@@ -0,0 +1,73 @@
+import {
+ Dialog,
+ DialogTitle,
+ DialogContent,
+ DialogContentText,
+ TextField,
+ DialogActions,
+ Button,
+} from "@mui/material";
+import { MatrixLinkApi } from "../api/MatrixLinkApi";
+import { useAlert } from "../hooks/contexts_provider/AlertDialogProvider";
+import { useLoadingMessage } from "../hooks/contexts_provider/LoadingMessageProvider";
+import { useSnackbar } from "../hooks/contexts_provider/SnackbarProvider";
+import React from "react";
+import { useUserInfo } from "../widgets/dashboard/BaseAuthenticatedPage";
+
+export function SetRecoveryKeyDialog(p: {
+ open: boolean;
+ onClose: () => void;
+}): React.ReactElement {
+ const alert = useAlert();
+ const snackbar = useSnackbar();
+ const loadingMessage = useLoadingMessage();
+
+ const user = useUserInfo();
+
+ const [newKey, setNewKey] = React.useState("");
+
+ const handleSubmitKey = async () => {
+ try {
+ loadingMessage.show("Updating recovery key...");
+
+ await MatrixLinkApi.SetRecoveryKey(newKey);
+ setNewKey("");
+ p.onClose();
+
+ snackbar("Recovery key successfully updated!");
+ user.reloadUserInfo();
+ } catch (e) {
+ console.error(`Failed to set new recovery key! ${e}`);
+ alert(`Failed to set new recovery key! ${e}`);
+ } finally {
+ loadingMessage.hide();
+ }
+ };
+
+ return (
+
+ );
+}
diff --git a/matrixgw_frontend/src/routes/MatrixLinkRoute.tsx b/matrixgw_frontend/src/routes/MatrixLinkRoute.tsx
index 2d16bc6..1bb675d 100644
--- a/matrixgw_frontend/src/routes/MatrixLinkRoute.tsx
+++ b/matrixgw_frontend/src/routes/MatrixLinkRoute.tsx
@@ -8,16 +8,11 @@ import {
Card,
CardActions,
CardContent,
- Dialog,
- DialogActions,
- DialogContent,
- DialogContentText,
- DialogTitle,
- TextField,
Typography,
} from "@mui/material";
import React from "react";
import { MatrixLinkApi } from "../api/MatrixLinkApi";
+import { SetRecoveryKeyDialog } from "../dialogs/SetRecoveryKeyDialog";
import { useAlert } from "../hooks/contexts_provider/AlertDialogProvider";
import { useConfirm } from "../hooks/contexts_provider/ConfirmDialogProvider";
import { useLoadingMessage } from "../hooks/contexts_provider/LoadingMessageProvider";
@@ -152,34 +147,12 @@ function ConnectedCard(): React.ReactElement {
}
function EncryptionKeyStatus(): React.ReactElement {
- const alert = useAlert();
- const snackbar = useSnackbar();
- const loadingMessage = useLoadingMessage();
-
const user = useUserInfo();
- const [typeNewKey, setTypeNewKey] = React.useState(false);
- const [newKey, setNewKey] = React.useState("");
+ const [openSetKeyDialog, setOpenSetKeyDialog] = React.useState(false);
- const handleSetKey = () => setTypeNewKey(true);
- const cancelSetKey = () => setTypeNewKey(false);
- const handleSubmitKey = async () => {
- try {
- loadingMessage.show("Updating recovery key...");
-
- await MatrixLinkApi.SetRecoveryKey(newKey);
- setNewKey("");
- setTypeNewKey(false);
-
- snackbar("Recovery key successfully updated!");
- user.reloadUserInfo();
- } catch (e) {
- console.error(`Failed to set new recovery key! ${e}`);
- alert(`Failed to set new recovery key! ${e}`);
- } finally {
- loadingMessage.hide();
- }
- };
+ const handleSetKey = () => setOpenSetKeyDialog(true);
+ const handleCloseSetKey = () => setOpenSetKeyDialog(false);
return (
<>
@@ -222,30 +195,10 @@ function EncryptionKeyStatus(): React.ReactElement {
{/* Set new key dialog */}
-
+
>
);
}