|
| 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 | +} |
0 commit comments