Add ResetIdentityDialog, wrapping ResetIdentityBody in a dialog
This commit is contained in:
61
src/components/views/dialogs/ResetIdentityDialog.tsx
Normal file
61
src/components/views/dialogs/ResetIdentityDialog.tsx
Normal file
@@ -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<HTMLButtonElement>;
|
||||
/**
|
||||
* 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<HTMLButtonElement> = (...args) => {
|
||||
onFinished();
|
||||
onResetFinished(...args);
|
||||
};
|
||||
const onCancelWrapper: () => void = () => {
|
||||
onFinished();
|
||||
onCancelClick();
|
||||
};
|
||||
return (
|
||||
<MatrixClientContext.Provider value={matrixClient}>
|
||||
<ResetIdentityBody onFinish={onResetWrapper} onCancelClick={onCancelWrapper} variant={variant} />
|
||||
</MatrixClientContext.Provider>
|
||||
);
|
||||
}
|
||||
@@ -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");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user