-
-
Notifications
You must be signed in to change notification settings - Fork 828
Add sign out button to settings profile section #12666
Changes from 7 commits
e73f2f2
dcf9e53
5f46ba0
249b923
a2c47b6
9536abb
f13fed5
b232b8b
a89d7b7
2a81272
8d846b9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,9 +22,10 @@ import { IDeferred, defer, sleep } from "matrix-js-sdk/src/utils"; | |
import { TypedEventEmitter } from "matrix-js-sdk/src/matrix"; | ||
import { Glass } from "@vector-im/compound-web"; | ||
|
||
import dis from "./dispatcher/dispatcher"; | ||
import dis, { defaultDispatcher } from "./dispatcher/dispatcher"; | ||
import AsyncWrapper from "./AsyncWrapper"; | ||
import { Defaultize } from "./@types/common"; | ||
import { ActionPayload } from "./dispatcher/payloads"; | ||
|
||
const DIALOG_CONTAINER_ID = "mx_Dialog_Container"; | ||
const STATIC_DIALOG_CONTAINER_ID = "mx_Dialog_StaticContainer"; | ||
|
@@ -114,6 +115,19 @@ export class ModalManager extends TypedEventEmitter<ModalManagerEvent, HandlerMa | |
return container; | ||
} | ||
|
||
public constructor() { | ||
super(); | ||
|
||
// We never unregister this: it's a singleton. An instance could be instantiated, in theory... | ||
defaultDispatcher.register(this.onAction); | ||
} | ||
|
||
private onAction = (payload: ActionPayload): void => { | ||
if (payload.action === "logout") { | ||
this.forceCloseAllModals(); | ||
} | ||
}; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this feels like something that should be in a separate PR, tbh. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Split out to #12777 |
||
|
||
public toggleCurrentDialogVisibility(): void { | ||
const modal = this.getCurrentModal(); | ||
if (!modal) return; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,6 +18,7 @@ import React, { ChangeEvent, useCallback, useEffect, useMemo, useState } from "r | |
import { logger } from "matrix-js-sdk/src/logger"; | ||
import { EditInPlace, Alert, ErrorMessage } from "@vector-im/compound-web"; | ||
import { Icon as PopOutIcon } from "@vector-im/compound-design-tokens/icons/pop-out.svg"; | ||
import { Icon as SignOutIcon } from "@vector-im/compound-design-tokens/icons/sign-out.svg"; | ||
|
||
import { _t } from "../../../languageHandler"; | ||
import { OwnProfileStore } from "../../../stores/OwnProfileStore"; | ||
|
@@ -31,6 +32,10 @@ import { useId } from "../../../utils/useId"; | |
import CopyableText from "../elements/CopyableText"; | ||
import { useMatrixClientContext } from "../../../contexts/MatrixClientContext"; | ||
import AccessibleButton from "../elements/AccessibleButton"; | ||
import LogoutDialog, { shouldShowLogoutDialog } from "../dialogs/LogoutDialog"; | ||
import Modal from "../../../Modal"; | ||
import defaultDispatcher from "../../../dispatcher/dispatcher"; | ||
import { Flex } from "../../utils/Flex"; | ||
|
||
const SpinnerToast: React.FC = ({ children }) => ( | ||
<> | ||
|
@@ -76,6 +81,25 @@ const ManageAccountButton: React.FC<ManageAccountButtonProps> = ({ externalAccou | |
</AccessibleButton> | ||
); | ||
|
||
const SignOutButton: React.FC = () => { | ||
const client = useMatrixClientContext(); | ||
|
||
const onClick = useCallback(async () => { | ||
if (await shouldShowLogoutDialog(client)) { | ||
Modal.createDialog(LogoutDialog); | ||
} else { | ||
defaultDispatcher.dispatch({ action: "logout" }); | ||
} | ||
}, [client]); | ||
|
||
return ( | ||
<AccessibleButton onClick={onClick} kind="danger_outline"> | ||
<SignOutIcon className="mx_UserProfileSettings_accountmanageIcon" width="24" height="24" /> | ||
{_t("action|sign_out")} | ||
</AccessibleButton> | ||
); | ||
}; | ||
|
||
interface UserProfileSettingsProps { | ||
// The URL to redirect the user to in order to manage their account. | ||
externalAccountManagementUrl?: string; | ||
|
@@ -219,11 +243,12 @@ const UserProfileSettings: React.FC<UserProfileSettingsProps> = ({ | |
</Alert> | ||
)} | ||
{userIdentifier && <UsernameBox username={userIdentifier} />} | ||
{externalAccountManagementUrl && ( | ||
<div className="mx_UserProfileSettings_profile_buttons"> | ||
<Flex gap="var(--cpd-space-4x)" className="mx_UserProfileSettings_profile_buttons"> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. do we really want this sort of inline CSS? Shouldn't the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would really have thought so, yeah, but this seems to be how the Flex component is used, and that's what was suggested. |
||
{externalAccountManagementUrl && ( | ||
<ManageAccountButton externalAccountManagementUrl={externalAccountManagementUrl} /> | ||
</div> | ||
)} | ||
)} | ||
<SignOutButton /> | ||
</Flex> | ||
</div> | ||
); | ||
}; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't quite get this. So we should deregister the listener?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated this comment in the split out PR so hopefully its clearer.