diff --git a/config.sample.json b/config.sample.json index 6dc5db77b5..972d04cfe1 100644 --- a/config.sample.json +++ b/config.sample.json @@ -8,6 +8,18 @@ "base_url": "https://matrix.i.tchap.gouv.fr" } }, + "homeserver_list": [ + { + "base_url": "https://matrix.i.tchap.gouv.fr", + "server_name": "Internes - preprod", + "email_examples": "hakim@beta.gouv.fr, alice@interieur.gouv.fr, ..." + }, + { + "base_url": "https://matrix.e.tchap.gouv.fr", + "server_name": "Externes - preprod", + "email_examples": "nina@soprasteria.com, paul@athos.fr, ..." + } + ], "disable_custom_urls": false, "disable_guests": true, "disable_login_language_selector": false, diff --git a/src/components/views/dialogs/TchapServerPickerDialog.tsx b/src/components/views/dialogs/TchapServerPickerDialog.tsx new file mode 100644 index 0000000000..acf6618bb2 --- /dev/null +++ b/src/components/views/dialogs/TchapServerPickerDialog.tsx @@ -0,0 +1,113 @@ +/* +* Copyright 2022 DINUM "Apache License" version 2.0 +*/ + +import React from "react"; +import SdkConfig from 'matrix-react-sdk/src/SdkConfig'; +import { _t } from "matrix-react-sdk/src/languageHandler"; +// We import components from the react-sdk like this to avoid " Attempted to get a component before a skin +// has been loaded" +import * as sdk from 'matrix-react-sdk/src/index'; +import AutoDiscoveryUtils, { ValidatedServerConfig } from "matrix-react-sdk/src/utils/AutoDiscoveryUtils"; + +interface IProps { + title?: string; + serverConfig: ValidatedServerConfig; + onFinished(config?: ValidatedServerConfig): void; +} + +interface IState { + selectedHomeServerUrl: string; +} + +export default class TchapServerPickerDialog extends React.PureComponent { + static replaces = 'ServerPickerDialog'; + + homeServerList; + + constructor(props) { + super(props); + this.homeServerList = SdkConfig.get()['homeserver_list']; + this.state = { + selectedHomeServerUrl: props.serverConfig.hsUrl, + }; + } + + private findHomeServerInListByUrl = url => { + return this.homeServerList.find(homeServer => homeServer.base_url === url); + }; + + private onSubmit = async (ev) => { + ev.preventDefault(); + + const selectedHomeServer = this.findHomeServerInListByUrl(this.state.selectedHomeServerUrl); + + // Fake the discovery process, we don't need it since we know our own servers. + const discoveryResult = { + "m.homeserver": { + state: "SUCCESS", + error: null, + base_url: selectedHomeServer.base_url, + server_name: selectedHomeServer.server_name, + }, + "m.identity_server": { + state: "PROMPT", + error: null, + base_url: selectedHomeServer.base_url, // On Tchap our Identity server urls and home server urls are the same + server_name: selectedHomeServer.server_name, + }, + }; + // Then continue the same flow as the original ServerPickerDialog. + const validatedConf = AutoDiscoveryUtils.buildValidatedConfigFromDiscovery( + discoveryResult['m.homeserver'].server_name, discoveryResult); + this.props.onFinished(validatedConf); + }; + + private onHomeServerSelected = (homeServerUrl) => { + this.setState({ + selectedHomeServerUrl: homeServerUrl, + }); + }; + + public render() { + // Imports + const BaseDialog = sdk.getComponent('dialogs.BaseDialog'); + const AccessibleButton = sdk.getComponent('elements.AccessibleButton'); + const StyledRadioGroup = sdk.getComponent('elements.StyledRadioGroup'); + + const radioButtonOptions = this.homeServerList.map(homeServer => { + return { + value: homeServer.base_url, + label: { homeServer.server_name }, + description: { _t("Examples:") } { homeServer.email_examples }, + }; + }); + + return +
+
+ +
+
+ +
+ + + { _t("Continue") } + +
+
; + } +} diff --git a/src/i18n/strings/en_EN.json b/src/i18n/strings/en_EN.json index 754d93f761..fd90d84e80 100644 --- a/src/i18n/strings/en_EN.json +++ b/src/i18n/strings/en_EN.json @@ -32,5 +32,7 @@ "Explore rooms": "Explore rooms", "Username": "Email", "Username_comments": "We use Email to login in Tchap. The Login code accepts both username and email. So the simplest change for us to force login by email is to just rename the Username field to Email.", - "Welcome to Tchap": "Bienvenue sur Tchap" + "Welcome to Tchap": "Bienvenue sur Tchap", + "Examples:": "Examples:", + "Choose a homeserver:": "Choose a homeserver:" } diff --git a/src/i18n/strings/fr.json b/src/i18n/strings/fr.json index 6a3e839767..825c541337 100644 --- a/src/i18n/strings/fr.json +++ b/src/i18n/strings/fr.json @@ -39,5 +39,7 @@ "Previous recently visited room or community": "Salon ou communauté précédemment visité", "Username": "E-mail", "Username_comments": "We use E-mail to login in Tchap. The Login code accepts both username and email. So the simplest change for us to force login by email is to just rename the Username field to Email.", - "Welcome to Tchap": "Bienvenue sur Tchap" + "Welcome to Tchap": "Bienvenue sur Tchap", + "Examples:": "Exemples :", + "Choose a homeserver:": "Choisissez un serveur d'accueil :" }