From 5ca126eef74ea8d86c903f66993374d6e65d160e Mon Sep 17 00:00:00 2001 From: Pierre HUBERT Date: Wed, 12 Nov 2025 08:06:47 +0100 Subject: [PATCH] Split recovery key dialog in new file --- .../src/dialogs/SetRecoveryKeyDialog.tsx | 73 +++++++++++++++++++ .../src/routes/MatrixLinkRoute.tsx | 63 ++-------------- 2 files changed, 81 insertions(+), 55 deletions(-) create mode 100644 matrixgw_frontend/src/dialogs/SetRecoveryKeyDialog.tsx 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 ( + + Set new recovery key + + + Enter below you recovery key to verify this session and gain access to + old messages. + + setNewKey(e.target.value)} + fullWidth + /> + + + + + + + ); +} 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 */} - - Set new recovery key - - - Enter below you recovery key to verify this session and gain access - to old messages. - - setNewKey(e.target.value)} - fullWidth - /> - - - - - - + ); }