2020-11-25 09:46:56 +00:00
|
|
|
/*
|
2024-09-09 14:57:16 +01:00
|
|
|
Copyright 2024 New Vector Ltd.
|
|
|
|
|
Copyright 2020, 2021 The Matrix.org Foundation C.I.C.
|
2020-11-25 09:46:56 +00:00
|
|
|
|
2025-01-06 11:18:54 +00:00
|
|
|
SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only OR LicenseRef-Element-Commercial
|
2024-09-09 14:57:16 +01:00
|
|
|
Please see LICENSE files in the repository root for full details.
|
2020-11-25 09:46:56 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
import React from "react";
|
|
|
|
|
|
|
|
|
|
import AccessibleButton from "./AccessibleButton";
|
2025-02-05 13:25:06 +00:00
|
|
|
import { type ValidatedServerConfig } from "../../../utils/ValidatedServerConfig";
|
2021-06-29 13:11:58 +01:00
|
|
|
import { _t } from "../../../languageHandler";
|
2020-11-25 09:46:56 +00:00
|
|
|
import TextWithTooltip from "./TextWithTooltip";
|
|
|
|
|
import SdkConfig from "../../../SdkConfig";
|
|
|
|
|
import Modal from "../../../Modal";
|
|
|
|
|
import ServerPickerDialog from "../dialogs/ServerPickerDialog";
|
|
|
|
|
import InfoDialog from "../dialogs/InfoDialog";
|
|
|
|
|
|
|
|
|
|
interface IProps {
|
|
|
|
|
title?: string;
|
|
|
|
|
dialogTitle?: string;
|
|
|
|
|
serverConfig: ValidatedServerConfig;
|
2024-08-17 10:37:35 +01:00
|
|
|
disabled?: boolean;
|
2020-11-25 09:46:56 +00:00
|
|
|
onServerConfigChange?(config: ValidatedServerConfig): void;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const showPickerDialog = (
|
2023-03-13 15:07:20 +00:00
|
|
|
title: string | undefined,
|
2020-11-25 09:46:56 +00:00
|
|
|
serverConfig: ValidatedServerConfig,
|
|
|
|
|
onFinished: (config: ValidatedServerConfig) => void,
|
2023-01-12 13:25:14 +00:00
|
|
|
): void => {
|
2022-06-14 17:51:51 +01:00
|
|
|
Modal.createDialog(ServerPickerDialog, { title, serverConfig, onFinished });
|
2020-11-25 09:46:56 +00:00
|
|
|
};
|
|
|
|
|
|
2023-01-12 13:25:14 +00:00
|
|
|
const onHelpClick = (): void => {
|
2022-03-23 16:31:25 +00:00
|
|
|
const brand = SdkConfig.get().brand;
|
2022-06-14 17:51:51 +01:00
|
|
|
Modal.createDialog(
|
|
|
|
|
InfoDialog,
|
|
|
|
|
{
|
2023-10-03 19:17:26 +01:00
|
|
|
title: _t("auth|server_picker_title_default"),
|
|
|
|
|
description: _t("auth|server_picker_description", { brand }),
|
2023-08-23 11:57:22 +01:00
|
|
|
button: _t("action|dismiss"),
|
2020-11-25 09:46:56 +00:00
|
|
|
hasCloseButton: false,
|
|
|
|
|
fixedWidth: false,
|
|
|
|
|
},
|
|
|
|
|
"mx_ServerPicker_helpDialog",
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
2024-08-17 10:37:35 +01:00
|
|
|
const ServerPicker: React.FC<IProps> = ({ title, dialogTitle, serverConfig, onServerConfigChange, disabled }) => {
|
2022-03-18 10:12:36 -06:00
|
|
|
const disableCustomUrls = SdkConfig.get("disable_custom_urls");
|
2021-11-29 11:06:11 +00:00
|
|
|
|
2020-11-25 09:46:56 +00:00
|
|
|
let editBtn;
|
2021-11-29 11:06:11 +00:00
|
|
|
if (!disableCustomUrls && onServerConfigChange) {
|
2023-01-12 13:25:14 +00:00
|
|
|
const onClick = (): void => {
|
2020-11-25 09:46:56 +00:00
|
|
|
showPickerDialog(dialogTitle, serverConfig, (config?: ValidatedServerConfig) => {
|
|
|
|
|
if (config) {
|
|
|
|
|
onServerConfigChange(config);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
};
|
2020-11-25 10:22:16 +00:00
|
|
|
editBtn = (
|
2024-08-17 10:37:35 +01:00
|
|
|
<AccessibleButton className="mx_ServerPicker_change" kind="link" onClick={onClick} disabled={disabled}>
|
2023-08-22 20:55:15 +01:00
|
|
|
{_t("action|edit")}
|
2020-11-25 09:46:56 +00:00
|
|
|
</AccessibleButton>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2021-04-06 12:26:50 +01:00
|
|
|
let serverName: React.ReactNode = serverConfig.isNameResolvable ? serverConfig.hsName : serverConfig.hsUrl;
|
2020-11-25 09:46:56 +00:00
|
|
|
if (serverConfig.hsNameIsDifferent) {
|
|
|
|
|
serverName = (
|
2023-12-19 17:19:54 +00:00
|
|
|
<TextWithTooltip className="mx_Login_underlinedServerName" tooltip={serverConfig.hsUrl}>
|
2021-07-19 22:43:11 +01:00
|
|
|
{serverConfig.hsName}
|
2020-11-25 09:46:56 +00:00
|
|
|
</TextWithTooltip>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let desc;
|
|
|
|
|
if (serverConfig.hsName === "matrix.org") {
|
2023-10-03 19:17:26 +01:00
|
|
|
desc = <span className="mx_ServerPicker_desc">{_t("auth|server_picker_description_matrix.org")}</span>;
|
2020-11-25 09:46:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<div className="mx_ServerPicker">
|
2023-08-23 10:25:33 +01:00
|
|
|
<h2>{title || _t("common|homeserver")}</h2>
|
2022-08-01 08:31:14 +01:00
|
|
|
{!disableCustomUrls ? (
|
2023-08-23 10:25:33 +01:00
|
|
|
<AccessibleButton
|
|
|
|
|
className="mx_ServerPicker_help"
|
|
|
|
|
onClick={onHelpClick}
|
|
|
|
|
aria-label={_t("common|help")}
|
|
|
|
|
/>
|
2022-08-01 08:31:14 +01:00
|
|
|
) : null}
|
2022-02-04 10:20:20 +00:00
|
|
|
<span className="mx_ServerPicker_server" title={typeof serverName === "string" ? serverName : undefined}>
|
|
|
|
|
{serverName}
|
|
|
|
|
</span>
|
2020-11-25 09:46:56 +00:00
|
|
|
{editBtn}
|
|
|
|
|
{desc}
|
2021-06-29 13:11:58 +01:00
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
};
|
2020-11-25 09:46:56 +00:00
|
|
|
|
|
|
|
|
export default ServerPicker;
|