From 8d714bdef30d902ed8267f498638b15eb79dd081 Mon Sep 17 00:00:00 2001 From: Andy Balaam Date: Fri, 11 Apr 2025 11:50:14 +0100 Subject: [PATCH] Add ResetIdentityDialog, wrapping ResetIdentityBody in a dialog --- .../views/dialogs/ResetIdentityDialog.tsx | 61 +++++++++++++++++++ .../settings/encryption/ResetIdentityBody.tsx | 13 ++-- 2 files changed, 68 insertions(+), 6 deletions(-) create mode 100644 src/components/views/dialogs/ResetIdentityDialog.tsx diff --git a/src/components/views/dialogs/ResetIdentityDialog.tsx b/src/components/views/dialogs/ResetIdentityDialog.tsx new file mode 100644 index 0000000000..54ef736ba1 --- /dev/null +++ b/src/components/views/dialogs/ResetIdentityDialog.tsx @@ -0,0 +1,61 @@ +/* + * Copyright 2025 New Vector Ltd. + * + * SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only OR LicenseRef-Element-Commercial + * Please see LICENSE files in the repository root for full details. + */ + +import React, { type MouseEventHandler } from "react"; + +import { MatrixClientPeg } from "../../../MatrixClientPeg"; +import MatrixClientContext from "../../../contexts/MatrixClientContext"; +import { ResetIdentityBody, type ResetIdentityBodyVariant } from "../settings/encryption/ResetIdentityBody"; + +interface ResetIdentityDialogProps { + /** + * Called when the dialog closes. + */ + onFinished: () => void; + /** + * Called when the identity is reset. + */ + onResetFinished: MouseEventHandler; + /** + * Called when the cancel button is clicked. + */ + onCancelClick: () => void; + + /** + * Which variant of this dialog to show. + */ + variant: ResetIdentityBodyVariant; +} + +/** + * The dialog for resetting the identity of the current user. + */ +export function ResetIdentityDialog({ + onFinished, + onCancelClick, + onResetFinished, + variant, +}: ResetIdentityDialogProps): JSX.Element { + const matrixClient = MatrixClientPeg.safeGet(); + + // Wrappers for ResetIdentityBody's callbacks so that onFinish gets called + // whenever the reset is done, whether by completing successfully, or by + // being cancelled + const onResetWrapper: MouseEventHandler = (...args) => { + onFinished(); + onResetFinished(...args); + }; + const onCancelWrapper: () => void = () => { + onFinished(); + onCancelClick(); + }; + return ( + + + + ); +} diff --git a/src/components/views/settings/encryption/ResetIdentityBody.tsx b/src/components/views/settings/encryption/ResetIdentityBody.tsx index f2c339ca4d..dabf61f915 100644 --- a/src/components/views/settings/encryption/ResetIdentityBody.tsx +++ b/src/components/views/settings/encryption/ResetIdentityBody.tsx @@ -36,15 +36,17 @@ interface ResetIdentityBodyProps { } /** - * "compromised" is shown when the user chooses 'reset' explicitly in settings, usually because they believe their - * identity has been compromised. + * "compromised" is shown when the user chose 'Reset cryptographic identity' explicitly in settings, usually because + * they believe their identity has been compromised. * * "sync_failed" is shown when the user tried to recover their identity but the process failed, probably because * the required information is missing from recovery. * - * "forgot" is shown when the user has just forgotten their passphrase. + * "forgot" is shown when the user chose 'Forgot recovery key?' during `SetupEncryptionToast`. + * + * "confirm" is shown when the user chose 'Reset all' during `SetupEncryptionBody`. */ -export type ResetIdentityBodyVariant = "compromised" | "forgot" | "sync_failed"; +export type ResetIdentityBodyVariant = "compromised" | "forgot" | "sync_failed" | "confirm"; /** * User interface component allowing the user to reset their cryptographic identity. @@ -113,11 +115,10 @@ export function ResetIdentityBody({ onCancelClick, onFinish, variant }: ResetIde function titleForVariant(variant: ResetIdentityBodyVariant): string { switch (variant) { case "compromised": + case "confirm": return _t("settings|encryption|advanced|breadcrumb_title"); case "sync_failed": return _t("settings|encryption|advanced|breadcrumb_title_sync_failed"); - - default: case "forgot": return _t("settings|encryption|advanced|breadcrumb_title_forgot"); }