Skip to content

Commit 4ac84fa

Browse files
committed
Add ResetIdentityDialog, wrapping ResetIdentityBody in a dialog
1 parent d0d3268 commit 4ac84fa

File tree

2 files changed

+68
-6
lines changed

2 files changed

+68
-6
lines changed
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
/*
2+
* Copyright 2025 New Vector Ltd.
3+
*
4+
* SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only OR LicenseRef-Element-Commercial
5+
* Please see LICENSE files in the repository root for full details.
6+
*/
7+
8+
import React, { type MouseEventHandler } from "react";
9+
10+
import { MatrixClientPeg } from "../../../MatrixClientPeg";
11+
import MatrixClientContext from "../../../contexts/MatrixClientContext";
12+
import { ResetIdentityBody, type ResetIdentityBodyVariant } from "../settings/encryption/ResetIdentityBody";
13+
14+
interface ResetIdentityDialogProps {
15+
/**
16+
* Called when the dialog closes.
17+
*/
18+
onFinished: () => void;
19+
/**
20+
* Called when the identity is reset.
21+
*/
22+
onResetFinished: MouseEventHandler<HTMLButtonElement>;
23+
/**
24+
* Called when the cancel button is clicked.
25+
*/
26+
onCancelClick: () => void;
27+
28+
/**
29+
* Which variant of this dialog to show.
30+
*/
31+
variant: ResetIdentityBodyVariant;
32+
}
33+
34+
/**
35+
* The dialog for resetting the identity of the current user.
36+
*/
37+
export function ResetIdentityDialog({
38+
onFinished,
39+
onCancelClick,
40+
onResetFinished,
41+
variant,
42+
}: ResetIdentityDialogProps): JSX.Element {
43+
const matrixClient = MatrixClientPeg.safeGet();
44+
45+
// Wrappers for ResetIdentityBody's callbacks so that onFinish gets called
46+
// whenever the reset is done, whether by completing successfully, or by
47+
// being cancelled
48+
const onResetWrapper: MouseEventHandler<HTMLButtonElement> = (...args) => {
49+
onFinished();
50+
onResetFinished(...args);
51+
};
52+
const onCancelWrapper: () => void = () => {
53+
onFinished();
54+
onCancelClick();
55+
};
56+
return (
57+
<MatrixClientContext.Provider value={matrixClient}>
58+
<ResetIdentityBody onFinish={onResetWrapper} onCancelClick={onCancelWrapper} variant={variant} />
59+
</MatrixClientContext.Provider>
60+
);
61+
}

src/components/views/settings/encryption/ResetIdentityBody.tsx

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,17 @@ interface ResetIdentityBodyProps {
3636
}
3737

3838
/**
39-
* "compromised" is shown when the user chooses 'reset' explicitly in settings, usually because they believe their
40-
* identity has been compromised.
39+
* "compromised" is shown when the user chose 'Reset cryptographic identity' explicitly in settings, usually because
40+
* they believe their identity has been compromised.
4141
*
4242
* "sync_failed" is shown when the user tried to recover their identity but the process failed, probably because
4343
* the required information is missing from recovery.
4444
*
45-
* "forgot" is shown when the user has just forgotten their passphrase.
45+
* "forgot" is shown when the user chose 'Forgot recovery key?' during `SetupEncryptionToast`.
46+
*
47+
* "confirm" is shown when the user chose 'Reset all' during `SetupEncryptionBody`.
4648
*/
47-
export type ResetIdentityBodyVariant = "compromised" | "forgot" | "sync_failed";
49+
export type ResetIdentityBodyVariant = "compromised" | "forgot" | "sync_failed" | "confirm";
4850

4951
/**
5052
* Reset the user's cryptographic identity. Used by ResetIdentityPanel.
@@ -111,11 +113,10 @@ export function ResetIdentityBody({ onCancelClick, onFinish, variant }: ResetIde
111113
function titleForVariant(variant: ResetIdentityBodyVariant): string {
112114
switch (variant) {
113115
case "compromised":
116+
case "confirm":
114117
return _t("settings|encryption|advanced|breadcrumb_title");
115118
case "sync_failed":
116119
return _t("settings|encryption|advanced|breadcrumb_title_sync_failed");
117-
118-
default:
119120
case "forgot":
120121
return _t("settings|encryption|advanced|breadcrumb_title_forgot");
121122
}

0 commit comments

Comments
 (0)